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.
Interpolation using splines of an order larger than 1 requires a pre-
filtering step. The interpolation functions described in section
21.5.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:
The spline_filter function
calculates a multi-dimensional spline filter.
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
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.
21.5.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 problem
is solved in the same way as described in section
21.3 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
The geometric_transform function applies an
arbitrary 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.
Optionally extra arguments can be defined and passed to the filter
function. The extra_arguments and extra_keywords arguments
can be used to pass a tuple of extra arguments and/or a dictionary of
named arguments that are passed to derivative at each call. For example,
we can pass the shifts in our example as arguments:
The function map_coordinates applies an arbitrary coordinate
transformation using the given array of coordinates. The shape of the
output is derived from that of the coordinate array by dropping the first
axis. The parameter coordinates is used to find for each point in
the output the corresponding coordinates in the input. The values of
coordinates along the first axis are the coordinates in the input
array at which the output value is found. (See also the numarray
coordinates function.) Since the coordinates may be non-
integer coordinates, the value of the input at these coordinates is
determined by spline interpolation of the requested order. Here is an
example that interpolates a 2D array at (0.5, 0.5) and (1, 2):
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.
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.