Main Content

imregcorr

Estimate geometric transformation that aligns two 2-D images using cross correlation

Description

tform = imregcorr(moving,fixed) estimates the geometric transformation that aligns an image, moving, with a reference image, fixed, using gradient correlation.

example

tform = imregcorr(moving,Rmoving,fixed,Rfixed) estimates the geometric transformation that aligns an image, moving, with a reference image, fixed. Rmoving and Rfixed are spatial referencing objects that contain spatial information about the moving and fixed images, respectively. The geometric transformation, tform, defines the point mapping in the world coordinate system.

tform = imregcorr(___,tformType) also specifies the type of transformation, tformType.

tform = imregcorr(___,Name=Value) enables you to specify the cross correlation method as phase correlation, and to enable or disable windowing for phase correlation, using name-value arguments.

[tform,peakcorr] = imregcorr(___) also returns the peak correlation value, peakcorr.

Examples

collapse all

Read a reference image into the workspace.

fixed  = imread("cameraman.tif");

Create a synthetic moving image by scaling and rotating the fixed image.

scaleFactor = 2.3;
theta = 20;
translation = [0 0];
tform = simtform2d(scaleFactor,theta,translation);
moving = imwarp(fixed,tform);

Add synthetic noise to the moving image.

moving = moving + uint8(10*rand(size(moving)));

Display the fixed and the moving image alongside each other.

imshowpair(fixed,moving,"montage")

Figure contains an axes object. The hidden axes object contains an object of type image.

Estimate the transformation needed to align the images using imregcorr.

tformEstimate = imregcorr(moving,fixed);

Apply the estimated geometric transform to the moving image. Specify the "OutputView" name-value argument to obtain a registered image the same size and with the same world limits as the reference image.

Rfixed = imref2d(size(fixed));
movingReg = imwarp(moving,tformEstimate,"OutputView",Rfixed);

View the original image and the registered image side-by-side to check the registration. Then view the registered image overlaid on the original using the "falsecolor" option to highlight any areas where the images differ.

imshowpair(fixed,movingReg,"montage")

Figure contains an axes object. The hidden axes object contains an object of type image.

imshowpair(fixed,movingReg,"falsecolor");

Figure contains an axes object. The hidden axes object contains an object of type image.

Input Arguments

collapse all

Moving image, or the image to be registered, specified as a grayscale, binary, or RGB image. imregcorr converts RGB images to grayscale using rgb2gray before processing.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | logical

Reference image in the target orientation, specified as a grayscale, binary, or RGB image. imregcorr converts RGB images to grayscale using rgb2gray before processing.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | logical

Spatial referencing information of the moving image, specified as an imref2d object.

Spatial referencing information of the fixed image, specified as an imref2d object.

Type of transformation to estimate, specified as one of these values.

ValueDescription
"translation"

Translation transformation

When using the "translation" option with spatial referencing objects Rmoving and Rfixed, the input images must have the same pixel extents in world coordinates.

"rigid"

Rigid transformation: translation and rotation

When using the "rigid" option with spatial referencing objects Rmoving and Rfixed, the input images must have the same pixel extents in world coordinates.

"similarity"

Similarity transformation: translation, rotation, and isotropic scaling

When using the "similarity" option with the phase correlation method, imregcorr does not detect scale differences less than 1/4 or greater than 4.

Data Types: char | string

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: tform = imregcorr(moving,fixed,Method="phasecorr") uses phase correlation.

Since R2024b

Correlation method, specified as "gradcorr" for gradient correlation or "phasecorr" for phase correlation. If either input image is a vector, then use phase correlation.

Use windowing to suppress spectral leakage effects in the frequency domain, specified as a numeric or logical 1 (true) or 0 (false). When Window is true and Method is "phasecorr", the imregcorr function performs windowing using a Blackman filter. The function ignores the Window argument when Method is "gradcorr".

To increase the stability of registration results for phase correlation, specify Window as true. However, if the common features in your images are oriented along the edges, then setting Window to false can sometimes provide superior registration results.

Output Arguments

collapse all

Geometric transformation, returned as a geometric transformation object according to the type of transformation, tformType.

tformTypeGeometric Transformation Object
"translation"transltform2d
"rigid"rigidtform2d
"similarity"simtform2d

Peak correlation value between the two images, returned as a number in the range [0, 1]. A larger peak correlation value indicates more confidence in the estimated geometric transformation.

Tips

  • If your image is of type double, you can achieve performance improvements by casting the image to single with im2single before registration. Input images of type double cause the algorithm to compute FFTs in double.

  • Because of differences in the gradient correlation and phase correlation algorithms, the peak correlation value peakcorr should not be used as a metric to compare the performance of the algorithms.

References

[1] Reddy, B. S. and Chatterji, B. N. "An FFT-Based Technique for Translation, Rotation, and Scale-Invariant Image Registration." IEEE Transactions on Image Processing, Vol. 5, No. 8, August 1996.

[2] Tzimiropoulos, Georgios, Vasileios Argyriou, Stefanos Zafeiriou, and Tania Stathaki. “Robust FFT-Based Scale-Invariant Image Registration with Image Gradients.” IEEE Transactions on Pattern Analysis and Machine Intelligence 32, no. 10 (October 2010): 1899–1906. https://doi.org/10.1109/TPAMI.2010.107.

Extended Capabilities

Version History

Introduced in R2014a

expand all