Documentation Center

  • Trial Software
  • Product Updates

fitgeotrans

Fit geometric transformation to control point pairs

Syntax

  • tform = fitgeotrans(movingPoints,fixedPoints,transformationType) example
  • 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, movingPoints and fixedPoints, and uses them to infer the geometric transformation, specified by transformationType.

tform = fitgeotrans(movingPoints,fixedPoints,'polynomial',degree) fits an images.geotrans.PolynomialTransformation2D object to control point pairs movingPoints and fixedPoints. Specify the degree of the polynomial transformation degree, which can be 2, 3, or 4.

tform = fitgeotrans(movingPoints,fixedPoints,'pwl') fits an images.geotrans.PiecewiseLinearTransformation2D object to control point pairs movingPoints and fixedPoints. This transformation maps control points by breaking up the plane into local piecewise-linear regions in which a different affine transformation maps control points in each local region.

tform = fitgeotrans(movingPoints,fixedPoints,'lwm',n) fits an images.geotrans.LocalWeightedMeanTransformation2D object to 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 n closest points are used to infer a second degree polynomial transformation for each control point pair.

Examples

expand all

Create a geometric transformation that can be used to align the two images

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

I = checkerboard;
J = imrotate(I,30);

imshowpair(I,J,'montage')

Define some control points on the fixed image (the checkerboard) and moving image (the rotated checkerboard), using cpselect, the Control Point Selection tool.

fixedPoints  = [11 11; 41 71];
movingPoints = [14 44; 70 81];
cpselect(J,I,movingPoints,fixedPoints);

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

tform = fitgeotrans(movingPoints,fixedPoints,'NonreflectiveSimilarity');
tform = 

  affine2d with properties:

                 T: [3x3 double]
    Dimensionality: 2

Use the tform estimate to resample rotated image J to register it with I. The regions of color (green and magenta) in the false color overlay image indicate error in the registration due to lack of precise correspondence in the control points.

Jregistered = imwarp(J,tform,'OutputView',imref2d(size(I)));
falsecolorOverlay = imfuse(I,Jregistered);
figure, imshow(falsecolorOverlay,'InitialMagnification','fit');

Recover angle and scale 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) 
scale = 1 / sqrt(dx^2 + dy^2) 
angle =

   29.9816

scale =

    1.0006

Input Arguments

expand all

movingPointsX and Y coordinates of control points in the image you want to transformm-by-2 double matrix

X and Y coordinates of control points in the image you want to transform, specified as an m-by-2 double matrix.

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

Data Types: double

fixedPointsX and Y coordinates of control points in the base imagem-by-2 double matrix

X and Y coordinates of control points in the base image, specified as an m-by-2 double matrix.

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

Data Types: double

transformationType — Type of transformation'NonreflectiveSimilarity' | 'Similarity' | 'Affine' | 'Projective'

Type of transformation, specified as one of the following text strings.

TypeDescription
'Affine'Affine transformation
'NonreflectiveSimilarity'Nonreflective similarity
'Projective'Projective transformation
'Similarity'Similarity

Example: tform = fitgeotrans(movingPoints,fixedPoints,'NonreflectiveSimilarity');

Data Types: char

degree — Degree of the polynomial2 | 3 | 4

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

Data Types: double

n — Number of points to use in local weighted mean calculationnumeric value

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

Data Types: double

Output Arguments

expand all

tform — Transformationtransformation object

Transformation, specified as a transformation object. The type of object depends on the transformation type. For example, if you specify the transformation type 'affine', tform is an affine2d object. If you specify 'pwl', tform is an image.geotrans.PiecewiseLinearTransformation2d object.

See Also

| | | | | |

Was this topic helpful?