Main Content


Create resampling structure



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,...) create a resampler structure that uses a user-written resampler using parameter value pairs.


collapse all

Read an image into the workspace and display it.

A = imread('moon.tif');

Figure contains an axes. The axes contains an object of type image.

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.


Figure contains an axes. The axes contains an object of type image.

Input Arguments

collapse all

Interpolating kernel, specified as 'nearest', 'linear', 'cubic',or a cell array. The following table lists the named interpolants:




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:

{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].

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

Method used to assign values to output elements that map outside the input array, specified as one of the following values.

Pad Method



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


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


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


Pads array by repeating border elements of array. Same as padarray.


Pads array with mirror reflections of itself. Same as padarray.

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 Pair Arguments

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.

Example: resamp = makeresampler('Type','separable','Interpolant','linear','PadMethod','fill');

Resampler type, specified as one of the following values.

'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

See the padmethod argument for more information.

Data Types: char | string

See the interpolant argument for more information.

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:


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.

See Also

Introduced before R2006a