Menu

Deep learning for NeuroImaging in Python.

Note

This page is a reference documentation. It only explains the class signature, and not how to use it. Please refer to the gallery for the big picture.

class nidl.volume.transforms.preprocessing.spatial.resize.Resize(target_shape: int | tuple[int, int, int], interpolation: str = 'linear', **kwargs)[source]

Bases: Resample

Resize a 3d volume to match a target shape.

This transformation resizes a 3d volume to a new target shape, implicitely modifying the physical spacing. Internally, it uses SimpleITK for fast and robust resampling. It handles np.ndarray or torch.Tensor as input and returns a consistent output (same type). Input shape must be (C, H, W, D) or (H, W, D).

Parameters:

target_shape : int or tuple of (int, int, int)

Output shape (H', W', D'). If int is given, it sets H'=W'=D'.

interpolation : str in {‘nearest’, ‘linear’, ‘bspline’, ‘cubic’, ‘gaussian’, ‘label_gaussian’, ‘hamming’, ‘cosine’, ‘welch’, ‘lanczos’, ‘blackman’}, default=’linear’

Interpolation techniques available in ITK. linear, the default in nidl for scalar images, offers a good compromise between image quality and speed and is a solid choice for data augmentation during training. Methods such as bspline or lanczos produce high-quality results but are slower and best used during offline preprocessing. nearest is very fast but gives poorer results for scalar images; however, it is the default for label maps, as it preserves categorical values. For a full comparison of interpolation methods, see [R14]. Descriptions of available methods:

  • nearest: Nearest-neighbor interpolation.

  • linear: Linear interpolation.

  • bspline: B-spline of order 3 (cubic).

  • cubic: Alias for bspline.

  • gaussian: Gaussian interpolation \sigma=0.8,\alpha=4.

  • label_gaussian: Gaussian interpolation for label maps (\sigma=1, \alpha=1).

  • hamming: Hamming-windowed sinc kernel.

  • cosine: Cosine-windowed sinc kernel.

  • welch: Welch-windowed sinc kernel.

  • lanczos: Lanczos-windowed sinc kernel.

  • blackman: Blackman-windowed sinc kernel.

**kwargs : dict

Keyword arguments given to nidl.transforms.Transform.

References

[R14] (1,2)

Meijering et al. (1999), “Quantitative Comparison of Sinc-Approximating Kernels for Medical Image Interpolation.”

apply_transform(data: ndarray | Tensor) ndarray | Tensor[source]

Resize the input volume.

Parameters:

data : np.ndarray or torch.Tensor

The input data with shape (C, H, W, D) or (H, W, D). The channel dimension is never resized.

Returns:

data : np.ndarray or torch.Tensor

Resampled data with shape (H', W', D') or (C, H', W', D') and same type as input.

Follow us

© 2025, nidl developers