Skip to content

Motion Correction Functions

Selmaan edited this page Mar 3, 2017 · 4 revisions

The motion correction function that's been optimized by Matthias and Selmaan is called 'lucasKanade_affineReg'. It applies a spatial and temporal hierarchy of shifts: Full frame slow timescale sub-pixel affine warping -> sub-pixel full-frame via fft -> pixel-shifts of vertically spaced splines -> sub-pixel vertically spaced splines.

Relevant things to consider if you're using this function, or want to make improvements:
(1) The slow-timescale shifts are well approximated by an affine, but not exactly (e.g. blood vessels can expand and contract with blood pressure, producing local deformation). We use matlab's 'imregtform' to fit an affine in 'lucasKanade_affineReg', but this could be improved to a fully non-parametric non-rigid deformation (e.g. imregdemons or NormCorre?)
(2) The number of vertically spaced splines is given by 'nBasis' in 'doLucasKanadeSPMD', line 72. Using larger numbers would allow for finer line-by-line shifts, but is less robust. A value of 4 has been a good trade-off for me w/ our standard resonant scanning setup, but this can be adjusted if needed.
(3) The algorithm gets substantial speed-ups by dropping the spline-wise sub-pixel shift fine-tuning if they are all negligible for a given frame. For example, correcting my 4hr acquisitions goes from >30hrs to ~10hrs. However this is easy to manipulate by adjusting the parameter 'absShiftThresh' in line 179 of 'doLucasKanadeSPMF'. I have it currently set to 1/3 of a pixel. Note that this is after sub-pixel full-frame adjustments, and only applies to sub-pixel deviations of individual splines.
(4) Despite the hierarchical estimation process, the composite interpolation is applied only once to go from raw to final data, for best quality. The interpolation is determined by the code in the 'apply' block of code in 'lucasKanade_affineReg' (as opposed to the 'identify' block). I have recently changed this to bicubic, which improved on bilinear without adding much more time. More complex spline or frequency-domain shifts can be applied here if the increased computation time is desired.

Clone this wiki locally