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".

The output shape is resolved first and defines the single endpoint-aligned sampling grid. Use axes= to identify spatial axes in arrays that also carry batch or channel dimensions; unselected axes are not filtered.

splineops.resize.resize(data: NDArray, *, zoom_factors: float | Sequence[float] | None = None, output: NDArray | dtype | None = None, output_size: Sequence[int] | None = None, axes: Sequence[int] | None = None, method: str = 'cubic') NDArray#

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 method string, and then delegates to resize_degrees().

Parameters:
  • data (ndarray) – Input array.

  • zoom_factors (float or sequence of float, optional) – Scale factors for the selected axes. A scalar broadcasts to every selected axis. Ignored if output_size is given.

  • output (ndarray or dtype, optional) – If an ndarray is supplied, the result is written in-place into that array and returned. If a dtype is supplied, a new array of that dtype is allocated and returned.

  • output_size (sequence of int, optional) – Desired lengths for the selected axes (overrides zoom_factors).

  • axes (sequence of int, optional) – Unique axes to resize. Negative axes are accepted. By default all axes are resized; non-selected axes remain unchanged.

  • 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 equal-degree least-squares configurations. On the public zero-shift grid, every projection with analysis degree one or greater uses a stable direct compact cross-Gram operator; analysis degree zero uses the finite-difference form. These are degree controls, not additional method presets.

splineops.resize.resize_degrees(data: NDArray, *, zoom_factors: float | Sequence[float] | None = None, output: NDArray | dtype | None = None, output_size: Sequence[int] | None = None, axes: Sequence[int] | None = None, interp_degree: int = 3, analy_degree: int = -1, synthe_degree: int | None = None) NDArray#

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) – Scale factors for the selected axes. A scalar broadcasts to every selected axis. Ignored if output_size is given.

  • output (ndarray or dtype, optional) – If an ndarray is supplied, the result is written in-place into that array and returned. If a dtype is supplied, a new array of that dtype is allocated and returned.

  • output_size (sequence of int, optional) – Desired lengths for the selected axes (overrides zoom_factors).

  • axes (sequence of int, optional) – Unique axes to resize. Negative axes are normalized. By default all axes are resized; unselected axes retain their original lengths and are passed to the backend as identity geometry.

  • 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.

Returns:

Resized data: either a new array or the one supplied via output.

Return type:

ndarray

Notes

Requested zooms determine integer output lengths using half-away-from-zero rounding. Resampling then uses the unique endpoint-aligned scale (M - 1) / (N - 1). For a one-point output, interpolation evaluates at the symmetric input centre while projection returns the per-line mean. A one-point input is treated as a constant and replicated.

Real integer and floating inputs are accepted. float32 input preserves float32 output; all other accepted inputs produce float64 unless an explicit real output array or dtype is supplied.

Reusable plans#

For repeated same-shape workloads, use ResizePlan to resolve the target geometry once and apply it to multiple arrays. Plans are read-only and safe to share across threads; a compatible output array also avoids the final allocation and copy. Process-wide one-shot plans and per-plan idle workspaces are byte-bounded by default, so occasional large shapes or bursts of callers do not create an unbounded retained-memory cache.

class splineops.resize.ResizePlan(input_shape: Sequence[int], *, zoom_factors: float | Sequence[float] | None = None, output_size: Sequence[int] | None = None, axes: Sequence[int] | None = None, method: str = 'cubic')#

Reusable resize plan for repeated same-shape workloads.

A plan fixes the input shape, target geometry, and spline degrees once, then applies that geometry to many arrays with the same shape. axes optionally restricts resizing to unique normalized spatial axes; scalar zooms broadcast over those axes and other dimensions remain exact identity dimensions. Configuration properties are read-only; construct a new plan to use different geometry or spline degrees. 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, output: NDArray | dtype | None = None) NDArray#

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: Sequence[int] | None = None, axes: Sequence[int] | None = None, interp_degree: int = 3, analy_degree: int = -1, synthe_degree: int | None = None) ResizePlan#

Create a plan using explicit spline degrees.

See also#

TensorSpline

The base class used internally for spline interpolation.