Image registration

From Bioimaging Wiki
Revision as of 17:41, 13 September 2023 by JWTay (talk | contribs) (Created page with "'''Image registration''' is the process of spatially aligning images in a dataset. Registration is often used to correct for drift or motion within an imaging dataset. Registration can also be used to align images taken from different viewpoints or by different equipment (e.g., aligning EM images with optical images). === Strategies to correct image drift === Drift in an image can be caused by different issues, including thermal changes (which causes expansion/contracti...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Image registration is the process of spatially aligning images in a dataset. Registration is often used to correct for drift or motion within an imaging dataset. Registration can also be used to align images taken from different viewpoints or by different equipment (e.g., aligning EM images with optical images).

Strategies to correct image drift

Drift in an image can be caused by different issues, including thermal changes (which causes expansion/contraction of the sample) or due to mounting (e.g., if the imaged objects are free-floating). This typically results in a global translation of the image.

Cross-correlation

Animation showing the cross-correlation calculation. The left shows the displacement between reference (image in middle) and the moving images. The plot on the right shows the value of the cross-correlation. When the moving image overlaps with the reference image, the cross-correlation is maximized. From Wikimedia.

The simplest method to correct for image drift is to use a cross-correlation measurement. This method works best for fluorescence images or other other images where there are easy features that are recognizable in the image. This method is also often referred to as template matching.

Assume that we have a reference image and a moving image. To register the two images, one can calculate the cross-correlation. To calculate a cross-correlation, the two images are displaced from each other. The product of the overlapping sections between the two images is then calculated and summed. This calculation is repeated for all possible displacements over the x and y axes. The displacement is then given by the position of the maximum cross-correlation to the center of the image.

Cross-correlation calculations are typically computationally expensive. To speed up the process, one can take the 2D Fourier Transform instead. Thus, the equations to calculate the cross-correlation can be given by



where denotes the Fourier transform, is the complex conjugate, and is the inverse transform.

Example code

Example of an implementation in MATLAB:

function pxShift = xcorrreg(refImg, movedImg)
%REGISTERIMG  Register two images using cross-correlation
%
%  P = xcorrreg(R, M) registers two images by calculating the
%  cross-correlation between them. R is the reference or stationary image,
%  and M is the moved image. The output P will be a 1-by-2 vector with the
%  [x, y] offsets.
%
%  Note: This algorithm only works for translational shifts, and will not
%  work for rotational shifts or image resizing.

%Compute the cross-correlation of the two images
crossCorr = ifft2((fft2(refImg) .* conj(fft2(movedImg))));

%Find the location in pixels of the maximum correlation
[xMax, yMax] = find(crossCorr == max(crossCorr(:)));

%Compute the relative shift in pixels
Xoffset = fftshift(-size(refImg,1)/2:(size(refImg,1)/2 - 1));
Yoffset = fftshift(-size(refImg,2)/2:(size(refImg,2)/2 - 1));

pxShift = round([Xoffset(xMax), Yoffset(yMax)]);

end