Apply spatial transformation to N-D array
B = tformarray(A,T,R,TDIMS_A, TDIMS_B,TSIZE_B,TMAP_B,F)
Create a 2-by-2 checkerboard image where each square is 20 pixels wide and display it.
I = checkerboard(20,1,1); figure imshow(I)
Transform the checkerboard with a projective transformation. First create the spatial transformation structure (TFORM).
T = maketform('projective',[1 1; 41 1; 41 41; 1 41],... [5 5; 40 5; 35 30; -10 30]);
Create a resampler. Use the pad method 'circular' when creating a resampler, so that the output appears to be a perspective view of an infinite checkerboard.
R = makeresampler('cubic','circular');
Perform the transformation, specifying the TFORM and the resampler. Swap the output dimensions. Specify a 100-by-100 output image. Leave TMAP_B empty, since you specify TSIZE_B. Leave the fill value empty since it won't be needed.
J = tformarray(I,T,R,[1 2],[2 1],[100 100],,); figure imshow(J)
A— Input image
Input image, specified as a nonsparse numeric array, that can be real or complex.
T— Spatial transformation
Spatial transformation, specified as a spatial transformation
structure, called a
TFORM. You typically use the
to create a
tforminv to compute the corresponding
location in the input transform subscript space for each location
in the output transform subscript space.
the input transform space by
the output transform subscript space by
T is empty,
as a direct resampling function. It applies the resampler defined
R to compute values at each transform space
location defined in
tformarray applies the resampler at each
location in the output transform subscript grid.
Resampler, specified as a structure. A resampler structure defines
how to interpolate values of the input array at specified locations.
makeresampler, which allows fine control
over how to interpolate along each dimension.
controls what input array values to use when interpolating close to
the edge of the array.
TDIMS_A— Input transform dimensions
Input transform dimensions, specified as a row vector of finite, positive integers.
which dimensions of the input and output arrays are involved in the
spatial transformation. Each element must be unique, and must be a
positive integer. The entries need not be listed in increasing order,
but the order matters. It specifies the precise correspondence between
dimensions of arrays
the input and output spaces of the transformer
For example, if
T is a 2-D transformation,
= [2 1], and
TDIMS_B = [1 2], then the
column dimension and row dimension of
to the first and second transformation input-space dimensions, respectively.
The row and column dimensions of
B correspond to
the first and second output-space dimensions, respectively.
TDIMS_B— Size of output array in the transform dimensions
Size in the transform dimensions, specified as a row vector
of finite, positive integers. For more information, see
TSIZE_B— Size of output array in the transform dimensions
Size of the output array transform dimensions, specified as
a row vector of finite, positive integers. The size of
nontransform dimensions is taken directly from the size of
those dimensions. For example, if
T is a 2-D
size(A) = [480 640 3 10],
[200 300 3].
TMAP_B— Point locations in output space
Point locations in output space, specified as a nonsparse, finite
TMAP_B is an optional argument
that provides an alternative way of specifying the correspondence
between the position of elements of
B and the location
in output transform space.
TMAP_B can be used,
for example, to compute the result of an image warp at a set of arbitrary
locations in output space. If
TMAP_B is not empty,
then the size of
TMAP_B takes the form
[D1 D2 D3 ... DN L]
[D1 D2 ... DN] is used in place of
TMAP_B is not empty, then
The value of
L depends on whether
T is not empty, then
and each L-dimension point in
TMAP_B is transformed
to an input-space location using
L-dimensional point in
used directly as a location in input space.
F— Fill values
Fill values, specified as an array. The fill values in
be used in three situations:
When a separable resampler is created with
padmethod is set to either
When a custom resampler is used that supports the
methods (with behavior that is specific to the customization).
When the map from the transform dimensions of
the transform dimensions of
A is deliberately undefined
for some points. Such points are encoded in the input transform space
NaNs in either
in the output of
In the first two cases, fill values are used to compute values
for output locations that map outside or near the edges of the input
array. Fill values are copied into
B when output
locations map well outside the input array. See
makeresampler for more information about
F can be a scalar (including
in which case its value is replicated across all the nontransform
F can also be a nonscalar, whose size
size(A) in the nontransform dimensions.
K is the
nontransform dimension of
a convenience to the user,
any dimensions with unit size such that after the replication
For example, suppose
A represents 10 RGB
images and has size 200-by-200-by-3-by-10,
a 2-D transformation, and
both [1 2]. In other words,
the same 2-D transform to each color plane of each of the 10 RGB images.
In this situation you have several options for
F can be a scalar, in which case
the same fill value is used for each color plane of all 10 images.
F can be a 3-by-1 vector,
tformarray uses the RGB value
as the fill value for the corresponding color planes of each of the
F can be a 1-by-10 vector.
a different fill value for each of 10 images, with that fill value
being used for all three color planes.
F can be a 3-by-10 matrix.
a different RGB fill color for each of the 10 images.
B— Transformed image
Transformed image, returned as an array.