AlbumentationsExplore
DocumentationExploreAdoptionPricingBlog
GitHub

Resize3D

Targets:
volume
mask3d
keypoints
Image Types:uint8, float32

Resize a volume to a fixed (depth, height, width) shape, preserving all channels, dtype, and its public layout intact.

Resize3D resamples all three spatial axes together; depth is never treated as a batch axis. Single-volume intensity data and categorical masks use independently configurable interpolation. The routed Albucore backend supports only linear and nearest-neighbor interpolation, ensuring the same public contract for NumPy and CPU Tensor inputs.

Arguments
size
tuple[int, int, int]

Target spatial shape in (depth, height, width) order.

interpolation
0 | 1
1

Interpolation for a volume: cv2.INTER_LINEAR or cv2.INTER_NEAREST. Default: cv2.INTER_LINEAR.

mask_interpolation
0 | 1
0

Interpolation for mask3d: cv2.INTER_LINEAR or cv2.INTER_NEAREST. Default: cv2.INTER_NEAREST.

p
float
1

Probability of applying the transform. Default: 1.0.

Examples
>>> import albumentations as A
>>> import cv2
>>> import numpy as np
>>> volume = np.random.default_rng(137).random((16, 64, 96, 1), dtype=np.float32)
>>> mask3d = np.zeros((16, 64, 96), dtype=np.uint8)
>>> transform = A.Compose([
...     A.Resize3D(
...         size=(32, 128, 128),
...         interpolation=cv2.INTER_LINEAR,
...         mask_interpolation=cv2.INTER_NEAREST,
...     ),
... ])
>>> result = transform(volume=volume, mask3d=mask3d)
>>> result["volume"].shape, result["mask3d"].shape
((32, 128, 128, 1), (32, 128, 128))
Notes
  • NumPy volume data use channel-last (D, H, W, C) layout. CPU Tensor volume data use channel-first (C, D, H, W) layout.
  • uint8 output preserves dtype; linear resampling rounds and saturates to [0, 255]. Float32 output remains float32.
  • Keypoints use (x, y, z) order and scale from the voxel-grid origin by (W2 / W1, H2 / H1, D2 / D1), matching the 2D resize convention.
  • This transform changes voxel-grid coordinates only. It does not update physical voxel spacing or orientation metadata.
See Also
  • Affine3D: Sample continuous rotations, scales, and translations while keeping the input output grid.