NoRMCorre: Non-Rigid Motion Correction
This package can be used for online piecewise rigid motion correction of 2d (planar) or 3d (volumetric) calcium imaging data.
The algorithm operates by splitting the field of view into a set of overlapping patches. For each patch and each frame a rigid translation is estimated by aligning the patch against a template using an efficient, FFT based, algorithm for subpixel registration 1. The estimated set of translations is further upsampled to a finer resolution to create a smooth motion field that is applied to a set of smaller overlapping patches. Extra care is taken to avoid smearing caused by interpolating overlapping patches with drastically different motion vectors. The registered frame is used to update the template in an online fashion by calculating a running/mean of past registered frames. The pipeline is summarized in the figure below.
See the function
demo.m for an example of the code. The algorithm is implemented in the function
normcorre.m. If you have access to the parallel computing toolbox, then the function
normcorre_batch.m can offer speed gains by enabling within mini-batch parallel processing. The user gives a dataset (either as 3D or 4D tensor loaded in RAM or memory mapped, or a pointer to a .tiff stack or .hdf5 file), and a parameters struct
options. Optionally, an initial template can also be given.
options struct can be set either manually or by using the function
NoRMCorreSetParms.m. The most important parameters of the
options struct are the following:
||dimensions of field of view|
||size of non-overlapping portion of the grid in each direction (x-y-z)|
||size of overlapping region in each direction before upsampling|
||upsampling factor for smoothing and refinement of motion field|
||size of overlapping region in each direction after upsampling|
||maximum allowed shift for rigid translation|
||maximum deviation of each patch from estimated rigid translation|
||update the template online after registering some frames|
||length of bin over which the registered frames are averaged to update the template|
||number of frames to be taken for computing initial template|
||number of times to go over the dataset|
||type of output registered file|
||flag for using phase correlation|
The performance of registration can be evaluated using the function
motion_metrics.m. The function simply computes the correlation coefficient of each (registered) frame, with the mean (registered) frame across time, the mean registered frame, and its crispness.
Eftychios A. Pnevmatikakis, Flatiron Institure, Simons Foundation
This package includes functions from the following packages
- Save and load a multipage tiff file
- Savefast for saving (and then loading) MAT files more quickly without compressing their contents.
- Eficient subpixel registration by cross-correlation for fast alignment of an image against a template.
This package will be integrated with the Matlab code for source extraction and deconvolution using CNMF.
Although the two implementations give almost identical results for the same input file, there are some slight differences in the way they are called and their capabilities. These differences are highlighted here.
More details and citing NoRMCorre
If you find this package useful please cite the following paper:
Eftychios A. Pnevmatikakis and Andrea Giovannucci, NoRMCorre: An online algorithm for piecewise rigid motion correction of calcium imaging data, bioRxiv 108514; doi: https://doi.org/10.1101/108514
Example dataset is kindly provided from Andrea Giovannucci, taken at Wang lab (Princeton University).
 Guizar-Sicairos, M., Thurman, S. T., & Fienup, J. R. (2008). Efficient subpixel image registration algorithms. Optics letters, 33(2), 156-158. Matlab implementation available here.