
# Virtual Blebbistatin

Readme file for virtual blebbistatin software based on lkmechanics code 
by John Boyle: https://doi.org/10.1098/rsif.2014.0685

Current code: Louis Woodhams, Mimi Guo, Guy Genin, Nathaniel Huebsch
This code was devolped in Matlab and is known to be compatible with version
2021b.

# Procedure:

## Pre-processing image/video files:

The easiest way to get files (videos) into the program is often to convert 
them to a folder of .tif files.  There is also support for videos, arrays 
saved into .mat files, and even some scientific formats built into the 
original code.  I am currently using ImageJ to convert the .nd2 files to 
tiffs (save as image sequence).

Preprocessing .nd2 files:
Open .nd2 files in imagej:
Options: 
- View Stack - Hyperstack, 
- Color Mode – Default, 
- Autoscale – checked, 
- all other boxes clear

Adjustments in ImageJ: 
If necessary, you can adjust the histogram under Image->Adjust->Brightness/Contrast 
to remove unused intensity range.
- Convert to 8-bit under Image -> Type
Save as tiffs:
- Save as -> Image Sequence -> Format TIFF1

Time filtering of images:
Time-filtering of images using a median filter on each pixel-timeseries was 
found to improve convergence of the algorithm. 


## Running analysis and stabilization

Because the first frame of the video analyzed will be the reference configuration 
for deformations in all other frames, pick a still frame for first image.
I have just been manually looking at the video in imageJ, picking a still 
frame by inspection, then removing all frames before that frame from the 
images folder.  This could be a step to automate.

Running image analysis and Stabilization:

1.	Run the runme_VB.m file
a.	A video selection dialog will allow you to select “folder of images”
b.	There are options in runme.m to show results by changing the showStrains 
variable to true. It will save a video of the results (described in Boyle 2014 paper).
c.	The file should begin to process immediately. Low Epsilon values (<0.1) 
indicate good convergence.  A few higher values means the program had some 
trouble in those frames, if epsilon is consistently high, it is not a good 
sign (trouble converging). –see also ImageError and Iterations (avg. number)

2.	When the first part (deformation mapping) is finished, if the unwarp 
flag is set to true, the program will create an array of stabilized images.
3.	The unwarped video will be saved as ‘unwarped’ in the workspace, and 
an array of the original and stabilized images will be created as 
'side_by_side'. You can view these using the implay() function.

4.	Displacements and strains are in the 'mechanics' structure in the workspace.

## Post-processing

Plot calcium signal vs. contraction:
Function plotCalciumContraction.m requires inputs 'unwarped', 'preComp', 
and 'mechanics' from the step above.

Plot correlation of each frame to frame 1
corrVals = corrToFirst(videoArray);

Make a pretty video of calcium and contraction propagation
[~, ~, colorVid] = calcDilation(mechanics,unwarped, CaVid);
implay(colorVid)

Optimizing Box Size:
1.	Open the runme_batch.m file
2.	Set the boxVector vector to contain box sizes for testing
3.	Run the script
4.	Results will be generated automatically (plots)
5.	To save the results, save the myStats structure


