Create resampling structure
creates
a separable resampler structure for use with R
= makeresampler(interpolant
,padmethod
)tformarray
.
The interpolant
argument specifies the interpolating
kernel that the separable resampler uses. The padmethod
argument
controls how the resampler interpolates or assigns values to output
elements that map close to or outside the edge of the input array.
create
a resampler structure that uses a user-written resampler using parameter
value pairs.R
= makeresampler(Name,Value
,...)
Read an image into the workspace and display it.
A = imread('moon.tif');
imshow(A)
Create a separable resampler.
resamp = makeresampler({'nearest','cubic'},'fill');
Create a spatial transformation structure (TFORM) that defines an affine transformation.
stretch = maketform('affine',[1 0; 0 1.3; 0 0]);
Apply the transformation, specifying the custom resampler.
B = imtransform(A,stretch,resamp);
Display the transformed image.
imshow(B)
interpolant
— Interpolating kernel'cubic'
| 'linear'
| 'nearest'
| cell arrayInterpolating kernel, specified as 'nearest'
, 'linear'
,
'cubic'
,or a cell array. The following table lists
the named interpolants:
Interpolant | Description |
---|---|
| Cubic interpolation |
| Linear interpolation |
| Nearest-neighbor interpolation |
If you want to use a custom interpolating kernel, specify a cell array in either of these forms:
|
|
|
|
To specify the interpolation method independently along each
dimension, combine both types of interpolant specifications. The number
of elements in the cell array must equal the number of transform dimensions.
For example, consider the following example of an interpolant
value:
{'nearest', 'linear', {2 KERNEL_TABLE}}
In this example, the resampler uses nearest-neighbor interpolation along the first transform dimension, linear interpolation along the second dimension, and custom table-based interpolation along the third.
Data Types: char
| string
| cell
padmethod
— Method used to assign values to output elements that map outside the input array'bound'
| 'circular'
| 'replicate'
| 'symmetric'
| 'fill'
Method used to assign values to output elements that map outside the input array, specified as one of the following values.
Pad Method | Description |
---|---|
| Assigns values from the fill value array to points that
map outside the input array. Repeats border elements of the array
for points that map inside the array (same as |
| Pads array with circular repetition of elements within
the dimension. Same as |
| Generates an output array with smooth-looking edges (except
when using nearest-neighbor interpolation). For output points that
map near the edge of the input array (either inside or outside), it
combines input image and fill values. When |
| Pads array by repeating border elements of array. Same
as |
| Pads array with mirror reflections of itself. Same as |
For 'fill'
, 'replicate'
, 'circular'
,
or 'symmetric'
, the resampling performed by tformarray
occurs
in two logical steps:
Pad the array A
infinitely to fill
the entire input transform space.
Evaluate the convolution of the padded A
with
the resampling kernel at the output points specified by the geometric
map.
Each nontransform dimension is handled separately. The padding is virtual (accomplished by remapping array subscripts) for performance and memory efficiency. If you implement a custom resampler, you can implement these behaviors.
Data Types: char
| string
Specify optional
comma-separated pairs of Name,Value
arguments. Name
is
the argument name and Value
is the corresponding value.
Name
must appear inside quotes. You can specify several name and value
pair arguments in any order as
Name1,Value1,...,NameN,ValueN
.
resamp = makeresampler('Type','separable','Interpolant','linear','PadMethod','fill');
'Type'
— Resampler type'separable'
| 'custom'
Resampler type, specified as one of the following values.
Type | Description |
---|---|
'separable' | Create a separable resampler. If you specify this value, the
only other properties that you can specify are 'Interpolant' and 'PadMethod' .
The result is equivalent to using the makeresampler(interpolant,padmethod) syntax. |
'custom' | Create a customer resampler. If you specify this value, you
must specify the 'NDims' and 'ResampleFcn' properties
and, optionally, the 'CustomData' property. |
Data Types: char
| string
'PadMethod'
— Method used to assign values to output elements that map close to or outside the edge of the input arraySee the padmethod
argument for more information.
Data Types: char
| string
'Interpolant'
— Interpolating kernelSee the interpolant
argument for more information.
Data Types: char
| string
| cell
'NDims'
— Dimensionality custom resampler can handleDimensionality custom resampler can handle, specified as a positive
integer. Use a value of Inf
to indicate that the
custom resampler can handle any dimension. If 'Type'
is 'custom'
,
you must specify NDims
.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
'ResampleFcn'
— Function that performs the resamplingFunction that performs the resampling, specified as a function handle. You call this function with the following interface:
B = resample_fcn(A,M,TDIMS_A,TDIMS_B,FSIZE_A,FSIZE_B,F,R)
For more information about the input arguments to this function,
see the help for tformarray
.
The argument M
is an array that maps the transform
subscript space of B
to the transform subscript
space of A
. If A
has N
transform
dimensions (N = length(TDIMS_A))
and B
has P
transform
dimensions (P = length(TDIMS_B))
, then ndims(M)
= P + 1
, if N > 1
and P
if N
== 1
, and size(M,P + 1) = N
.
The first P
dimensions of M
correspond
to the output transform space, permuted according to the order in
which the output transform dimensions are listed in TDIMS_B
.
(In general TDIMS_A
and TDIMS_B
need
not be sorted in ascending order, although some resamplers can impose
such a limitation.) Thus, the first P
elements
of size(M)
determine the sizes of the transform
dimensions of B
. The input transform coordinates
to which each point is mapped are arrayed across the final dimension
of M
, following the order given in TDIMS_A
. M
must
be double
. FSIZE_A
and FSIZE_B
are
the full sizes of A
and B
, padded
with 1
's as necessary to be consistent with TDIMS_A
, TDIMS_B
,
and size(A)
.
Data Types: function_handle
'CustomData'
— User-define dataUser-defined data, specified using a string scalar, character vector, or numeric array.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
| char
| string
R
— ResamplerResampler, returned as a structure.
You have a modified version of this example. Do you want to open this example with your edits?