To perform a general 2-D geometric transformation, follow this process:
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.
The following figure illustrates this process.
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:
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.
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 Transform||Transformation Matrix|
|Shear||x,y shear:||x,z shear:||y, z shear:|
|Rotation||About x axis:||About y axis:||About z axis:|
The following example defines the transformation matrix for
a translation and creates an
xform = [ 1 0 0 0 1 0 40 40 1 ]; tform_translate = affine2d(xform);
tform_translate = affine2d with properties: T: [3x3 double] Dimensionality: 2
You can create a geometric transformation object by passing
two sets of control point pairs to the
fitgeotrans function estimates the transformation
from these points and returns one of the geometric transformation
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
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
Once you define the transformation in a geometric transformation
object, you can perform the transformation by calling the
passing it the image to be transformed and a geometric transformation
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.