Products & Services Solutions Academia Support User Community Company

Learn more about Video and Image Processing Blockset   

Apply Geometric Transformation - Apply projective or affine transformation to an image

Library

Geometric Transformations

Description

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).

Input Description
ImageM-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:
  • 2-by-3 matrix (affine transform) or 6-by-Q matrix (multiple affine transforms)

  • 3-by-3 matrix (projective transform) or 9-by-Q matrix (multiple projective transforms)

Q: Number of transformations.

ROIWhen you set the ROI source parameter to Input port, the ROI input port accepts:
  • 4-element vector rectangle ROI

  • 2L-element vector polygon ROI

  • 4-by-R matrix for multiple rectangle ROIs

  • 2L-by-R matrix for multiple polygon ROIs

R: Number of Region of Interests (ROIs).

L (L 3): Number of vertices in a polygon ROI.

Transformations

The size of the transformation matrix will dictate the transformation type. See the table above for details.

Affine Transformation

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:

Projective Transformation

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,

Region of Interest

The Apply Geometric Transformation block can apply transformations to the entire image, or a portion (or portions) of an image specified by ROIs.

Region of Interest (ROI) Types

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.

ROI Processing

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 MatricesRegion of Interest
One transformation matrixYou can apply the transformation on the entire image, single ROI or multiple ROIs.
Multiple transformation matrices
  • You can apply multiple transformation matrices on one ROI or on the entire image. The transformations are done in the order they are entered in the TForm.

  • You can apply multiple transformation matrices on multiple ROIs. Each transformation matrix is applied to one ROI. The first transformation matrix specified is applied to the first ROI specified. The second transformation matrix is applied to the second ROI specified, and so on. The number of transformation matrices must be equal to the number of ROIs.

Quadratic Approximation Mode for Projective Transformation

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.

Dialog Box

Transformation matrix source

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.

Transformation matrix

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.

Interpolation method for calculating pixel value(s)

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.

Background fill value

Specify the value of the pixels that are outside of the input image. Use either a scalar value of P-element vector.

Output image size and position

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.

Size [height width]

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.

Location of the upper left corner [row col]

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.

Process pixels in

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.

ROI source

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.

Location and size of rectangle ROI [row col height width]

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.

Vertices of polygon ROI [r1 c1 r2 c2 ... rn cn]

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.

Output flag indicating if any part of ROI is outside input image

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.

For projective transformation, use quadratic approximation to calculate pixel locations

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.

Error tolerance (in pixels)

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.

Output flag indicating if any transformed pixels were clipped

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.

Examples

Apply a Projective Transformation to an ImageA simple model using the Apply Geometric Transformation block.
Create an Image of a Cube using Three Regions of InterestA model which uses the Apply Geometric Transformation block to create an image of a cube using ROIs.

Apply a Projective Transformation to an Image

The Simple projective transformation model doc_vipApplyGeo_proj, uses the Apply Geometric Transformation block, two Constant blocks and two Video 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:

  1. 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]

  2. 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.

Create an Image of a Cube using Three Regions of Interest

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:

  1. Change the Process pixels in parameter to Polygon ROI.

  2. Change the Background fill value to [0.5 0.5 0.75]

  3. 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]'.

  4. Add two Video Viewer blocks, connecting one directly to the Constant block containing the input image. The other Video Viewer block connected to the Apply Geometric Transformation output port.

References

[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 Presss, 2nd edition, 2003.

Supported Data Types

PortSupported Data Types
Image
  • Double-precision floating point

  • Single-precision floating point

TForm
  • Double-precision floating point

  • Single-precision floating point

ROI
  • Double-precision floating point

  • Single-precision floating point

  • 8-, 16-, and 32-bit signed integers

  • 8-, 16-, and 32-bit unsigned integers

OutputSame as input
Err_roiBoolean
Err_clipBoolean

See Also

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

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS