Documentation Center 
Apply projective or affine transformation to an image
Use the Apply Geometric Transformation block to apply projective or affine transform to an image. You can use this block to transform the entire image or portions of the image with either polygon or rectangle Regions of Interest (ROIs).
Port  Description 

Image  MbyN or MbyNbyP input
matrix. M: Number of rows in the image. N: Number of columns in the image. P: Number of color planes in the image. 
TForm  When you set the Transformation
matrix source parameter to Input port,
the TForm input port accepts:
Q: Number of transformations. When you specify multiple transforms in a single matrix, each transform is applied separately to the original image. If the individual transforms produce an overlapping area, the result of the transform in the last row of the matrix is overlaid on top. 
ROI  When you set the ROI source
parameter to Input port, the ROI input port accepts:
R: Number of Region of Interests (ROIs). L(L 3): Number of vertices in a polygon ROI. 
The size of the transformation matrix will dictate the transformation type.
For affine transformation, the value of the pixel located at in the output image, is determined by the value of the pixel located at in the input image. The relationship between the input and the output point locations is defined by the following equations:
where h_{1}, h_{2}, ... h_{6} are transformation coefficients.
If you use one transformation, the transformation coefficients must be arranged as a 3by2 matrix as in:
or in a 1by6 vector as in .
If you use more than one transformation, the transformation coefficients must be arranged as a Qby6 matrix, where each row has the format of , and Q is the number of transformations as in:
When you specify multiple transforms in a single matrix, each transform is applied separately to the original image. If the individual transforms produce an overlapping area, the result of the transform in the last row of the matrix is overlaid on top.
For projective transformation, the relationship between the input and the output points is defined by the following equations:
where h_{1}, h_{2}, ... h_{9} are transformation coefficients.
If you use one transformation, the transformation coefficients must be arranged as a 3by3 matrix as in:
or in a 1by9 vector as in, .
If you use more than one transformation, the transformation coefficients must be arranged as a Qby9 matrix, where each row has the format of , and Q is the number of transformations. For example,
The Main pane of the Apply Geometric Transformation dialog box appears as shown in the following figure.
Specify input matrix source, either Specified via dialog, or Input port. If you select Specify via dialog, you can enter the transformation matrix parameters in the parameter that appear with this selection.
Specify a 3by2, 3by3, Qby6,or aQby9 matrix. This option appears when you set the Transformation matrix source parameter to Specified via dialog.
Specify interpolation method, either Nearest neighbor, Bilinear, or Bicubic interpolation to calculate output pixel values. See Geometric Transformation Interpolation Methods for an overview of these methods.
Specify the value of the pixels that are outside of the input image. Use either a scalar value of Pelement vector.
Specify the output image size to be either Same as input image, or Specify via dialog. If you select to Specify via dialog, you can specify the bounding box in the size and location parameters that appear with this selection.
Specify the height and width for the output image size as[height width]. You can specify this parameter, along with the Location of the upper left corner [x y] parameter when you set the Output image size and position parameter to Specify via dialog.
Specify the [x y] location for the upper left corner of the output image. You can specify this parameter, along with the Size [height width] parameter, when you set the Output image size and position parameter to Specify via dialog.
Specify the region in which to process pixels. Specify Whole input image, Rectangle ROI, or Polygon ROI. If you select Rectangle ROI, or Polygon ROI the ROI source parameter becomes available.
The transformations will be applied on the whole image, or on specified multiple ROIs. The table below outlines how transformation matrices are handled with an entire image and with single and multiple ROIs.
Number of Transformation Matrices  Region of Interest 

One transformation matrix  You can apply the transformation on the entire image, single ROI or multiple ROIs. 
Multiple transformation matrices 

Specify the source for the region of interest (ROI), either Specify via dialog or Input port. This appears when you set the Process pixels in parameter to either Rectangle ROI, or Polygon ROI.
Specify a 4element vector or an Rby4 matrix , (where R represents the number of ROIs). This parameter appears when you set the Process pixels in parameter to Rectangle ROI.
Specify the rectangle by its topleft corner and size in width and height. If you specify one ROI, it must be a 4element vector of format [x y width height]. If you specify more than one ROI, it must be an Rby4 matrix, such that each row's format is [x y width height].
Specify a 2Lelement vector or an Rby2L matrix, (where R represents the number of ROIs and L is the number of vertices in a polygon). This parameter appears when you set the Process pixels in parameter to Polygon ROI.
Specify the polygon by its vertices in clockwise or counterclockwise order, with at least three or more vertices. If you specify one ROI of L vertices, it must be a 2Lelement vector of format . If you specify more than one ROI, it must be an Rby2L matrix, where L is the maximum number of vertices in the ROIs. For ROI with vertices fewer than L, its last vertex can be repeated to form a vector.
Select the Output flag indicating if any part of ROI is outside input image check box to enable this output port on the Apply Geometric Transformation block.
Specify whether to use an exact computation or an approximation for the projective transformation. If you select this option, you can enter an error tolerance in the Error tolerance (in pixels) parameter.
Specify the maximum error tolerance in pixels. This appears when you select the For projective transformation, use quadratic approximation to calculate pixel locations check box.
Enable output port for flag, which indicates clipping. Clipping occurs when any of the transformed pixels fall outside of the output image.
The Simple projective transformation model ex_visionApplyGeo_projex_visionApplyGeo_proj, uses the Apply Geometric Transformation block, two Constant blocks and twoVideo Viewer blocks to illustrate a basic model. The transformation matrix determines a projective transformation and is applied to the entire input image. The input image is a checker board. The steps taken to run this model were:
Add two Constant blocks for the input image and the transformation matrix. Set the Constant value parameters for the constant blocks as follows:
for the input image, "checker_board", and
for the transformation matrix,[1 0 0; .4 1 0; 0 0 1]
Add two Video Viewer blocks, connecting one directly to the input image output port, and the other one to the Apply Geometric Transformation output port.
This example shows how to apply affine transformation on multiple ROIs of an image. It also sets the background color of the output image to a solid color purple. The input image, transformation matrix, and ROI vertices are provided to the Apply Geometric Transformation block via constant blocks. Video viewers are used to view the original image and the output image created. Open this model by typing ex_visionApplyGeo_roi ex_visionApplyGeo_roi at the MATLAB command prompt. The steps taken to run this model was:
Change the Process pixels in parameter to Polygon ROI.
Change the Background fill value to [0.5 0.5 0.75]
Add three Constant blocks for the input image, transformation matrix, and ROI vertices. Set the Constant value parameters for the three blocks as follows:
For the input image, checker_board(20,10).
For the transformation matrix,[1 0 30 0 1 30; 1.0204 0.4082 70 0 0.4082 30; 0.4082 0 89.1836 0.4082 1 10.8164].
For the polygon ROI, [1 101 99 101 99 199 1 199; 1 1 99 1 99 99 1 99; 101 101 199 101 199 199 101 199].
Add two Video Viewer blocks, connecting one directly to the Constant block containing the input image. The other, to the Apply Geometric Transformation output port.
[1] George Wolberg, "Digital Image Warping", IEEE Computer Society Press, 3^{rd} edition, 1994.
Richard Hartley and Andrew Zisserman, "Multiple View Geometry in Computer Vision", Cambridge University Press, 2^{nd }edition, 2003.
Port  Supported Data Types 

Image 

TForm 

ROI 

Output  Same as input 
Err_roi  Boolean 
Err_clip  Boolean 
imtransform  Image Processing Toolbox™ 
Estimate Geometric Transformation  Computer Vision System Toolbox™ 
Trace Boundary  Computer Vision System Toolbox 
Blob Analysis  Computer Vision System Toolbox 
Video and Image Processing Demos Video and Image Processing Demos  Computer Vision System Toolbox 