# makeresampler

Create resampling structure

## Description

example

R = makeresampler(interpolant,padMethod) creates a separable resampler structure for use with 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.

R = makeresampler(Name,Value) creates a user-written resampler using name-value arguments.

## Examples

collapse all

Read an image into the workspace and display it.

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)

## Input Arguments

collapse all

Interpolation kernel, specified as "nearest", "linear", "cubic", or a cell array. These kernels perform nearest-neighbor, bilinear, bicubic, and custom interpolation, respectively.

Define a custom interpolation kernel as a two-element cell array in either of these forms:

FormDescription

{half_width, positive_half}

half_width is a positive scalar designating the half width of a symmetric interpolating kernel. positive_half is a vector of values regularly sampling the kernel on the closed interval [0 positive_half].

{half_width, interp_fcn}

interp_fcn is a function handle that returns interpolating kernel values, given an array of input values in the interval [0 positive_half].

You can define the interpolation method independently along each transform dimension by specifying a cell array whose number of elements is equal to the number of transform dimensions. Each element of the cell array must be one of the prior types of interpolant kernels. For example, consider this value of interpolant for a 3-D interpolation kernel:

{"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

Pad method used to assign values to output elements that map outside the input array, specified as one of the these values.

Description

"bound"

Assign values from the fill value array to points that map outside the input array. Repeat border elements of the array for points that map inside the array (same as "replicate"). When interpolant is "nearest", this pad method produces the same results as "fill". "bound" is like "fill", but avoids mixing fill values and input image values.

"circular"

Pad array with circular repetition of elements within the dimension. Same as padarray.

"fill"

Generate 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 interpolant is "nearest", this pad method produces the same results as "bound".

"replicate"

"symmetric"

For "fill", "replicate", "circular", or "symmetric", the resampling performed by tformarray occurs in two logical steps:

1. Pad the array A infinitely to fill the entire input transform space.

2. 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

### Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: "Type","separable" creates a separable resampler

Resampler type, specified as one of the following values.

TypeDescription
"separable"Create a separable resampler. If you specify this value, the only other arguments 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 arguments and, optionally, the CustomData argument.

Data Types: char | string

Data Types: char | string

Data Types: char | string | cell

Dimensionality 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

Function 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

User-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

## Output Arguments

collapse all

Resampler, returned as a structure.

## Version History

Introduced before R2006a

expand all