Main Content

imregtform

Estimate geometric transformation that aligns two 2-D or 3-D images

Description

tform = imregtform(moving,fixed,tformType,optimizer,metric) estimates the geometric transformation that aligns the moving image moving with the fixed image fixed. tformType defines the type of transformation to estimate. optimizer describes the method for optimizing the metric. metric defines the quantitative measure of similarity between the images to optimize.

example

tform = imregtform(moving,Rmoving,fixed,Rfixed,tformType,optimizer,metric) estimates the geometric transformation where Rmoving and Rfixed specify the spatial referencing objects associated with the moving and fixed images. The output tform is a geometric transformation object in units defined by the spatial referencing objects Rmoving and Rfixed.

tform = imregtform(___,Name=Value) estimates the geometric transformation using name-value arguments to control aspects of the operation.

Examples

collapse all

Read two images. This example uses two magnetic resonance (MRI) images of a knee. The fixed image is a spin echo image, while the moving image is a spin echo image with inversion recovery. The two sagittal slices were acquired at the same time but are slightly out of alignment.

fixed = dicomread("knee1.dcm");
moving = dicomread("knee2.dcm");

View the misaligned images.

imshowpair(fixed,moving,"Scaling","joint")

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

Create the optimizer and metric. Specify the modality to "multimodal" because the images come from different sensors.

[optimizer,metric] = imregconfig("multimodal")
optimizer = 
  registration.optimizer.OnePlusOneEvolutionary

  Properties:
         GrowthFactor: 1.050000e+00
              Epsilon: 1.500000e-06
        InitialRadius: 6.250000e-03
    MaximumIterations: 100
metric = 
  registration.metric.MattesMutualInformation

  Properties:
    NumberOfSpatialSamples: 500
     NumberOfHistogramBins: 50
              UseAllPixels: 1

Tune the properties of the optimizer to get the problem to converge on a global maxima and to allow for more iterations.

optimizer.InitialRadius = 0.009;
optimizer.Epsilon = 1.5e-4;
optimizer.GrowthFactor = 1.01;
optimizer.MaximumIterations = 300;

Find the geometric transformation that maps the image to be registered (moving) to the reference image (fixed).

tform = imregtform(moving,fixed,"affine",optimizer,metric)
tform = 
  affinetform2d with properties:

    Dimensionality: 2

                 A: [ 1.0408   -0.0768   -0.6511
                     -0.0429    1.0374  -10.1764
                           0         0    1.0000]

Apply the transformation to the image being registered (moving) using the imwarp function. The example uses the "OutputView" name-value argument to preserve world limits and resolution of the reference image when forming the transformed image.

movingRegistered = imwarp(moving,tform,"OutputView",imref2d(size(fixed)));

View the registered images.

figure
imshowpair(fixed,movingRegistered,"Scaling","joint")

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

Input Arguments

collapse all

Image to be registered, specified as a 2-D grayscale image or 3-D grayscale volume.

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

Reference image in the target orientation, specified as a 2-D grayscale image or 3-D grayscale volume.

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

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

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

Geometric transformation type, specified as one of these values:

ValueDescription
"translation"Translation transformation
"rigid"Rigid transformation: translation and rotation
"similarity"Similarity transformation: translation, rotation, and isotropic scaling
"affine"Affine transformation: translation, rotation, anisotropic scaling, and shearing

The "similarity" and "affine" transformation types do not support reflection.

Data Types: char | string

Method for optimizing the similarity metric, specified as a RegularStepGradientDescent or OnePlusOneEvolutionary object.

Image similarity metric to be optimized during registration, specified as a MeanSquares or MattesMutualInformation object.

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: PyramidLevels=4 uses four pyramid levels.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: "PyramidLevels",4 uses four pyramid levels.

Display optimization information in the command window during the registration process, specified as the logical value true or false.

Data Types: logical

Initial geometric transformation, specified as a geometric transformation object listed in the table.

Geometric Transformation ObjectDescription
2-D Geometric Transformations
transltform2dTranslation transformation
rigidtform2dRigid transformation: translation and rotation
simtform2dSimilarity transformation: translation, rotation, and isotropic scaling
affinetform2dAffine transformation: translation, rotation, anisotropic scaling, reflection, and shearing
3-D Geometric Transformations
transltform3dTranslation transformation
rigidtform3dRigid transformation: translation and rotation
simtform3dSimilarity transformation: translation, rotation, and isotropic scaling
affinetform3dAffine transformation: translation, rotation, anisotropic scaling, reflection, and shearing

Note

You can also specify InitialTransformation as an affine2d object or an affine3d object. However, these objects are not recommended. For more information, see Version History.

Number of pyramid levels used during the registration process, specified as a positive integer.

Example: PyramidLevels=4 sets the number of pyramid levels to 4.

Output Arguments

collapse all

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

Transformation Type

2-D Geometric Transformation Object3-D Geometric Transformation Object
"translation"transltform2dtransltform3d
"rigid"rigidtform2drigidtform3d
"similarity"simtform2dsimtform3d
"affine"affinetform2daffinetform3d

Tips

  • When you have spatial referencing information available, it is important to provide this information to imregtform, using spatial referencing objects. This information helps imregtform converge to better results more quickly because scale differences can be considered.

  • Both imregtform and imregister use the same underlying registration algorithm. imregister performs the additional step of resampling moving to produce the registered output image from the geometric transformation estimate calculated by imregtform. Use imregtform when you want access to the geometric transformation that relates moving to fixed. Use imregister when you want a registered output image.

  • Getting good results from optimization-based image registration usually requires modifying optimizer and/or metric settings for the pair of images being registered. The imregconfig function provides a default configuration that should only be considered a starting point. See the output of the imregconfig for more information on the different parameters that can be modified.

Version History

Introduced in R2013a

expand all