This code is adapted from the manuscript "Quantifying topography-guided actin dynamics across scales using optical flow" by Lee*, Campanello*, Hourwitz, Alvarez, Omidvar, Fourkas and Losert. The original code used in the manuscript is posted by @LosertLab at https://github.com/losertlab/flowclustertracking.
The current version of the code is written in MATLAB and only applicable to 2-D data. A Python version is in the works.
The workflow is managed by ControlScript.m (ControlScript_sample.m for the example data). Detailed explanations of all predefined parameters in the control script can be found in Parameters.txt.
"MainAnalysisScript.m" receives the parameters from ControlScript.m and performs all of the main functions of the analysis workflow.
Data must be saved in a single-channel multistack .tif such that "imread('FILENAME.tif', n)" loads frame "n" of the time series.
Optical flow is calculated using the Lucas-Kanade method. The Lucas-Kanade method assumes that local spatial and temporal image gradients can be modeled as a linear translation of intensity between two adjacent frames.
The optical-flow calculation here uses a derivative-of-Gaussian (DoG) kernel to calculate spatial and temporal image gradients, and solves for the best estimate of optical flow using least-squares criteria. The DoG kernel assures that pixel noise does not result in overly noise optical flow.
The Lucas-Kanade method prescribes that local spatial and temporal gradients be accumulated in the calculation step using a window of a predefined size. Here, we applied an additional gaussian weight matrix to ensure that optical-flow vectors indicated by pixels at the center of the window carried more information than those far away from the central pixel.
Optical-flow reliability is a measure of certaintly in the flow calculation. Low reliability indicates that the optical-flow calculation has encountered the aperture problem. Here, we define the reliability as the smaller eigenvalue of the Lucas-Kanade structure tensor. Alternatively, one may use optical-flow coherence as a measure of quality (defined as the absolute value of the difference of the eigenvalues divided by their sum), which is included as a currently unused output of LKxOpticalFlow_allFrames.m.
Optical-flow clusters were calculated by superimposing optical-flow alignment on regions of protruding dynamic behavior.
Optical-flow alignment was calculated by taking the weighted sum of the dot product between optical-flow vectors with neighboring vectors. The alignment metric uses a gaussian weight matrix so that alignment in a central pixel is largely comprised of information from nearby pixels.
Protruding regions were defined as areas where the difference image of overly smoothed images is positive. Thus, the workflow first calculates the "SmoothImages" and then the "DifferenceImages."
Tracking was performed using the Crocker-Grier particle-tracking algorithm translated to MATLAB. Tracking is performed on peak optical-flow alignment within optical flow clusters, but can be alternatively performed on binary images by thresholding the '''clusterIm*''' variables before tracking.