Image Processing Toolbox    

Performing General Spatial Transformations

To perform general 2-D spatial transformations, use the imtransform function. (For information about performing more advanced transformations, see Advanced Spatial Transformation Techniques.)

The imtransform function accepts two primary arguments:

Specifying the Transformation Type

You specify the type of transformation you want to perform in a TFORM structure. There are two ways to create a TFORM struct:

Using maketform

When you use the maketform function, you can specify the type of transformation you want to perform. The following table lists the types of transformations maketform supports.

Transformation
Description
'affine'
A transformation that may include translation, rotation, scaling, stretching and shearing. Straight lines remain straight, and parallel lines remain parallel, but rectangles may become parallelograms.
'projective'
A transformation in which straight lines remain straight, but parallel lines converge toward "vanishing points." (The vanishing points may fall inside or outside the image--even at infinity.)
'box'
A special case of an affine transformation where each dimension is shifted and scaled independently.
'custom'
A user-defined transformation, providing the forward and/or inverse functions that are called by imtransform.
'composite'
A composition of two or more transformations.

The 'custom' and 'composite' capabilities of maketform allow a virtually limitless variety of spatial transformations to be used with imtransform and/or tformarray.

Using cp2tform

You use cp2tform to create the TFORM when you want to perform a transformation that requires fitting of data points, such as a polynomial transformation. Image Registration explains how to use the cp2tform function to fit a 2-D transformation to a set of control points selected in a pair of images.

Performing the Transformation

Once you define the transformation in a TFORM struct, you can perform the transformation by calling imtransform.

For example, this code uses imtransform to perform a projective transformation of a checkerboard image.

The imtransform function options let you control many aspects of the transformation. For example, note how the transformed image appears to contain multiple copies of the original image. This is accomplished by using the 'Size' option, to make the output image larger than the input image, and then specifying a padding method that extends the input image by repeating the pixels in a circular pattern. The Image Processing Toolbox Image Transformation demos provide more examples of using the imtransform function, and related functions, to perform different types of spatial transformations.


  Image Cropping Advanced Spatial Transformation Techniques