Documentation

fitgeotrans

Fit geometric transformation to control point pairs

Syntax

tform = fitgeotrans(movingPoints,fixedPoints,transformationType)
tform = fitgeotrans(movingPoints,fixedPoints,'polynomial',degree)
tform = fitgeotrans(movingPoints,fixedPoints,'pwl')
tform = fitgeotrans(movingPoints,fixedPoints,'lwm',n)

Description

example

tform= fitgeotrans(movingPoints,fixedPoints,transformationType)takes the pairs of control points,movingPointsandfixedPoints, and uses them to infer the geometric transformation specified bytransformationType.

tform= fitgeotrans(movingPoints,fixedPoints,'polynomial',degree)fits aPolynomialTransformation2Dobject to control point pairsmovingPointsandfixedPoints. Specify the degree of the polynomial transformationdegree, which can be 2, 3, or 4.

tform= fitgeotrans(movingPoints,fixedPoints,'pwl')fits aPiecewiseLinearTransformation2Dobject to control point pairsmovingPointsandfixedPoints. This transformation maps control points by breaking up the plane into local piecewise-linear regions. A different affine transformation maps control points in each local region.

tform= fitgeotrans(movingPoints,fixedPoints,'lwm',n)fits aLocalWeightedMeanTransformation2Dobject to control point pairsmovingPointsandfixedPoints. The local weighted mean transformation creates a mapping, by inferring a polynomial at each control point using neighboring control points. The mapping at any location depends on a weighted average of these polynomials. Thenclosest points are used to infer a second degree polynomial transformation for each control point pair.

Examples

collapse all

This example shows how to create a geometric transformation that can be used to align two images.

Create a checkerboard image and rotate it to create a misaligned image.

I = checkerboard(40); J = imrotate(I,30); imshowpair(I,J,'montage')

Define some matching control points on the fixed image (the checkerboard) and moving image (the rotated checkerboard). You can define points interactively using the Control Point Selection tool.

fixedPoints = [41 41; 281 161]; movingPoints = [56 175; 324 160];

Create a geometric transformation that can be used to align the two images, returned as anaffine2dgeometric transformation object.

tform = fitgeotrans(movingPoints,fixedPoints,'NonreflectiveSimilarity')
tform = affine2d with properties: T: [3x3 double] Dimensionality: 2

Use thetformestimate to resample the rotated image to register it with the fixed image. The regions of color (green and magenta) in the false color overlay image indicate error in the registration. This error comes from a lack of precise correspondence in the control points.

Jregistered = imwarp(J,tform,'OutputView',imref2d(size(I))); figure imshowpair(I,Jregistered)

Recover angle and scale of the transformation by checking how a unit vector parallel to the x-axis is rotated and stretched.

u = [0 1]; v = [0 0]; [x, y] = transformPointsForward(tform, u, v); dx = x(2) - x(1); dy = y(2) - y(1); angle = (180/pi) * atan2(dy, dx)
angle = 29.7686
scale = 1 / sqrt(dx^2 + dy^2)
scale = 1.0003

Input Arguments

collapse all

x- andy-coordinates of control points in the image you want to transform, specified as anm-by-2 double matrix.

Example:movingPoints = [11 11; 41 71];

Data Types:double|single

x- andy- coordinates of control points in the fixed image, specified as anm-by-2 double matrix.

Example:fixedPoints = [14 44; 70 81];

Data Types:double|single

Type of transformation, specified as one of the following:'nonreflectivesimilarity','similarity','affine', or'projective'. For more information, seeTransformation Types.

Data Types:char|string

Degree of the polynomial, specified as the integer 2, 3, or 4.

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

Number of points to use in local weighted mean calculation, specified as a numeric value.ncan be as small as 6, but makingnsmall risks generating ill-conditioned polynomials

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

Output Arguments

collapse all

Transformation, returned as a transformation object. The type of object depends on the transformation type. For example, if you specify the transformation type'affine',tformis anaffine2dobject. If you specify'pwl',tformis animage.geotrans.PiecewiseLinearTransformation2dobject.

More About

collapse all

Transformation Types

表中列出了所有转换类型rted byfitgeotransin order of complexity.

Transformation Type

Description Minimum Number of Control Point Pairs Example
'nonreflective similarity' Use this transformation when shapes in the moving image are unchanged, but the image is distorted by some combination of translation, rotation, and scaling. Straight lines remain straight, and parallel lines are still parallel. 2

'similarity' Same as'nonreflective similarity'with the addition of optional reflection. 3

'affine' Use this transformation when shapes in the moving image exhibit shearing. Straight lines remain straight, and parallel lines remain parallel, but rectangles become parallelograms. 3

'projective' Use this transformation when the scene appears tilted. Straight lines remain straight, but parallel lines converge toward a vanishing point. 4

'polynomial' Use this transformation when objects in the image are curved. The higher the order of the polynomial, the better the fit, but the result can contain more curves than the fixed image.

6 (order 2)

10 (order 3)

15 (order 4)

'piecewise linear' Use this transformation when parts of the image appear distorted differently. 4

'lwm' Use this transformation (local weighted mean), when the distortion varies locally and piecewise linear is not sufficient. 6 (12 recommended)

References

[1] Goshtasby, Ardeshir, "Piecewise linear mapping functions for image registration," Pattern Recognition, Vol. 19, 1986, pp. 459-466.

[2] Goshtasby, Ardeshir, "Image registration by local approximation methods," Image and Vision Computing, Vol. 6, 1988, pp. 255-261.

Extended Capabilities

Introduced in R2013b

Was this topic helpful?