Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

maketform

Create spatial transformation structure (TFORM)

maketform is not recommended. Use fitgeotrans, affine2d, affine3d, or projective2d instead.

Syntax

T = maketform('affine',A)
T = maketform('affine',U,X)
T = maketform('projective',A)
T = maketform('projective',U,X)
T = maketform('custom',NDIMS_IN,NDIMS_OUT,FORWARD_FCN,INVERSE_FCN,TDATA)
T = maketform('box',tsize,LOW,HIGH)
T = maketform('box',INBOUNDS, OUTBOUNDS)
T = maketform('composite',T1,T2,...,TL)
T = maketform('composite', [T1 T2 ... TL])

Description

example

T = maketform('affine',A) creates a multidimensional spatial transformation structureT for an N-dimensional affine transformation. A is a nonsingular real (N+1)-by-(N+1) or (N+1)-by-N matrix. If A is (N+1)-by-(N+1), the last column of A must be [zeros(N,1);1]. Otherwise, A is augmented automatically, such that its last column is [zeros(N,1);1]. The matrix A defines a forward transformation such that tformfwd(U,T), where U is a 1-by-N vector, returns a 1-by-N vector X, such that X = U * A(1:N,1:N) + A(N+1,1:N). T has both forward and inverse transformations.

A spatial transformation structure (called a TFORM struct) that can be used with the tformfwd, tforminv, fliptform, imtransform, or tformarray functions.

T = maketform('affine',U,X) creates a TFORM struct T for a two-dimensional affine transformation that maps each row of U to the corresponding row of X. The U and X arguments are each 3-by-2 and define the corners of input and output triangles. The corners cannot be collinear.

T = maketform('projective',A) creates a TFORM struct for an N-dimensional projective transformation. A is a nonsingular real (N+1)-by-(N+1) matrix. A(N+1,N+1) cannot be 0. The matrix A defines a forward transformation such that tformfwd(U,T), where U is a 1-by-N vector, returns a 1-by-N vector X, such that X = W(1:N)/W(N+1), where W = [U 1] * A. The transformation structure T has both forward and inverse transformations.

T = maketform('projective',U,X) creates a TFORM struct T for a two-dimensional projective transformation that maps each row of U to the corresponding row of X. The U and X arguments are each 4-by-2 and define the corners of input and output quadrilaterals. No three corners can be collinear.

T = maketform('custom',NDIMS_IN,NDIMS_OUT,FORWARD_FCN,INVERSE_FCN,TDATA) creates a custom TFORM struct T based on user-provided function handles and parameters. NDIMS_IN and NDIMS_OUT are the numbers of input and output dimensions. FORWARD_FCN and INVERSE_FCN are function handles to forward and inverse functions. The forward function must support the following syntax: X = FORWARD_FCN(U,T). The inverse function must support the following syntax: U = INVERSE_FCN(X,T). In these syntaxes, U is a P-by-NDIMS_IN matrix whose rows are points in the transformation input space. X is a P-by-NDIMS_OUT matrix whose rows are points in the transformation output space. The TDATA argument can be any MATLAB® array and is typically used to store parameters of the custom transformation. It is accessible to FORWARD_FCN and INVERSE_FCN via the tdata field of T. Either FORWARD_FCN or INVERSE_FCN can be empty, although at least INVERSE_FCN must be defined to use T with tformarray or imtransform.

T = maketform('box',tsize,LOW,HIGH) or
T = maketform('box',INBOUNDS, OUTBOUNDS) builds an N-dimensional affine TFORM struct T. The tsize argument is an N-element vector of positive integers. LOW and HIGH are also N-element vectors. The transformation maps an input box defined by the opposite corners ones(1,N) and tsize, or by corners INBOUNDS(1,:) and INBOUND(2,:), to an output box defined by the opposite corners LOW and HIGH or OUTBOUNDS(1,:) and OUTBOUNDS(2,:). LOW(K) and HIGH(K) must be different unless tsize(K) is 1, in which case the affine scale factor along the Kth dimension is assumed to be 1.0. Similarly, INBOUNDS(1,K) and INBOUNDS(2,K) must be different unless OUTBOUNDS(1,K) and OUTBOUNDS(2,K) are the same, and conversely. The 'box' TFORM is typically used to register the row and column subscripts of an image or array to some world coordinate system.

T = maketform('composite',T1,T2,...,TL) or
T = maketform('composite', [T1 T2 ... TL]) builds a TFORM struct T whose forward and inverse functions are the functional compositions of the forward and inverse functions of T1, T2, ..., TL.

The inputs T1, T2, ..., TL are ordered just as they would be when using the standard notation for function composition: T = T1 T2 ... TL and note also that composition is associative, but not commutative. This means that to apply T to the input U, one must apply TL first and T1 last. Thus if L = 3, for example, then tformfwd(U,T) is the same as tformfwd(tformfwd(tformfwd(U,T3),T2),T1). The components T1 through TL must be compatible in terms of the numbers of input and output dimensions. T has a defined forward transform function only if all the component transforms have defined forward transform functions. T has a defined inverse transform function only if all the component functions have defined inverse transform functions.

Examples

collapse all

Create a transformation structure (TFORM) that defines an affine transformation.

T = maketform('affine',[.5 0 0; .5 2 0; 0 0 1])
T = 

  struct with fields:

       ndims_in: 2
      ndims_out: 2
    forward_fcn: @fwd_affine
    inverse_fcn: @inv_affine
          tdata: [1×1 struct]

Apply the forward transformation.

tformfwd([10 20],T)
ans =

    15    40

Read an image into the workspace and display it.

I = imread('cameraman.tif');

imshow(I), 

Apply the transformation to the image.

I2 = imtransform(I,T);

Display the original image and the transformed image.

figure, imshow(I2)

Input Arguments

collapse all

Transformation matrix, specified as a nonsingular, real (N+1)-by-(N+1) or (N+1)-by-N matrix.

Data Types: double

Corners, specified as a 3-by-2 matrix (for affine transformations) or 4-by-2 matrix (for projective transformations). The matrices define the corners of triangles (for affine transformations) or quadrangles (for projective transformations).

Data Types: double

Number of input and output dimensions, specified as a scalar.

Example:

Data Types: double

Forward and inverse functions, specified as function handles.

Data Types: function_handle

Parameters of custom transformation, specified as an array.

Example:

Data Types: double

Size of input box, specified as an n-element vector of positive integers.

Example:

Data Types: double

Corners of output box, specified as an n-element vector.

Example:

Data Types: double

Function and inverse functions, specified as function handles.

Example:

Data Types: function_handle

Output Arguments

collapse all

Multidimensional spatial transformation structure, returned as a transformation structure (TFORM).

Tips

  • An affine or projective transformation can also be expressed like this equation, for a 3-by-2 A:

    [X Y]'  =  A' * [U V 1] ' 
    

    Or, like this equation, for a 3-by-3 A:

    [X Y 1]'  =  A' * [U V 1]'

Introduced before R2006a

Was this topic helpful?