Skip to main content
`Ctrl`+`K`
scipy.ndimage.

# spline_filter1d

scipy.ndimage.spline_filter1d(input, order=3, axis=-1, output=<class 'numpy.float64'>, mode='mirror')

  Calculate a 1-D spline filter along the given axis.

  The lines of the array along the given axis are filtered by a spline filter. The order of the spline must be >= 2 and <= 5.

  Parameters:
    input array_like

      The input array.

    order int, optional

      The order of the spline, default is 3.

    axis int, optional

      The axis along which the spline filter is applied. Default is the last axis.

    output ndarray 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’ (b c d b c | a b c d | b c a b c)

        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.

        For the example illustrated above, the edge values `a` and `d` overlap, while the inner pattern `b c` repeats. The example demonstrates one possible output, while `b c a b c | a b c d | b c d b c` is another, since either `a` or `d` may occur at each point of overlap.

  Returns:
    spline_filter1d ndarray

      The filtered input.

  See also

  `spline_filter`

    Multidimensional spline filter.

  Notes

  All of the interpolation functions in ndimage do spline interpolation of the input image. If using B-splines of order > 1, the input image values have to be converted to B-spline coefficients first, which is done by applying this 1-D filter sequentially along all axes of the input. All functions that require B-spline coefficients will automatically filter their inputs, a behavior controllable with the prefilter keyword argument. For functions that accept a mode parameter, the result will only be correct if it matches the mode used when filtering.

  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_filter1d` has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable `SCIPY_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 1-D spline along the given axis:

      >>> from scipy.ndimage import spline_filter1d
      >>> import numpy as np
      >>> import matplotlib.pyplot as plt
      >>> orig_img = np.eye(20)  # create an image
      >>> orig_img[10, :] = 1.0
      >>> sp_filter_axis_0 = spline_filter1d(orig_img, axis=0)
      >>> sp_filter_axis_1 = spline_filter1d(orig_img, axis=1)
      >>> f, ax = plt.subplots(1, 3, sharex=True)
      >>> for ind, data in enumerate([[orig_img, "original image"],
      ...             [sp_filter_axis_0, "spline filter (axis=0)"],
      ...             [sp_filter_axis_1, "spline filter (axis=1)"]]):
      ...     ax[ind].imshow(data[0], cmap='gray_r')
      ...     ax[ind].set_title(data[1])
      >>> plt.tight_layout()
      >>> plt.show()