ScanImage 2016 : Motion Correction

Introduction

ScanImage can continuously detect motion of the currently acquired image relative to a reference image during an active acquisiton.

The motion correction can be used for

Setup

Error rendering macro 'html' : Notify your Confluence administrator that "Bob Swift Atlassian Add-ons - HTML" requires a valid license. Reason: VERSION_MISMATCH

Algorithm

ScanImage ships with three algorithms for motion detection:

ScanImage DefaultFunctionPerformanceDescription
Default if GPU acceleration is not availablefftCorrGoodestimates motion by calculating the fft-based circular cross correlation between the reference image and the current image
Default if GPU acceleration is availablefftCorrGpuExcellentsame as fftCorr, but calculates the fft-based cross correlation using the GPU
 fftCorrSideProjExcellentfirst calculates the mean side projections for x and y, then calculates the fft-based circular cross correlation between the side projections of the reference image and the current image; less accurate, but more performant than fftCorr
Icon

GPU acceleration for motion correction is only available if the Matlab Parallel Computing Toolbox is installed and a CUDA enabled GPU is available.

 

The motion correction algorithm is split into two parts:

  • Reference image pre-process function
  • Motion correction algorithm

Use the Motion Correction Windows to select which motion correction algorithm is used.

Icon

The Motion Correction Functions are stored in +scanimage\+components\+motionCorrection
When selecting a motion correction function in the Motion Correction Window, make sure to also select the corresponding preprocess function. 

API

The pre-process function is called only when a new reference image is loaded, while the motion correction algorithm is called every time a frame is acquired. This reduces the number of reoccuring calculations. In the fft-based cross correlation, the fft of the reference image is processed once, and then stored for later use. The preprocess function ha two return values:

Return ValueDescription
refDisplayImage

(Required) Used as a reference image in the Motion Correction Display Windows

refImagePreProcessed(Required) The pre-processed reference data passed to the motion correction algorithm whenever a frame is acquired. (Can be a matrix, struct, class..)

The motion-correction function expects two inputs:

InputDescription
refImagePreProcessedpre-processed reference data
imageimage data of current frame
OutputRequiredData typeDescription
successRequiredlogicalIndicates if the motion algorithm found a match between the reference image and the current image
ijOffsetRequired if success==true\[1x2]\ doubleThe [i,j] offset between the reference image and the current image
qualityCan be emptydoubleA metric describing the quality/certainty of the match
ciiCan be empty\[1xM\]doubleA metric showing the quality/certainty of the match for each possible pixelshift in direction i
cjjCan be empty\[1xN]doubleA metric showing the quality/certainty of the match for each possible pixelshift in direction j
Icon

Note: ScanImage internally represents images in column-major order, whereas Matlab uses row-major order for storing matrices. This means that images appear to be transposed when plotted.
As a workaround, images can be transposed, which will result in a performance hit. Alternatively, the axes view can be rotated:

view(gca,-90,90);
Icon

The motion correction functionality is handled by the ScanImage module hMotionManager. Type

hSI.hMotionManager

in the Matlab Command Window to see all availble properties and functions.