Resize#
Functions for resizing N-dimensional data using standard spline interpolation, or projection-based antialiasing methods.
High-level helper#
The main entry point is resize(), which selects both
the spline degrees and (optional) antialiasing behavior via a single
method string. For production downsampling, the recommended public presets
are the oblique-projection methods "linear-antialiasing",
"quadratic-antialiasing" and "cubic-antialiasing".
- splineops.resize.resize(data: ndarray[tuple[Any, ...], dtype[_ScalarT]], *, zoom_factors: float | Sequence[float] | None = None, output: ndarray[tuple[Any, ...], dtype[_ScalarT]] | dtype | None = None, output_size: Tuple[int, ...] | None = None, method: str = 'cubic') ndarray[tuple[Any, ...], dtype[_ScalarT]]#
Resize an N-dimensional array using spline interpolation or an antialiasing projection preset.
This entry point selects both the algorithm and the spline degrees via a single
methodstring, and then delegates toresize_degrees().- Parameters:
data (ndarray) – Input array.
zoom_factors (float or sequence of float, optional) – Per-axis scale factors. Ignored if output_size is given.
output (ndarray or dtype, optional) – If an
ndarrayis supplied, the result is written in-place into that array and returned. If adtypeis supplied, a new array of that dtype is allocated and returned.output_size (tuple of int, optional) – Desired shape (overrides zoom_factors).
method (str) –
Preset selecting a specific (interp_degree, analy_degree, synthe_degree) triple.
Interpolation (no anti-aliasing, analy = -1):
"fast"– degree 0 (nearest)"linear"– degree 1"quadratic"– degree 2"cubic"– degree 3
Antialiasing (oblique projection, recommended for downsampling):
"linear-antialiasing"– (interp=1, analy=0, synthe=1)"quadratic-antialiasing"– (interp=2, analy=1, synthe=2)"cubic-antialiasing"– (interp=3, analy=1, synthe=3)
Equal-degree least-squares projection is available through
resize_degrees()for advanced/reference use, but is not exposed as a routine preset.
- Returns:
Resized data: either a new array or the one supplied via output.
- Return type:
ndarray
Advanced degrees API#
For full control over the three spline degrees (interpolation, analysis,
synthesis), use resize_degrees().
This exposes the underlying Muñoz/Unser projection framework directly, including advanced/reference equal-degree least-squares configurations.
- splineops.resize.resize_degrees(data: ndarray[tuple[Any, ...], dtype[_ScalarT]], *, zoom_factors: float | Sequence[float] | None = None, output: ndarray[tuple[Any, ...], dtype[_ScalarT]] | dtype | None = None, output_size: Tuple[int, ...] | None = None, interp_degree: int = 3, analy_degree: int = -1, synthe_degree: int | None = None, inversable: bool = False) ndarray[tuple[Any, ...], dtype[_ScalarT]]#
Resize an N-dimensional array using explicit spline degrees.
This is the most general entry point: it exposes the three degrees:
interp_degree : degree of the interpolation B-spline φ (0..3)
analy_degree : analysis spline degree (-1..3, -1 = no projection)
synthe_degree : synthesis spline degree (0..3)
Use this function for custom projection studies, including advanced or reference equal-degree least-squares configurations. For routine downsampling, prefer
resize()with one of the oblique antialiasing presets.- Parameters:
data (ndarray) – Input array.
zoom_factors (float or sequence of float, optional) – Per-axis scale factors. Ignored if output_size is given.
output (ndarray or dtype, optional) – If an
ndarrayis supplied, the result is written in-place into that array and returned. If adtypeis supplied, a new array of that dtype is allocated and returned.output_size (tuple of int, optional) – Desired shape (overrides zoom_factors).
interp_degree (int, default 3) – Degree of the interpolation B-spline φ (0..3).
analy_degree (int, default -1) –
Degree of the analysis spline φ₁:
-1 → no projection (pure interpolation)
0..3 → projection-based resizing (antialiasing, equal-degree projection, etc.)
synthe_degree (int, optional) – Degree of the synthesis spline φ₂ (output space). Defaults to
interp_degree. Must be in [0..3] and <=interp_degree.inversable (bool, default False) – If True, use a size policy that ensures invertible zoom along each axis.
- Returns:
Resized data: either a new array or the one supplied via output.
- Return type:
ndarray
Reusable plans#
For repeated same-shape workloads, use
ResizePlan to resolve the target geometry once and
apply it to multiple arrays.
- class splineops.resize.ResizePlan(input_shape: Sequence[int], *, zoom_factors: float | Sequence[float] | None = None, output_size: Tuple[int, ...] | None = None, method: str = 'cubic', inversable: bool = False)#
Reusable resize plan for repeated same-shape workloads.
A plan fixes the input shape, target geometry, spline degrees, and size policy once, then applies that geometry to many arrays with the same shape. When the native extension is available and acceleration is not disabled, the plan uses the native backend and reuses its cached per-axis metadata. Otherwise it falls back to the pure-Python resize implementation.
- apply(data: ndarray[tuple[Any, ...], dtype[_ScalarT]], output: ndarray[tuple[Any, ...], dtype[_ScalarT]] | dtype | None = None) ndarray[tuple[Any, ...], dtype[_ScalarT]]#
Apply the planned resize to an array with
input_shape.
- classmethod from_degrees(input_shape: Sequence[int], *, zoom_factors: float | Sequence[float] | None = None, output_size: Tuple[int, ...] | None = None, interp_degree: int = 3, analy_degree: int = -1, synthe_degree: int | None = None, inversable: bool = False) ResizePlan#
Create a plan using explicit spline degrees.
See also#
TensorSplineThe base class used internally for spline interpolation.