Quantcast

Documentation Center

  • Trial Software
  • Product Updates

maketform

Create spatial transformation structure (TFORM)

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

Syntax

T = maketform(transformtype,...)
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

T = maketform(transformtype,...) creates a multidimensional spatial transformation structure (called a TFORM struct) that can be used with the tformfwd, tforminv, fliptform, imtransform, or tformarray functions.

transformtype can be any of the following spatial transformation types. maketform supports a special syntax for each transformation type. See the following sections for information about these syntax.

Transform Type

Description

'affine'

Affine transformation in 2-D or N-D

'projective'

Projective transformation in 2-D or N-D

'custom'

User-defined transformation that can be N-D to M-D

'box'

Independent affine transformation (scale and shift) in each dimension

'composite'

Composition of an arbitrary number of more basic transformations

Transform Types

Affine

T = maketform('affine',A) builds a TFORM struct T 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.

T = maketform('affine',U,X) builds 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.

Projective

T = maketform('projective',A) builds 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) builds 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.

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

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

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

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

Custom

T = maketform('custom', NDIMS_IN, NDIMS_OUT, FORWARD_FCN, INVERSE_FCN, TDATA) builds 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. Those functions must support the following syntax:

Forward function:

X = FORWARD_FCN(U,T)

Inverse function:

U = INVERSE_FCN(X,T)

where U is a P-by-NDIMS_IN matrix whose rows are points in the transformation's input space, and X is a P-by-NDIMS_OUT matrix whose rows are points in the transformation's 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.

Box

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, alternatively, 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 vice versa. The 'box' TFORM is typically used to register the row and column subscripts of an image or array to some world coordinate system.

Composite

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.

Note that 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 in order 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

Make and apply an affine transformation.

T = maketform('affine',[.5 0 0; .5 2 0; 0 0 1]);
tformfwd([10 20],T)
I = imread('cameraman.tif');
I2 = imtransform(I,T);
imshow(I), figure, imshow(I2)

See Also

| | | |

Was this topic helpful?