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:
TFORM
, that specifies the type of transformation you want to perform
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.
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.
Note
When used with imtransform , TFORM structures must define a 2-D spatial transformation. If an image contains more than two dimensions, such as an RGB image, the same 2-D transformation is automatically applied to all 2-D planes along the higher dimensions. For arbitrary-dimensional array transformations, use the tformarray function.
|
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.
I = checkerboard(20,1,1); figure; imshow(I) T = maketform('projective',[1 1; 41 1; 41 41; 1 41],... [5 5; 40 5; 35 30; -10 30]); R = makeresampler('cubic','circular'); K = imtransform(I,T,R,'Size',[100 100],'XYScale',1); figure, imshow(K)
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 | ![]() |