Documentation Center

  • Trial Software
  • Product Updates

imregtform

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

Syntax

  • tform = imregtform(moving,fixed,transformType,optimizer,metric) example
  • tform = imregtform(moving,Rmoving,fixed,Rfixed,transformType,optimizer,metric)
  • tform = imregtform(___,Name,Value)

Description

example

tform = imregtform(moving,fixed,transformType,optimizer,metric) estimates the geometric transformation that aligns the moving image moving with the fixed image fixed. transformType is a string that defines the type of transformation to estimate. optimizer is an object that describes the method for optimizing the metric. metric is an object that defines the quantitative measure of similarity between the images to optimize. The output tform is a geometric transformation object that maps moving to fixed.

tform = imregtform(moving,Rmoving,fixed,Rfixed,transformType,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 pairs to control aspects of the operation.

Examples

expand all

Estimate the transformation needed to register two misaligned images

Read two slightly misaligned magnetic resonance images of a knee obtained using different protocols and view the images overlaid on each other.

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

imshowpair(fixed, moving,'Scaling','joint');

Get default optimizer and metric configurations suitable for registering images from different sensors (‘multimodal'). Then tune the properties of the optimizer to get the problem to converge on a global maxima and to allow for more iterations.

[optimizer, metric] = imregconfig('multimodal')

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 = 

  affine2d with properties:

                 T: [3x3 double]
    Dimensionality: 2

Apply the transformation to the image being registered (moving) using the imwarp function. The example uses the 'OutputView' parameter to preserve world limits and resolution of the fixed image when forming the transformed image.

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

View registered images

figure
imshowpair(fixed, movingRegistered,'Scaling','joint');

Input Arguments

expand all

moving — Image to be registered2-D or 3-D grayscale image

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

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

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 or imref3d.

fixed — Reference image in the target orientation2-D or 3-D grayscale image

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

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

Rfixed — Spatial referencing information associated with the reference (fixed) imagespatial referencing object of type imref2d or imref3d

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

transformType — Geometric transformation to be applied to the image to be registered'translation' | 'rigid' | 'similarity' | 'affine'

Geometric transformation to be applied to the image to be registered, specified as one of the text strings listed in this table.

Transform TypeDescription
'translation'(x,y) translation.
'rigid'Rigid transformation consisting of translation and rotation.
'similarity'Nonreflective similarity transformation consisting of translation, rotation, and scale.
'affine'Affine transformation consisting of translation, rotation, scale, and shear.

The 'similarity' and 'affine' transformation types always involve nonreflective transformations.

optimizer — Method for optimizing the similarity metricoptimizer object

Method for optimizing the similarity metric, specified as an optimizer object. Use imregconfig to create the optimizer objects registration.optimizer.RegularStepGradientDescent or registration.optimizer.OnePlusOneEvolutionary.

metric — Image similarity metric to be optimized during registrationmetric object

Image similarity metric to be optimized during registration, specified as a metric object. Use imregconfig to create the metric objects registration.metric.MeanSquares or registration.metric.MattesMutualInformation.

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: 'DisplayOptimization',1 enables verbose optimization mode.

'DisplayOptimization' — Verbose optimization flagfalse (default) | true

Verbose optimization flag, specified as a logical value, either true or false. Controls whether imregister displays optimization information in the command window during the registration process.

Data Types: logical

'InitialTransformation' — Spatial transformation to start ataffine2d or affine3d spatial transformation object

Spatial transformation to start at, specified as an affine2d or affine3d geometric transformation object.

'PyramidLevels' — Number of multi-level image pyramid levels used during the registration process3 (default) | positive integer

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

expand all

tform — Geometric transformationgeometric transformation objectaffine2d or affine3d

Geometric transformation, specified as a geometric transformation object, affine2d or affine3d. If the input matrices are 3-D, imregtform returns an affine3d object.

More About

expand all

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 taken into account.

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

See Also

| | | | | | |

Was this topic helpful?