Smooth#

Functions to smooth data.

splineops.smooth.smoothing_spline.periodize(x: ndarray[tuple[int, ...], dtype[_ScalarType_co]], m: int) ndarray[tuple[int, ...], dtype[_ScalarType_co]]#

Periodize the input array by concatenating m copies of it.

Parameters:
  • x (ndarray) – Input array to be periodized.

  • m (int) – Number of times to concatenate the array.

Returns:

xp – The periodized array, which has its size multiplied by m along the concatenation axis.

Return type:

ndarray

Examples

>>> import numpy as np
>>> from splineops.interpolate.smooth.smoothing_spline import periodize
>>> x = np.array([1, 2, 3])
>>> periodize(x, 2)
array([1, 2, 3, 1, 2, 3])
splineops.smooth.smoothing_spline.recursive_smoothing_spline(signal: ndarray[tuple[int, ...], dtype[_ScalarType_co]], lamb: float = 1.0) ndarray[tuple[int, ...], dtype[_ScalarType_co]]#

Apply a recursive smoothing spline filter to the input signal.

Implements a causal and anticausal IIR filter based on the smoothing parameter lamb.

Parameters:
  • signal (ndarray) – 1D array of data points to smooth.

  • lamb (float, optional) – Smoothing parameter controlling the amount of smoothing. Default is 1.0.

Returns:

smoothed_signal – 1D array of smoothed data, same length as signal.

Return type:

ndarray

Examples

>>> import numpy as np
>>> from splineops.interpolate.smooth.smoothing_spline import recursive_smoothing_spline
>>> x = np.array([1., 2., 2., 3., 5.])
>>> xs = recursive_smoothing_spline(x, lamb=1.0)
>>> xs
array([...])
splineops.smooth.smoothing_spline.smoothing_spline(y: ndarray[tuple[int, ...], dtype[_ScalarType_co]], lamb: float, m: int, gamma: float) Tuple[ndarray[tuple[int, ...], dtype[_ScalarType_co]], ndarray[tuple[int, ...], dtype[_ScalarType_co]]]#

Compute the fractional smoothing spline at m-times upsampling of the input.

This function returns samples of the smoothing spline for a given input sequence, sampled at m times the rate of the input. The input is assumed to be sampled at integer locations 0..N-1.

Parameters:
  • y (ndarray) – Input signal of length N.

  • lamb (float) – Regularization parameter.

  • m (int) – Upsampling factor (integer).

  • gamma (float) – Order of the spline operator. Typically gamma = H + 0.5.

Returns:

  • t (ndarray) – The upsampled time vector, of length approximately N * m.

  • ys (ndarray) – The smoothing spline samples, of length approximately N * m.

Examples

>>> import numpy as np
>>> from splineops.interpolate.smooth.smoothing_spline import smoothing_spline
>>> y = np.array([1., 2., 3.])
>>> t, ys = smoothing_spline(y, lamb=0.1, m=2, gamma=1.5)
>>> t.shape, ys.shape
((6,), (6,))
splineops.smooth.smoothing_spline.smoothing_spline_nd(data: ndarray[tuple[int, ...], dtype[_ScalarType_co]], lamb: float, gamma: float) ndarray[tuple[int, ...], dtype[_ScalarType_co]]#

Apply multi-dimensional fractional smoothing spline to the input data.

Parameters:
  • data (ndarray) – Multi-dimensional input data (e.g., image or volume).

  • lamb (float) – Regularization parameter.

  • gamma (float) – Order of the spline operator (gamma = H + 0.5).

Returns:

data_smooth – Smoothed data of the same shape as data.

Return type:

ndarray

Examples

>>> import numpy as np
>>> from splineops.interpolate.smooth.smoothing_spline import smoothing_spline_nd
>>> x = np.random.rand(4, 4)
>>> x_smooth = smoothing_spline_nd(x, lamb=0.5, gamma=1.0)
>>> x_smooth.shape
(4, 4)