Image Processing Toolbox User's Guide Previous page   Next Page
makeresampler

Create resampling structure

Syntax

Description

R = makeresampler(interpolant,padmethod) creates a separable resampler structure for use with tformarray and imtransform.

The interpolant argument specifies the interpolating kernel that the separable resampler uses. In its simplest form, interpolant can have any of the following strings as a value.

Interpolant
Description
'cubic'
Cubic interpolation
'linear'
Linear interpolation
'nearest'
Nearest-neighbor interpolation

If you are using a custom interpolating kernel, you can specify interpolant as 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, you can combine both types of interpolant specifications. The number of elements in the cell array must equal the number of transform dimensions. For example, if you specify this value for interpolant

the resampler uses nearest-neighbor interpolation along the first transform dimension, linear interpolation along the second dimension, and a custom table-based interpolation along the third.

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. The following table lists all the possible values of padmethod.

Pad Method
Description
'bound'
Assigns values from the fill value array to points that map outside the array and 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.
'circular'
Pads array with circular repetition of elements within the dimension. Same as padarray.
'fill'
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'.
'replicate'
Pads array by repeating border elements of array. Same as padarray.
'symmetric'
Pads array with mirror reflections of itself. Same as padarray.

In the case of 'fill', 'replicate', 'circular', or 'symmetric', the resampling performed by tformarray or imtransform 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.

Custom Resamplers

The syntaxes described above construct a resampler structure that uses the separable resampler function that ships with the Image Processing Toolbox. It is also possible to create a resampler structure that uses a user-written resampler by using this syntax:

The makeresampler function supports the following properties.

Property
Description
'Type'
Can have the value 'separable' or 'custom' and must always be supplied. If 'Type' is 'separable', the only other properties that can be specified are 'Interpolant' and 'PadMethod', and the result is equivalent to using the makeresampler(interpolant,padmethod) syntax. If 'Type' is 'custom', you must specify the 'NDims' and 'ResampleFcn' properties and, optionally, the 'CustomData' property.
'PadMethod'
See the padmethod argument for more information.
'Interpolant'
See the interpolant argument for more information.
'NDims'
Positive integer indicating the dimensionality the custom resampler can handle. Use a value of Inf to indicate that the custom resampler can handle any dimension. If 'Type' is 'custom', NDims is required.
'ResampleFcn'
Handle to a function that performs the resampling. The function is called with the following interface.

  • B = resample_fcn(A,M,TDIMS_A,TDIMS_B,FSIZE_A,FSIZE_B,F,R)
    
See the help for tformarray for information about the inputs A, TDIMS_A, TDIMS_B, and F. 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 such a limitation might be imposed by specific resamplers.) 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).
'CustomData'
User-defined.

Example

Stretch an image in the y-direction using a separable resampler that applies cubic interpolation in the y-direction and nearest-neighbor interpolation in the x-direction. (This is equivalent to, but faster than, applying bicubic interpolation.)

See Also

imtransform, tformarray


Previous page  makelut maketform Next page

© 1994-2005 The MathWorks, Inc.