Main Content

imregcorr

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

Description

example

tform = imregcorr(moving,fixed) estimates the geometric transformation that aligns an image, moving, with a reference image, fixed. The function returns a geometric transformation object, tform, that maps pixels in moving to pixels in fixed.

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 transformation object returned, tform, defines the point mapping in the world coordinate system.

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

tform = imregcorr(___,Window=window) also specifies whether to perform windowing in the frequency domain. To increase the stability of registration results, 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.

Before R2021a, use the equivalent syntax tform = imregcorr(__,"Window",window).

[tform,peakcorr] = imregcorr(___) also returns the peak correlation, peakcorr, of the phase difference between the two images.

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")

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")

imshowpair(fixed,movingReg,"falsecolor");

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.

Note

The aspect ratio of moving affects the output transform tform. For best results, use a square image.

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.

Note

The aspect ratio of fixed affects the output transform tform. For best results, use a square image.

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, the phase correlation algorithm is only scale invariant within some range of scale difference between the fixed and moving images. imregcorr limits the search space to scale differences within the range [1/4, 4]. imregcorr does not detect scale differences less than 1/4 or greater than 4.

Data Types: char | string

Use windowing to suppress spectral leakage effects in the frequency domain, specified as a numeric or logical 1 (true) or 0 (false). When true, the imregcorr function performs windowing using a Blackman filter.

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 of the phase difference between the two images, returned as a numeric scalar.

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.

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

Extended Capabilities

Version History

Introduced in R2014a

expand all