Subsections

18.3 Interpolation functions

This section describes various interpolation functions that are based on B-spline theory. A good introduction to B-splines can be found in: M. Unser, "Splines: A Perfect Fit for Signal and Image Processing," IEEE Signal Processing Magazine, vol. 16, no. 6, pp. 22-38, November 1999.

18.3.1 Spline pre-filters

Interpolation using splines of an order larger than 1 requires a pre-filtering step. The interpolation functions described in section 18.3.2 apply pre-filtering by calling spline_filter, but they can be instructed not to do this by setting the prefilter keyword equal to False. This is useful if more than one interpolation operation is done on the same array. In this case it is more efficient to do the pre-filtering only once and use a prefiltered array as the input of the interpolation functions. The following two functions implement the pre-filtering:

spline_filter1d( input, order=3, axis=-1, output=None, output_type=numarray.Float64)
The spline_filter1d function calculates a one-dimensional spline filter along the given axis. An output array can optionally be provided. The order of the spline must be larger then 1 and less than 6.

spline_filter( input, order=3, output=None, output_type=numarray.Float64)
The spline_filter function calculates a multi-dimensional spline filter.

Note: The multi-dimensional filter is implemented as a sequence of one-dimensional spline filters. The intermediate arrays are stored in the same data type as the output. Therefore, if an output_type with a limited precision is requested, the results may be imprecise because intermediate results may be stored with insufficient precision. This can be prevented by specifying a output type of high precision.

 
18.3.2 Interpolation functions

Following functions all employ spline interpolation to effect some type of geometric transformation of the input array. This requires a mapping of the output coordinates to the input coordinates, and therefore the possibility arises that input values outside the boundaries are needed. This problems is solved in the same way as described in section 18.2 for the multi-dimensional filter functions. Therefore these functions all support a mode parameter that determines how the boundaries are handled, and a cval parameter that gives a constant value in case that the 'constant' mode is used.

geometric_transform( input, mapping, output_shape=None, output_type=None, output=None, order=3, mode='constant', cval=0.0, prefilter=True)
The geometric_transform function applies an arbritrary geometric transform to the input. The given mapping function is called at each point in the output to find the corresponding coordinates in the input. mapping must be a callable object that accepts a tuple of length equal to the output array rank and returns the corresponding input coordinates as a tuple of length equal to the input array rank. The output shape and output type can optionally be provided. If not given they are equal to the input shape and type.

map_indices( input, indices, output_type=None, output=None, order=3, mode='constant', cval=0.0, prefilter=True)
The function map_indices applies an arbritrary coordinate transformation using the given array of indices. The parameter indices is used to find for each point in the output the corresponding indices in the input. The values of indices along the first axis are the coordinates in the input array at which the output value is found. (See also the numarray indices function.) Since the indices may be non-integer coordinates, the value of the input at these indices is determined by spline interpolation of the requested order.

affine_transform( input, matrix, offset=0.0, output_shape=None, output_type=None, output=None, order=3, mode='constant', cval=0.0, prefilter=True)
The affine_transform function applies an affine transformation to the input array. The given transformation matrix and offset are used to find for each point in the output the corresponding coordinates in the input. The value of the input at the calculated coordinates is determined by spline interpolation of the requested order. The transformation matrix must be two-dimensional or can also be given as a one-dimensional sequence or array. In the latter case, it is assumed that the matrix is diagonal. A more efficient interpolation algorithm is then applied that exploits the separability of the problem. The output shape and output type can optionally be provided. If not given they are equal to the input shape and type.

shift( input, shift, output_type=None, output=None, order=3, mode='constant', cval=0.0, prefilter=True)
The shift function returns a shifted version of the input, using spline interpolation of the requested order.

zoom( input, zoom, output_type=None, output=None, order=3, mode='constant', cval=0.0, prefilter=True)
The zoom function returns a rescaled version of the input, using spline interpolation of the requested order.

rotate( input, angle, axes=(-1, -2), reshape=1, output_type=None, output=None, order=3, mode='constant', cval=0.0, prefilter=True)
The rotate function returns the input array rotated in the plane defined by the two axes given by the parameter axes, using spline interpolation of the requested order. The angle must be given in degrees. If reshape is true, then the size of the output array is adapted to contain the rotated input.

Send comments to the NumArray community.