FUNCTION REFERENCE

imregtform

Estimate the geometric transformation that aligns two 2-D images (intensity-based registration).

Estimate the geometric transformation that aligns two 2-D images (intensity-based registration).

Syntax

tform = imregtform(moving, fixed, transformType, optimizer, metric)

Syntax

tform = imregtform(moving, Rmoving, fixed, Rfixed, transformType, optimizer, metric)

Syntax

tform = imregtform(..., 'DisplayOptimization', tf, 'InitialTransformation', tform0, 'PyramidLevels', n)

moving and fixed are 2-D grayscale images of class single, double, int8, int16, int32, uint8, uint16 or uint32 (their sizes may differ); Rmoving and Rfixed (imref2d objects, default imref2d(size(image))) place them in world coordinates. transformType 'translation', 'rigid', 'similarity' or 'affine' (any case, a unique prefix is accepted) gives a transltform2d, rigidtform2d, simtform2d or affinetform2d. tform maps moving world coordinates to fixed world coordinates, so imwarp(moving, Rmoving, tform, 'OutputView', Rfixed) lines moving up with fixed (imregister does exactly this). optimizer and metric come from imregconfig, and any optimizer works with any metric. 'monomodal' gives registration.optimizer.RegularStepGradientDescent and registration.metric.MeanSquares, the mean of the squared differences over the fixed pixels that land inside the moving image (linear interpolation; the half pixel beyond the outer pixel centres repeats the edge value). 'multimodal' gives registration.optimizer.OnePlusOneEvolutionary and registration.metric.MattesMutualInformation, minus the mutual information of the joint histogram of fixed and moving values (NumberOfHistogramBins bins per image over each image's value range, a fixed value counts in its bin, a moving value spreads over four bins with a cubic B-spline), which also aligns images whose brightness differs (for example an inverted image); it uses every fixed pixel, or with UseAllPixels false NumberOfSpatialSamples pixels drawn per pyramid level with a fixed seed. The search runs on an image pyramid of PyramidLevels levels (default 3), coarse to fine, each level half the size of the next; every dimension of both images needs at least 4*2^(PyramidLevels-1) pixels. At each level the regular step gradient descent starts with steps of MaximumStepLength, multiplies the step by RelaxationFactor whenever the gradient direction reverses, and stops when the gradient magnitude is below GradientMagnitudeTolerance, when the step is below MinimumStepLength or after MaximumIterations iterations. Step lengths are in pixels of the current level: each parameter is scaled by the root-mean-square distance a unit change of it moves the pixels, so one step length suits rotation, scale, shear and translation; GradientMagnitudeTolerance is compared with the gradient of the metric per pixel of movement, so for images with values in [0, 1] and little detail it can end the search a few tenths of a pixel early, because the tolerance is absolute like the documented property (lower it, for example to 1e-6, or scale the images to 0-255 for a finer result). The one-plus-one evolutionary optimizer tries one random step (normal variates from a fixed seed, so results repeat) from the current estimate per iteration and keeps it when the metric is lower; the search widens along the step by GrowthFactor after a success and narrows by GrowthFactor^(-1/4) after a failure. Each level starts with a search radius of InitialRadius and stops when the radius is at most Epsilon or after MaximumIterations iterations; InitialRadius and Epsilon are in the same pixel units as the step lengths, so the default InitialRadius (6.25e-3) starts with very small steps: for warps of more than a pixel or two raise MaximumIterations (300 recovers the examples here). InitialTransformation (default: no change) is the starting estimate; it can be any 2-D transformation object whose matrix has the form of transformType (a pure translation for 'translation', a rotation plus translation for 'rigid', ...). DisplayOptimization true prints, for every pyramid level, one line per iteration (metric value, gradient magnitude and step length; for OnePlusOneEvolutionary the best metric value and the search radius) and the reason the level stopped.

Example

[x, y] = meshgrid(1:64); fixed = exp(-((x - 26).^2 + (y - 34).^2)/60) + 0.8*exp(-((x - 40).^2 + (y - 24).^2)/30) + 0.6*exp(-((x - 38).^2 + (y - 44).^2)/40); [optimizer, metric] = imregconfig('monomodal'); moving = imwarp(fixed, transltform2d(2.5, -1.5), 'OutputView', imref2d(size(fixed))); tform = imregtform(moving, fixed, 'translation', optimizer, metric); tform.Translation   % about [-2.5 1.5]

Example

[x, y] = meshgrid(1:64); fixed = exp(-((x - 26).^2 + (y - 34).^2)/60) + 0.8*exp(-((x - 40).^2 + (y - 24).^2)/30) + 0.6*exp(-((x - 38).^2 + (y - 44).^2)/40); [optimizer, metric] = imregconfig('monomodal'); moving = imwarp(fixed, rigidtform2d(3, [1 -2]), 'OutputView', imref2d(size(fixed))); optimizer.GradientMagnitudeTolerance = 1e-6; tform = imregtform(moving, fixed, 'rigid', optimizer, metric, 'PyramidLevels', 2); tform.RotationAngle   % about -3 (-2.96; -2.45 with the default tolerance)

Example

[x, y] = meshgrid(1:64); fixed = exp(-((x - 26).^2 + (y - 34).^2)/60) + 0.8*exp(-((x - 40).^2 + (y - 24).^2)/30) + 0.6*exp(-((x - 38).^2 + (y - 44).^2)/40); [optimizer, metric] = imregconfig('multimodal'); optimizer.MaximumIterations = 300; moving = 1 - imwarp(fixed, transltform2d(2.5, -1.5), 'OutputView', imref2d(size(fixed))); tform = imregtform(moving, fixed, 'translation', optimizer, metric); tform.Translation   % about [-2.5 1.5] (inverted brightness)

Differences from MATLAB: the reference pages do not give the algorithm; MatRust chooses these: the pyramid filter ([1 3 3 1]/8 over pixel pairs) and the minimum image size, the parameter scaling and step units above (so OnePlusOneEvolutionary settings tuned for MATLAB can behave differently), metric gradients from central differences, the random generators and seeds, and the DisplayOptimization text. NumberOfHistogramBins is at most 4096. Results can differ from MATLAB's in the digits and, for hard cases, in the optimum found. 3-D volumes (imref3d), imregcorr, imregdemons and feature-based registration are not supported yet.

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.