Resize#

class deeptrack.optical.math.Resize(dsize: tuple[int, int] | Callable[[...], tuple[int, int]] = (256, 256), channel_axis: int | None = None, **kwargs: Any)#

Bases: Feature

Resize an image to a specified spatial size.

Resizes the spatial dimensions of an input array or tensor to a target size specified by dsize. The size is given as (width, height), while the output follows standard array layout (height, width).

The operation supports both NumPy arrays and PyTorch tensors:

  • NumPy backend: uses cv2.resize

  • PyTorch backend: uses torch.nn.functional.interpolate

Channel handling follows the channel_axis convention:

  • If channel_axis is specified, resizing is applied only to spatial

dimensions and independently for each channel. - If channel_axis=None and the input has more than two dimensions, the last axis is treated as the channel dimension.

Parameters#

dsize: tuple[int, int]

Target output size given as (width, height). This convention is backend-independent and applies equally to NumPy and PyTorch inputs.

channel_axis: int or None, default=None

Axis corresponding to channels in the input image. If None and dimension > 2, the last channel dimension is used.

**kwargs: Any

Additional keyword arguments.

Methods#

get(image, dsize, **kwargs) -> array | tensor

Resize the input image to the specified size using the selected backend.

Examples#

>>> import numpy as np
>>> import numpy as np
>>>
>>> input_image = np.random.rand(16, 16)
>>> feature = dt.math.Resize(dsize=(8, 4))
>>> resized_image = feature.resolve(input_image)
>>> resized_image.shape
(4, 8)
>>> import numpy as np
>>> input_image = np.random.rand(16, 16, 16)
>>> feature = dt.math.Resize(dsize=(8, 4), channel_axis=1)
>>> resized_image = feature.resolve(input_image)
>>> resized_image.shape
(4, 16, 8)

Methods Summary

get(image, dsize, **kwargs)

Resize the input image to a specified spatial size.

Methods Documentation

get(image: np.ndarray | torch.Tensor | ScatteredVolume | ScatteredField, dsize: tuple[int, int], **kwargs: Any) np.ndarray | torch.Tensor#

Resize the input image to a specified spatial size.

This method dispatches to the appropriate backend implementation (NumPy or PyTorch) and applies resizing to the spatial dimensions of the input.

Parameters#

imagenp.ndarray or torch.Tensor or ScatteredVolume or ScatteredField

The input image to resize. If a scattered object is provided, the resizing is applied to its internal array/tensor.

dsizetuple[int, int]

Target output size given as (width, height). This convention is backend-independent and applies to both NumPy and PyTorch inputs.

**kwargsAny

Additional keyword arguments passed to the underlying resize implementation: - NumPy backend: forwarded to cv2.resize - PyTorch backend: forwarded to torch.nn.functional.interpolate (if supported)

Returns#

np.ndarray or torch.Tensor or ScatteredVolume or ScatteredField

The resized image, with the same type and layout as the input.