# imregcorr

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

## Syntax

``tform = imregcorr(moving,fixed)``
``tform = imregcorr(moving,fixed,transformtype)``
``tform = imregcorr(moving,Rmoving,fixed,Rfixed,___)``
``tform = imregcorr(___,Name,Value,___)``

## 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,fixed,transformtype)` estimates the geometric transformation, where `transformtype` is a string scalar or character vector that specifies the type of transformation.```
````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(___,Name,Value,___)` registers the moving image to the fixed image using name-value pairs to control various aspects of the registration algorithm.```

## 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.

```theta = 20; S = 2.3; tform = affine2d([S.*cosd(theta) -S.*sind(theta) 0; ... S.*sind(theta) S.*cosd(theta) 0; ... 0 0 1]); moving = imwarp(fixed,tform); 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 estimated geometric transform to the moving image. This example uses the `'OutputView'` parameter 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

Image to be registered, specified as a grayscale, binary, or RGB image. If you specify an RGB image, `imregcorr` converts it to a grayscale image 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. If you specify an RGB image, `imregcorr` converts it to a grayscale image 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`

Type of transformation to estimate, specified as one of the following values.

ValueDescription
`'translation'`Translation
`'rigid'`Translation and rotation
`'similarity'`Translation, rotation, and 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`

Spatial referencing information associated with the image to be registered, specified as an `imref2d` object.

Spatial referencing information associated with the reference (fixed) image, specified as an `imref2d` object.

### Name-Value Pair Arguments

Specify optional comma-separated pairs of `Name,Value` arguments. `Name` is the argument name and `Value` is the corresponding value. `Name` must appear inside quotes. You can specify several name and value pair arguments in any order as `Name1,Value1,...,NameN,ValueN`.

Example: ```tformEstimate = imregcorr(moving,fixed,'Window',true);```

Logical flag to control use of windowing to suppress spectral leakage effects in frequency domain, specified as the comma-separated pair consisting of `'Window'` and a logical scalar. When set to `true`, `imregcorr` uses a Blackman window to increase the stability of registration results. If the common features you are trying to align in your images are oriented along the edges, setting `'Window'` to `false` can sometimes provide superior registration results.

Example: ```tformEstimate = imregcorr(moving,fixed,'Window',true);```

Data Types: `logical`

## Output Arguments

collapse all

Geometric transformation, returned as a geometric transformation object of type `affine2d`.

## 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

Download now