Main Content

affine2d

(Not recommended) 2-D affine geometric transformation using postmultiply convention

affine2d is not recommended. Use the affinetform2d object instead. For more information, see Version History.

Description

An affine2d object stores information about a 2-D affine geometric transformation using the postmultiply convention, and enables forward and inverse transformations.

Creation

Description

tform = affine2d creates an affine2d object with default property settings that correspond to the identity transformation.

tform = affine2d(t) sets the property T as the specified 2-D affine transformation matrix t.

example

Properties

expand all

Forward 2-D affine transformation, specified as a nonsingular 3-by-3 numeric matrix. The matrix T uses the convention:

[x y 1] = [u v 1] * T

where T has the form:

 [a b 0;
  c d 0;
  e f 1];

The default of T is the identity transformation.

Data Types: double | single

This property is read-only.

Dimensionality of the geometric transformation for both input and output points, specified as the value 2.

Object Functions

invertInvert geometric transformation
isRigidDetermine if geometric transformation is rigid transformation
isSimilarityDetermine if geometric transformation is similarity transformation
isTranslationDetermine if geometric transformation is pure translation
outputLimitsFind output spatial limits given input spatial limits
transformPointsForwardApply forward geometric transformation
transformPointsInverseApply inverse geometric transformation

Examples

collapse all

Create an affine2d object that defines a 30 degree rotation in the counterclockwise direction around the origin.

theta = 30;
tform = affine2d([ ...
    cosd(theta) sind(theta) 0;...
    -sind(theta) cosd(theta) 0; ...
    0 0 1])
tform = 
  affine2d with properties:

                 T: [3x3 double]
    Dimensionality: 2

Apply the forward geometric transformation to a point (10,0).

[x,y] = transformPointsForward(tform,10,0)
x = 
8.6603
y = 
5

Validate the transformation by plotting the original point (in blue) and the transformed point (in red).

plot(10,0,'bo',x,y,'ro')
axis([0 12 0 12])
axis square

Figure contains an axes object. The axes object contains 2 objects of type line. One or more of the lines displays its values using only markers

Read an image into the workspace.

A = imread('pout.tif');

Create an affine2d object that defines an affine geometric transformation. This example combines vertical shear and horizontal stretch.

tform = affine2d([2 0.33 0; 0 1 0; 0 0 1])
tform = 
  affine2d with properties:

                 T: [3x3 double]
    Dimensionality: 2

Apply the geometric transformation to the image using imwarp.

B = imwarp(A,tform);

Display the resulting image.

figure
imshow(B);
axis on equal;

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

Extended Capabilities

Version History

Introduced in R2013a

expand all

R2022b: Not recommended

Starting in R2022b, most Image Processing Toolbox™ functions create and perform geometric transformations using the premultiply convention. Accordingly, the 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, which supports the premultiply convention. For more information, see Migrate Geometric Transformations to Premultiply Convention.

To update your code:

  • Change instances of the function name affine2d to affinetform2d.

  • Specify the transformation matrix as the transpose of the matrix T, where T is either the value of the T property of the affine2d object or the transformation matrix used to create the affine2d object.

Discouraged UsageRecommended Replacement

This example creates an affine2d object from transformation matrix T in the postmultiply convention.

T = [2 0.33 0; 0 1 0; 0 0 1];
tformPost = affine2d(T);

This example creates an affinetform2d object from the transpose of the transformation matrix T.

T = [2 0.33 0; 0 1 0; 0 0 1];
tform = affinetform2d(T');

This example starts with an affine2d object called tformPost and creates an affinetform2d object from the transpose of the T property of tformPost.

T = tformPost.T;
tform = affinetform2d(T');