Documentation

2-D Geometric Transformation Process Overview

To perform a general 2-D geometric transformation, follow this process:

  1. Define Parameters of the Geometric Transformation — To do this, you must create a geometric transformation object. The toolbox provides several ways to create a geometric transformation object.

  2. Perform the Geometric Transformation— To do this, you pass the image to be transformed and the geometric transformation object to the imwarp function.

The following figure illustrates this process.

Define Parameters of the Geometric Transformation

Before you can perform a geometric transformation, you must first define the parameters of the transformation in a geometric transformation object. The following sections describe two ways you can do this:

Using a Transformation Matrix

If you know the transformation matrix for the geometric transformation you want to perform, you can create one of the geometric transformation objects directly, passing the transformation matrix as a parameter.

For example, you can use a 3-by-3 matrix to specify any of the affine transformations. For affine transformations, the last column must contain 0 0 1 ([zeros(N,1); 1]). The following table lists 2-D affine transformations with the transformation matrix used to define them. You can combine multiple affine transformations into a single matrix.

Affine Transform

Example

Transformation Matrix

Translation

tx specifies the displacement along the x axis

ty specifies the displacement along the y axis.

Scale

sx specifies the scale factor along the x axis

sy specifies the scale factor along the y axis.

Shear

shx specifies the shear factor along the x axis

shy specifies the shear factor along the y axis.

Rotation

q specifies the angle of rotation.

The following table lists the 3-D affine transformations with the transformation matrix used to define them. Note that in the 3-D case, there are multiple matrices, depending on how you want to rotate or shear the image.

3-D Affine TransformTransformation Matrix  
Translation

[100001000010txtytz1]

  
Scale

[sx0000sy0000sz00001]

  
Shearx,y shear:

x'=x+azy'=y+bzz'=z

[10000100ab100001]

x,z shear:

x'=x+ayy'=yz'=z+cy

[1000a1c000100001]

y, z shear:

x'=xy'=y+bxz'=z+cx

[1bc0010000100001]

RotationAbout x axis:

[10000cos(a)sin(a)00sin(a)cos(a)00001]

About y axis:

[cos(a)0sin(a)00100sin(a)0cos(a)00001]

About z axis:

[cos(a)sin(a)00sin(a)cos(a)0000000001]

The following example defines the transformation matrix for a translation and creates an affine2d geometric transformation object.

xform = [ 1 0 0
          0 1 0
         40 40 1 ];

tform_translate = affine2d(xform);
tform_translate = 

  affine2d with properties:

                 T: [3x3 double]
    Dimensionality: 2

Using Sets of Points

You can create a geometric transformation object by passing two sets of control point pairs to the fitgeotrans function. The fitgeotrans function estimates the transformation from these points and returns one of the geometric transformation objects.

Different transformations require a varying number of points. For example, affine transformations require three non-collinear points in each image (a triangle) and projective transformations require four points (a quadrilateral).

This example passes two sets of control points to fitgeotrans, which returns an affine geometric transformation object.

movingPoints = [11 11;21 11; 21 21];
fixedPoints = [51 51;61 51;61 61];

tform = fitgeotrans(movingPoints,fixedPoints,'affine')
tform = 

  affine2d with properties:

                 T: [3x3 double]
    Dimensionality: 2

Perform the Geometric Transformation

Once you define the transformation in a geometric transformation object, you can perform the transformation by calling the imwarp function, passing it the image to be transformed and a geometric transformation object. The imwarp function performs the specified transformation on the coordinates of the input image and creates an output image. To see an illustration of this process, see Perform Simple 2-D Translation Transformation.

Was this topic helpful?