2-D affine geometric transformation
affinetform2d object stores information about a 2-D affine
geometric transformation and enables forward and inverse transformations.
You can create an
affinetform2d object in these ways:
imregtform— Estimate a geometric transformation that maps a moving image to a fixed image using similarity optimization.
imregcorr— Estimate a geometric transformation that maps a moving image to a fixed image using phase correlation.
fitgeotform2d— Estimate a geometric transformation that maps pairs of control points between two images.
randomAffine2d— Create a randomized 2-D affine transformation.
affinetform2dfunction described here.
tform = affinetform2d creates an
object that performs an identity transformation.
tform = affinetform2d( creates an
affinetform2d object and sets the property
A as the specified 2-D affine transformation matrix.
tform = affinetform2d( creates an
affinetform2d object from another geometric transformation object,
tformIn, that represents a valid 2-D affine geometric
tformIn — Affine 2-D geometric transformation
affinetform2d object |
rigidtform2d object |
simtform2d object |
transltform2d object |
A — Forward 2-D affine transformation
3-by-3 identity matrix (default) | nonsingular 3-by-3 numeric matrix
Forward 2-D affine transformation, specified as a nonsingular 3-by-3 numeric matrix.
When you create the object, you can also specify
A as a 2-by-3
numeric matrix. In this case, the object concatenates the row vector
1] to the end of the matrix, forming a 3-by-3 matrix. The default value of
A is the identity matrix.
transforms the point
(u, v) in the input coordinate space to the
point (x, y) in the output coordinate space using
For an affine transformation,
A has the form:
Dimensionality — Dimensionality of geometric transformation
This property is read-only.
Dimensionality of the geometric transformation for both input and output points,
specified as the value
Create 2-D Affine Transformation
Define a 3-by-3 geometric transformation matrix. This example specifies a matrix for an affine transformation consisting of vertical shear and horizontal stretch.
A = [2 0 0; 0.33 1 0; 0 0 1];
affinetform2d object from the transformation matrix.
tform = affinetform2d(A)
tform = affinetform2d with properties: Dimensionality: 2 A: [3x3 double]
Read and display an image.
I = imread("pout.tif"); imshow(I)
Apply the geometric transformation to the image, and display the result.
J = imwarp(I,tform); imshow(J)
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
affinetform2dsupports the generation of C code (requires MATLAB® Coder™). For more information, see Code Generation for Image Processing.
When generating code, you can only specify singular objects. Arrays of objects are not supported.
Run code in the background using MATLAB®
backgroundPool or accelerate code with Parallel Computing Toolbox™
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Version HistoryIntroduced in R2022b
R2022b: Recommended over
Starting in R2022b, most Image Processing Toolbox™ functions create and perform geometric transformations using the premultiply
affinetform2d object stores information about 2-D affine
geometric transformations in a format consistent with the premultiply convention.
affine2d object is not recommended because it
uses the postmultiply convention. Although there are no plans to remove the
affine2d object at this time, you can streamline your geometric
transformation workflows by switching to the
affinetform2d object. For more
information, see Migrate Geometric Transformations to Premultiply Convention.