Main Content

Matrix Representation of Geometric Transformations

You can represent a linear geometric transformation as a numeric matrix. Each type of transformation, such as translation, scaling, rotation, and reflection, is defined using a matrix whose elements follow a specific pattern. You can combine multiple transformations by taking a composite of the matrices representing the transformations. For more information, see Create Composite 2-D Affine Transformations.

2-D Affine Transformations

The table lists 2-D affine transformations with the transformation matrix used to define them. For 2-D affine transformations, the last row must be [0 0 1].

  • Use combinations of 2-D translation matrices to create a transltform2d object representing a translation transformation.

  • Use combinations of 2-D translation and rotation matrices to create a rigidtform2d object representing a nonreflective rigid transformation.

  • Use combinations of 2-D translation, rotation, and scaling matrices to create a simtform2d object representing a nonreflective similarity transformation.

  • Use any combination of 2-D transformation matrices to create an affinetform2d object representing a general affine transformation.

2-D Affine TransformationExample (Original and Transformed Image)Transformation Matrix
Translation

Original and translated checkerboard images. The axes limits indicate that the image has been translated horizontally and vertically.

[10tx01ty001]

tx specifies the displacement along the x axis

ty specifies the displacement along the y axis.

For more information about pixel coordinates, see Image Coordinate Systems.

Scale

Original and scaled checkerboard image. The scaled image appears stretched in the horizontal direction.

[sx000sy0001]

sx specifies the scale factor along the x axis

sy specifies the scale factor along the y axis.

Shear

Original and sheared checkerboard image. The sheared image appears stretched along the horizontal axis.

[1shx0shy10001]

shx specifies the shear factor along the x axis.

shy specifies the shear factor along the y axis.

Reflection

Original and horizontally reflected checkerboard image

[cosd(2φ)sind(2φ)0sind(2φ)cosd(2φ)0001]

φ specifies the angle of the axis of reflection, in degrees.

Two common reflections are vertical and horizontal reflection. Vertical reflection is reflection about the x-axis, so φ is 0 and the reflection matrix simplifies to:

[1 0 0; 0 -1 0; 0 0 1].

Horizontal reflection is reflection about the y-axis, so φ is 90 and the reflection matrix simplifies to:

[-1 0 0; 0 1 0; 0 0 1]

Rotation

Original and rotated checkerboard image. The transformed image has been rotated approximately 30 degrees clockwise.

[cosd(θ)sind(θ)0sind(θ)cosd(θ)0001]

θ specifies the angle of rotation about the origin, in degrees.

2-D Projective Transformations

Projective transformation enables the plane of the image to tilt. Parallel lines can converge towards a vanishing point, creating the appearance of depth.

The transformation is a 3-by-3 matrix. Unlike affine transformations, there are no restrictions on the last row of the transformation matrix. Use any composition of 2-D affine and projective transformation matrices to create a projtform2d object representing a general projective transformation.

2-D Projective Transformation ExampleTransformation Matrix
Tilt

Original and projected checkerboard image. The transformed image appears tilted into a different plane.

[100010EF1]

E and F influence the vanishing point.

When E and F are large, the vanishing point comes closer to the origin and thus parallel lines appear to converge more quickly.

3-D Affine Transformations

The 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. For 3-D affine transformations, the last row must be [0 0 0 1].

  • Use combinations of 3-D translation matrices to create a transltform3d object representing a translation transformation.

  • Use combinations of 3-D translation and rotation matrices to create a rigidtform3d object representing a nonreflective rigid transformation.

  • Use combinations of 3-D translation, rotation, and scaling matrices to create a simtform3d object representing a nonreflective similarity transformation.

  • Use any combination of 3-D transformation matrices to create an affinetform3d object representing a general affine transformation.

3-D Affine TransformationTransformation Matrix
Translation

Translation by amount tx, ty, and tz in the x, y, and z directions, respectively:

[100tx010ty001tz0001]

Scale

Scale by scale factor sx, sy, and sz in the x, y, and z dimensions, respectively:

[sx0000sy0000sz00001]

Shear

Shear within the y-z plane:

[1000shxy100shxz0100001]

such that

x'=xy'=y+shxyxz'=z+shxzx

Shear within the x-z plane:

[1shyx0001000shyz100001]

such that

x'=x+shyxyy'=yz'=z+shyzy

Shear within the x-y plane:

[10shzx001shzy000100001]

such that

x'=x+shzxzy'=y+shzyzz'=z

Reflection

Reflection across the y-z plane, negating the x coordinate:

[1000010000100001]

Reflection across the x-z plane, negating the y coordinate:

[1000010000100001]

Reflection across the x-y plane, negating the z coordinate:

[1000010000100001]

Rotation

Rotation within the y-z plane, by angle θx about the x axis, in degrees:

[10000cosd(θx)sind(θx)00sind(θx)cosd(θx)00001]

Rotation within the x-z plane, by angle θy about the y axis, in degrees:

[cosd(θy)0sind(θy)00100sind(θy)0cosd(θy)00001]

Rotation within the x-y plane, by angle θz about the z axis, in degrees:

[cosd(θz)sind(θz)00sind(θz)cosd(θz)0000100001]

3-D Projective and N-D Transformations

The imwarp function does not support 3-D projective transformations or N-D affine and projective transformations. Instead, you can create a spatial transformation structure from a geometric transformation matrix using the maketform function. Then, apply the transformation to an image using the tformarray function. For more information, see N-Dimensional Spatial Transformations.

The dimensions of the transformation matrix must be (N+1)-by-(N+1). The maketform and tformarray functions use the postmultiply matrix convention. Geometric transformation matrices in the postmultiply convention are the transpose of matrices in the premultiply convention. Therefore, for N-D affine transformation matrices, the last column must contain [zeros(N,1); 1] and there are no restrictions on the values of the last row.

See Also

| | | |

Related Examples

More About