To perform a 2-D or 3-D geometric transformation, follow this process:
Define Parameters of the Geometric Transformation — To do this,
you must create an
affine3d geometric transformation
object. The toolbox provides several ways to create a geometric transformation
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 a geometric transformation object directly, passing the transformation matrix in the constructor. For more information about creating a transformation matrix, see Matrix Representation of Geometric Transformations.
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
affine2d geometric transformation
movingPoints = [11 11;21 11; 21 21]; fixedPoints = [51 51;61 51;61 61]; tform_cpp = fitgeotrans(movingPoints,fixedPoints,'affine')
tform_cpp = 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
imwarp function, passing it the image
to be transformed and a geometric transformation object.
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.