Image Processing Toolbox User's Guide Previous page   Next Page
imtransform

Apply 2-D spatial transformation to image

Syntax

Description

B = imtransform(A,TFORM) transforms the image A according to the 2-D spatial transformation defined by TFORM, which is a spatial transformation structure (TFORM) as returned by maketform or cp2tform. If ndims(A) > 2, such as for an RGB image, then the same 2-D transformation is automatically applied to all 2-D planes along the higher dimensions.

When you use this syntax, imtransform automatically shifts the origin of your output image to make as much of the transformed image visible as possible. If you are using imtransform to do image registration, this syntax is not likely to give you the results you expect; you might want to set 'XData' and 'YData' explicitly.

B = imtransform(A,TFORM,INTERP) specifies the form of interpolation to use. INTERP can have one of these values. The default value is enclosed in braces ({}).

Value
Description
'bicubic'
Bicubic interpolation
{'bilinear'}
Bilinear interpolation
'nearest'
Nearest-neighbor interpolation

Alternatively, INTERP can be a RESAMPLER structure returned by makeresampler. This option allows more control over how resampling is performed.

[B,XDATA,YDATA] = imtransform(...) returns the location of the output image B in the output X-Y space. XDATA and YDATA are two-element vectors. The elements of XDATA specify the x-coordinates of the first and last columns of B. The elements of YDATA specify the y-coordinates of the first and last rows of B. Normally, imtransform computes XDATA and YDATA automatically so that B contains the entire transformed image A. However, you can override this automatic computation; see below.

[B,XDATA,YDATA] = imtransform(...,param1,val1,param2,val2,...) specifies parameters that control various aspects of the spatial transformation. This table lists all the parameters you can specify. Note that parameter names can be abbreviated and are not case sensitive.

Parameter
Description
'UData'
'VData'

Both of these parameters are two-element real vectors. 'UData' and 'VData' specify the spatial location of the image A in the 2-D input space U-V. The two elements of 'UData' give the u-coordinates (horizontal) of the first and last columns of A, respectively. The two elements of 'VData' give the v-coordinates (vertical) of the first and last rows of A, respectively.

The default values for 'UData' and 'VData' are [1 size(A,2)] and [1 size(A,1)], respectively.
'XData'
'YData'
Both of these parameters are two-element real vectors. 'XData' and 'YData' specify the spatial location of the output image B in the 2-D output space X-Y. The two elements of 'XData' give the x-coordinates (horizontal) of the first and last columns of B, respectively. The two elements of 'YData' give the y-coordinates (vertical) of the first and last rows of B, respectively.

If 'XData' and 'YData' are not specified, imtransform estimates values for them that will completely contain the entire transformed output image.
'XYScale'
A one- or two-element real vector. The first element of 'XYScale' specifies the width of each output pixel in X-Y space. The second element (if present) specifies the height of each output pixel. If 'XYScale' has only one element, then the same value is used for both width and height.
If 'XYScale' is not specified but 'Size' is, then 'XYScale' is computed from 'Size', 'XData', and 'YData'. If neither 'XYScale' nor 'Size' is provided, then the scale of the input pixels is used for 'XYScale'.
'Size'
A two-element vector of nonnegative integers. 'Size' specifies the number of rows and columns of the output image B. For higher dimensions, the size of B is taken directly from the size of A. In other words, size(B,k) equals size(A,k) for k > 2. If 'Size' is not specified, then it is computed from 'XData', 'YData', and 'XYScale'.
'FillValues'
An array containing one or several fill values.
Fill values are used for output pixels when the corresponding transformed location in the input image is completely outside the input image boundaries. If A is 2-D, 'FillValues' must be a scalar. However, if A's dimension is greater than two, then 'FillValues' can be an array whose size satisfies the following constraint: size(fill_values,k) must equal either size(A,k+2) or 1.
For example, if A is a uint8 RGB image that is 200-by-200-by-3, then possibilities for 'FillValues' include
0   Fill with black
[0;0;0]Fill with black
255 Fill with white
[255;255;255]Fill with white
[0;0;255]Fill with blue
[255;255;0]Fill with yellow

If A is 4-D with size 200-by-200-by-3-by-10, then 'FillValues' can be a scalar, 1-by-10, 3-by-1, or 3-by-10.

Notes

Class Support

The input image A can be of any nonsparse numeric class, real or complex, or it can be of class logical. The class of B is the same as the class of A.

Example

Example 1

Apply a horizontal shear to an intensity image.

Example 2

A projective transformation can map a square to a quadrilateral. In this example, set up an input coordinate system so that the input image fills the unit square and then transform the image into the quadrilateral with vertices (0 0), (1 0), (1 1), (0 1) to the quadrilateral with vertices (-4 2), (-8 3), (-3 -5), (6 3). Fill with gray and use bicubic interpolation. Make the output size the same as the input size.

Example 3

Register an aerial photo to an orthophoto.

Read in the aerial photo.

Read in the orthophoto.

Load control points that were previously picked.

Create a transformation structure for a projective transformation.

Get the width and height of the orthophoto and perform the transformation.

See Also

checkerboard, cp2tform, imresize, imrotate, maketform, makeresampler, tformarray


Previous page  imtophat imview Next page

© 1994-2005 The MathWorks, Inc.