Main Content

fitgeotform2d

Fit 2-D geometric transformation to control point pairs

Since R2022b

    Description

    tform = fitgeotform2d(movingPoints,fixedPoints,tformType) fits a linear geometric transformation of type tformType to the control point pairs movingPoints and fixedPoints.

    example

    tform = fitgeotform2d(movingPoints,fixedPoints,"polynomial",degree) fits a polynomial transformation of degree degree to the control point pairs movingPoints and fixedPoints. Specify the degree of the polynomial transformation degree, which can be 2, 3, or 4.

    tform = fitgeotform2d(movingPoints,fixedPoints,"pwl") fits a piecewise linear transformation to the control point pairs movingPoints and fixedPoints. This transformation creates a Delaunay triangulation of the fixed control points, and maps moving control points to the corresponding fixed control points. A different affine transformation maps control points in each local region. The mapping is continuous across the control points, but is not continuously differentiable.

    tform = fitgeotform2d(movingPoints,fixedPoints,"lwm",n) fits a local weighted mean transformation to the control point pairs movingPoints and fixedPoints. 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. The function uses the n closest points to infer a second degree polynomial transformation for each control point pair.

    Examples

    collapse all

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

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

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

    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 similarity geometric transformation that you can use to align the two images.

    tform = fitgeotform2d(movingPoints,fixedPoints,"similarity");

    Use the tform estimate 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)));
    imshowpair(I,Jregistered)

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

    Input Arguments

    collapse all

    Control points in the moving image, specified as an m-by-2 matrix. Each row specifies the (x, y) coordinate of a control point.

    The transformation type impacts the minimum number of control point pairs. For example, a similarity transformation without reflection requires at least two control point pairs. A fourth order polynomial transformation requires at least 15 control point pairs. For more information, see Transformation Types.

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

    Data Types: double | single

    Control points in the fixed image, specified as an m-by-2 matrix. Each row specifies the (x, y) coordinate of a control point.

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

    Data Types: double | single

    Type of linear transformation, specified as "similarity", "reflectivesimilarity", "affine", or "projective".

    Data Types: char | string

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

    Number of points to use in local weighted mean calculation, specified as a positive integer. n can be as small as 6, but a small n can generate ill-conditioned polynomials.

    Output Arguments

    collapse all

    Geometric transformation, returned as a geometric transformation object as defined in the table.

    Transformation Type

    Geometric Transformation Object
    "similarity"simtform2d
    "reflectivesimilarity"affinetform2d
    "affine"affinetform2d
    "projective"projtform2d
    "polynomial"PolynomialTransformation2D
    "pwl"PiecewiseLinearTransformation2D
    "lwm"LocalWeightedMeanTransformation2D

    More About

    collapse all

    Transformation Types

    The table lists the transformation types supported by fitgeotform2d in order of complexity.

    Transformation Type

    DescriptionMinimum Number of Control Point PairsExample
    "similarity"Use this transformation when shapes in the moving image are unchanged, but the image is distorted by some combination of translation, rotation, and isotropic scaling. Straight lines remain straight, and parallel lines are still parallel.2

    Image transformed using "similarity".

    "reflectivesimilarity" Same as "similarity", with the addition of optional reflection.3

    Image transformed using "reflectivesimilarity".

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

    Image transformed using "affine".

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

    Image transformed using "projective".

    "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)

    Image transformed using "polynomial".

    "pwl"Use this transformation (piecewise linear) when parts of the image appear distorted differently from each other.4

    Image transformed using "pwl".

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

    Image transformed using "lwm".

    The first five transformations, "similarity", "reflectivesimilarity", "affine", "projective", and "polynomial", are global transformations. In these transformations, a single mathematical expression applies to an entire image. The last two transformations, "pwl" (piecewise linear) and "lwm" (local weighted mean), are local transformations. In these transformations, different mathematical expressions apply to different regions within an image. When exploring how different transformations affect the images you are working with, try the global transformations first. If these transformations are not satisfactory, try the local transformations: the piecewise linear transformation first, and then the local weighted mean transformation.

    References

    [1] Goshtasby, Ardeshir. “Piecewise Linear Mapping Functions for Image Registration.” Pattern Recognition 19, no. 6 (January 1986): 459–66. https://doi.org/10.1016/0031-3203(86)90044-0.

    [2] Goshtasby, Ardeshir. “Image Registration by Local Approximation Methods.” Image and Vision Computing 6, no. 4 (November 1988): 255–61. https://doi.org/10.1016/0262-8856(88)90016-9.

    Extended Capabilities

    Version History

    Introduced in R2022b

    expand all