Resize#

Functions for resizing N-dimensional data using standard spline interpolation, or specialized least-squares / oblique projection methods.

splineops.resize.resize.resize(data: ndarray[tuple[int, ...], dtype[_ScalarType_co]], zoom_factors: float | Sequence[float] | None = None, output: ndarray[tuple[int, ...], dtype[_ScalarType_co]] | dtype | None = None, output_size: Tuple[int, ...] | None = None, degree: int = 3, modes: str | Sequence[str] = 'mirror', method: str = 'interpolation') ndarray[tuple[int, ...], dtype[_ScalarType_co]]#

Resize an N-dimensional image using TensorSpline for interpolation or LS/oblique projection methods.

Parameters:
  • data (ndarray) – The input data to resize.

  • zoom_factors (float or sequence of float, optional) – Scaling factors for each axis. Ignored if output_size is provided.

  • output (ndarray or numpy.dtype, optional) – If an ndarray, the result is copied into it. If a dtype, a new array of that dtype is returned. Default is None.

  • output_size (tuple of int, optional) – Desired output shape. If provided, zoom_factors is ignored.

  • degree (int, optional) – Degree of the B-spline interpolation (0 to 9). Default is 3.

  • modes (str or sequence of str, optional) – Extension mode(s) for each dimension. Default is “mirror”.

  • method ({'interpolation', 'least-squares', 'oblique'}, optional) – Resizing method. Default is “interpolation”.

Returns:

resized_data – Resized data. If output is an ndarray, the function writes the result in-place and returns output.

Return type:

ndarray

Examples

Resize a 2D array using interpolation:

>>> import numpy as np
>>> from splineops.interpolate.resize import resize
>>> data = np.array([[1, 2], [3, 4]])
>>> resized_data = resize(data, zoom_factors=2)
>>> resized_data.shape
(4, 4)

Resize a 3D array using LS projection:

>>> data_3d = np.random.rand(4, 4, 4)
>>> resized_data_3d = resize(data_3d, output_size=(8, 8, 8), degree=3, method="least-squares")
>>> resized_data_3d.shape
(8, 8, 8)

See also#

TensorSpline

The base class used internally for spline interpolation.