Skip to content

2D cross correlation

Eugene Katrukha edited this page Feb 5, 2021 · 3 revisions

Again, for the general cross-correlation theory/explanation, I wrote two blog posts that could be helpful (one, two).

As an input, this command takes a single image or 8-,16-,32- bit image stack (only with time or only with Z, not both).

As an output, the command returns an image or a stack of normalized cross-correlations (32-bit). What is a cross-correlation? Basically, it is a measure of similarity between two images, as a function of the displacement of one image relative to the other (displacement along both x and y, therefore 2D). So returned image or stack is basically 2D function of similarity depending on displacement along x and y. This function is normalized, so it means, that it returns values in the range from -1 (one image is inverted version of another) to 1 (two identical images). It is important to realize, that in returned images the origin of coordinates (or cross-correlation value corresponding to zero displacements in both x and y) is located at the center of the generated image (see below for a more detailed explanation).

Upon start the command provides the following parameters dialog:

parameters dialog

"Calculate 2D cross-correlation" option defines, which image pairs sequence from a currently opened stack will be used for cross-correlation sequence calculation. Let's assume that frames(slices) in a provided stack are labeled sequentially (1,2,3...N), then:

  • "consecutive images" will calculate cross-correlation between image pairs (1,2), (2,3) ...(N-1, N) from the stack. Interval between image pairs (measured in frames) can be changed below, see "for consecutive, interval between". For example, if this interval is equal to 3, image pairs will be (1,4), (2,5) ... (N-3,N);
  • "current image in stack and all other". In this case, command pick number of currently selected frame(slice) in the stack (suppose its number is 4) and calculates cross-correlation between pairs (4,1), (4,2), (4,3), (4,4) ...(4,N).
  • "autocorrelation" option calculates cross-correlation of image with itself for all images in stack, i.e. (1,1), (2,2)..(N,N). If only one image is provided, it is the only available option.

"Calculation method" allows to choose whether to use "FFT cross-correlation (fast)" or "Direct cross-correlation (slow)". As it can be seen from the label names, the difference is in speed, second method provided just for verification. Specifically, first method achieves O(N log(N)) computational complexity, while the second is O(N2), where in this case N is total number of pixels per image.

"Correct drift (max of corr)?" option corrects a drift in the stack (using one of the options above), by finding x and y shifts with maximum of cross-correlation function. I.e. when similarity between images is the highest. In the end it corrects drift with precision of one pixel (no sub-pixel correction).

If "Limit max displacement" option is selected, the maximum of cross-correlation for the drift correction will be searched in a limited area of displacements, i.e. shifts larger than provided values will be ignored. This option can be helpful when there are repetative areas in images and values for maximum of cross-correlation provides too high displacement values.


Output

As an output plugin generates 2D cross-correlation function image (or map) between pairs of images specified in the parametes window. The output image coordinates are calibrated, i.e. the origin of coordinates is not located at the top left corner of the image. It can be seen in ImageJ/FIJI bar when hovering mouse pointer over pixels of the image (see example below). In this case reported x and y values of the image pixel correspond to the displacements (shifts) and the pixel value is the value of normalized cross-correlation. Here is example of this image with "Fire" lookup table:

output CC illustration

The displacement x and y values for an image pair (Im1, Im2) correspond to the shift of Im2 with respect to Im1.

In addition, plugin generates Results table with displacements corresponding to maximum cross-correlation value and (if selected) drift correction shifts.

Clone this wiki locally