# imregcorr

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

## Syntax

• ``tform = imregcorr(moving,fixed)``
example
• ``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 text string 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

### Register an image using phase correlation

Solve a registration problem in which an image is synthetically scaled and rotated.

Prepare the sample `fixed` and `moving` images.

```fixed = imread('cameraman.tif'); 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))); figure, imshowpair(fixed,moving,'montage');```

Estimate the transformation needed to align the images using `imregcorr`.

```tformEstimate = imregcorr(moving,fixed); ```

Apply estimated geometric transform to the image you want to align (`moving`). The example uses the `'OutputView'` parameter to obtain a registered image the same size and with the same world limits as the reference image. The example first views the original image and the registered image side-by-side to check the registration. The example then views the registered image overlaid on the original using the `'falsecolor'` option to highlight any areas where the images differ.

```Rfixed = imref2d(size(fixed)); movingReg = imwarp(moving,tformEstimate,'OutputView',Rfixed); figure, imshowpair(fixed,movingReg,'montage'); figure, imshowpair(fixed,movingReg,'falsecolor');```

## Input Arguments

collapse all

### `moving` — Image to be registeredgrayscale image | binary image | RGB image

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.

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

### `fixed` — Reference image in the target orientationgrayscale image | binary image | RGB image

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.

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

### `transformtype` — Type of transformation to estimate`‘similarity'` (default) | `'rigid'` | `'translation'`

Type of transformation to estimate, specified as one of the text strings in this table.

Transformation TypeDescription
`'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). Scale differences less than 1/4 or greater than 4 cannot be detected by `imregcorr`.

Data Types: `char`

### `Rmoving` — Spatial referencing information associated with the image to be registeredspatial referencing object

Spatial referencing information associated with the image to be registered, specified as a spatial referencing object of type `imref2d`.

### `Rfixed` — Spatial referencing information associated with the reference (fixed) imagespatial referencing object

Spatial referencing information associated with the reference (fixed) image, specified as a spatial referencing object of type `imref2d`.

### 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 single 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);`

### `'Window'` — Logical flag to control use of windowing to suppress spectral leakage effects in frequency domaintrue (default) | scalar logical

Logical flag to control use of windowing to suppress spectral leakage effects in frequency domain, specified as 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

### `tform` — Geometric transformationgeometric transformation object

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

expand all

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