spline_filter#
- scipy.ndimage.spline_filter(input, order=3, output=<class 'numpy.float64'>, mode='mirror')[source]#
Multidimensional spline filter.
- Parameters:
- inputarray_like
The input array.
- orderint, optional
The order of the spline, default is 3.
- outputndarray or dtype, optional
The array in which to place the output, or the dtype of the returned array. Default is
numpy.float64
.- mode{โreflectโ, โgrid-mirrorโ, โconstantโ, โgrid-constantโ, โnearestโ, โmirrorโ, โgrid-wrapโ, โwrapโ}, optional
The mode parameter determines how the input array is extended beyond its boundaries. Default is โmirrorโ. Behavior for each valid value is as follows (see additional plots and details on boundary modes):
- โreflectโ (d c b a | a b c d | d c b a)
The input is extended by reflecting about the edge of the last pixel. This mode is also sometimes referred to as half-sample symmetric.
- โgrid-mirrorโ
This is a synonym for โreflectโ.
- โconstantโ (k k k k | a b c d | k k k k)
The input is extended by filling all values beyond the edge with the same constant value, defined by the cval parameter. No interpolation is performed beyond the edges of the input.
- โgrid-constantโ (k k k k | a b c d | k k k k)
The input is extended by filling all values beyond the edge with the same constant value, defined by the cval parameter. Interpolation occurs for samples outside the inputโs extent as well.
- โnearestโ (a a a a | a b c d | d d d d)
The input is extended by replicating the last pixel.
- โmirrorโ (d c b | a b c d | c b a)
The input is extended by reflecting about the center of the last pixel. This mode is also sometimes referred to as whole-sample symmetric.
- โgrid-wrapโ (a b c d | a b c d | a b c d)
The input is extended by wrapping around to the opposite edge.
- โwrapโ (d b c d | a b c d | b c a b)
The input is extended by wrapping around to the opposite edge, but in a way such that the last point and initial point exactly overlap. In this case it is not well defined which sample will be chosen at the point of overlap.
- Returns:
- spline_filterndarray
Filtered array. Has the same shape as input.
See also
spline_filter1d
Calculate a 1-D spline filter along the given axis.
Notes
The multidimensional filter is implemented as a sequence of 1-D spline filters. The intermediate arrays are stored in the same data type as the output. Therefore, for output types with a limited precision, the results may be imprecise because intermediate results may be stored with insufficient precision.
For complex-valued input, this function processes the real and imaginary components independently.
Added in version 1.6.0: Complex-valued support added.
Array API Standard Support
spline_filter
has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variableSCIPY_ARRAY_API=1
and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.Library
CPU
GPU
NumPy
โ
n/a
CuPy
n/a
โ
PyTorch
โ
โ
JAX
โ ๏ธ no JIT
โ
Dask
โ ๏ธ computes graph
n/a
See Support for the array API standard for more information.
Examples
We can filter an image using multidimensional splines:
>>> from scipy.ndimage import spline_filter >>> import numpy as np >>> import matplotlib.pyplot as plt >>> orig_img = np.eye(20) # create an image >>> orig_img[10, :] = 1.0 >>> sp_filter = spline_filter(orig_img, order=3) >>> f, ax = plt.subplots(1, 2, sharex=True) >>> for ind, data in enumerate([[orig_img, "original image"], ... [sp_filter, "spline filter"]]): ... ax[ind].imshow(data[0], cmap='gray_r') ... ax[ind].set_title(data[1]) >>> plt.tight_layout() >>> plt.show()