| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| R2010b Documentation → Video and Image Processing Blockset |
| Contents | Index |
| Learn more about Video and Image Processing Blockset |
Geometric Transformations

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 | M-by-N or M-by-N-by-P 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. |
| 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
|
The size of the transformation matrix will dictate the transformation type. See the table above for details.
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 h1, h2, ... h6, are transformation coefficients.
If you use one transformation, the transformation coefficients must be arranged as a 2-by-3 matrix as in:
![]()
or in a 6-by-1 vector
as in
.
If you use more than one transformation, the transformation
coefficients must be arranged as a 6-by-Q matrix,
where each column has the format of
,
and Q is the number of transformations as in:

For projective transformation, the relationship between the input and the output points is defined by the following equations:

where h1, h2, ... h9, are transformation coefficients.
If you use one transformation, the transformation coefficients must be arranged as a 3-by-3 matrix as in:

or in a 9-by-1 vector
as in,
.
If you use more than one transformation, the transformation
coefficients must be arranged as a 9-by-Q matrix,
where each column has the format of
, and Q is the
number of transformations. For example,

The Apply Geometric Transformation block can apply transformations to the entire image, or a portion (or portions) of an image specified by ROIs.
Two types of ROIs are supported. ROIs can be one or more rectangles or polygons.
A rectangle ROI is specified
by its top-left corner and its size. If you specify one ROI, it must
be a 4-element vector of
format
.
If you specify more than one ROI, it must be a 4-by-R matrix
such that each column is
.
A polygon ROI is specified
by the vertices of the polygon in clockwise or counter-clockwise order,
with at least three or more vertices. If you specify one ROI of L vertices,
it must be a 2L-element vector
of format
.
If you specify more than one ROI, it must be a 2L-by-R matrix,
where now 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 or 2L.
See Defining Shapes to Draw for details.
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 |
|
Projective Transformation block provides an approximation mode which reduces the number of pixels requiring division calculations [1]. The accuracy of the approximation to determine pixel locations is specified by the user in the Error tolerance parameter.
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 2-by-3, 3-by-3, 6-by-Q,or a 9-by-Q matrix. This option appears when you set Transformation matrix source 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 P-element 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 [row column] parameter when you set the Output image size and position parameter is set to Specify via dialog.
Specify the row and column 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 to process pixels in. Specify Whole input image, Rectangle ROI, or Polygon ROI. If you select Rectangle ROI, or Polygon ROI the ROI source parameter becomes available.
Specify the source for the region of interest (ROI), either Specify via dialog or Input port. This parameter is available when you set the Process pixels in parameter to either Rectangle ROI, or Polygon ROI.
Specify a 4-element vector or 4-by-R matrix, (where R represents the number of ROIs). This parameter is available when the Process pixels in parameter is set to Rectangle ROI.
Specify a 2L-element vector or 2L-by-R matrix, (where L is the number of vertices in a polygon and R represents the number of ROIs). This parameter becomes available when you set Process pixels in parameter to Polygon ROI.
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 parameter becomes available when you select For projective transformation, use quadratic approximation to calculate pixel locations check box.
Select the Output flag indicating if any transformed pixels were clipped check box to enable this output port on the Apply Geometric Transformation block. Clipping occurs when any of the transformed pixels fall outside of the output image.
| Apply a Projective Transformation to an Image | A simple model using the Apply Geometric Transformation block. |
| Create an Image of a Cube using Three Regions of Interest | A model which uses the Apply Geometric Transformation block to create an image of a cube using ROIs. |
The Simple projective transformation model doc_vipApplyGeo_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,[0.06 -0.15 15; 0.04 0.1 2; -0.01 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 doc_vipApplyGeo_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"
For the transformation matrix,[1 0 -15 0 1 15; 0.4082 0 15 -0.4082 1.0204 35; 1 -0.4082 5.4082 0 0.4082 44.5918]', and
For the polygon ROI, [50 0 50 49 99 49 99 0; 0 0 0 49 49 49 49 0; 50 50 50 99 99 99 99 50]'.
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, 3rd edition, 1994.
Richard Hartley and Andrew Zisserman, "Multiple View Geometry in Computer Vision", Cambridge University Press, 2nd 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 | Video and Image Processing Blockset |
| Trace Boundaries | Video and Image Processing Blockset |
| Blob Analysis | Video and Image Processing Blockset |
| Video and Image Processing Demos | Video and Image Processing Blockset |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2010- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |