Apply Geometric Transformation

Apply projective or affine transformation to an image

Library

Geometric Transformations

visiongeotforms

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

Port Descriptions

Port 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:
  • 3-by-2 matrix (affine transform) or a Q-by-6 matrix (multiple affine transforms).

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

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

  • R-by-4 matrix for multiple rectangle ROIs.

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

R: Number of Region of Interests (ROIs).

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

Transformations

The size of the transformation matrix will dictate the transformation type.

Affine Transformation

For affine transformation, the value of the pixel located at [x^,y^]in the output image, is determined by the value of the pixel located at [x,y] in the input image. The relationship between the input and the output point locations is defined by the following equations:

{x^=xh1+yh2+h3y^=xh4+yh5+h6

where h1, h2, ... h6 are transformation coefficients.

If you use one transformation, the transformation coefficients must be arranged as a 3-by-2 matrix as in:

H=[h1h4h2h5h3h6]

or in a 1-by-6 vector as in H=[h1h2h3h4h5h6].

If you use more than one transformation, the transformation coefficients must be arranged as a Q-by-6 matrix, where each row has the format of H=[h1h2h3h4h5h6], and Q is the number of transformations as in:

H=[h11h12...h16h21h22...h26...hQ1hQ2...hQ6]

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.

Projective Transformation

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

{x^=xh1+yh2+h3xh7+yh8+h9y^=xh4+yh5+h6xh7+yh8+h9

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:

H=[h1h4h7h2h5h8h3h6h9]

or in a 1-by-9 vector as in, H=[h1h2h3h4h5h6h7h8h9].

If you use more than one transformation, the transformation coefficients must be arranged as a Q-by-9 matrix, where each row has the format of H=[h1h2h3h4h5h6h7h8h9], and Q is the number of transformations. For example,

H=[h11h12...h19h21h22...h29...hQ1hQ2...hQ9]

Dialog Box

The Main pane of the Apply Geometric Transformation dialog box appears as shown in the following figure.

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 3-by-2, 3-by-3, Q-by-6,or aQ-by-9 matrix. This option appears when you set the Transformation matrix source parameter 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 [x y] parameter when you set the Output image size and position parameter to Specify via dialog.

Location of the upper left corner [x y]

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.

Process pixels in

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

ROI source

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.

Location and size of rectangle ROI [x y width height]

Specify a 4-element vector or an R-by-4 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 top-left corner and size in width and height. If you specify one ROI, it must be a 4-element vector of format [x y width height]. If you specify more than one ROI, it must be an R-by-4 matrix, such that each row's format is [x y width height].

Vertices of polygon ROI [x1 y1 x2 y2 ... xL yL]

Specify a 2L-element vector or an R-by-2L 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 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 [x1y1x2y2...xLyL]. If you specify more than one ROI, it must be an R-by-2L 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.

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 appears when you select the For projective transformation, use quadratic approximation to calculate pixel locations check box.

Output flag indicating if any transformed pixels were clipped

Enable output port for flag, which indicates clipping. Clipping occurs when any of the transformed pixels fall outside of the output image.

Examples

Apply a Projective Transformation to an 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:

  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,[1 0 0; .4 1 0; 0 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 ex_visionApplyGeo_roi ex_visionApplyGeo_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(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].

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

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 Press, 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

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

Was this topic helpful?