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.augmentation.spatial.random_resized_crop.RandomResizedCrop(target_shape: int | tuple[int, int, int], scale: tuple[float, float] = (0.08, 1.0), ratio: tuple[float, float] = (0.75, 1.33), interpolation: str = 'linear', **kwargs)[source]¶
Bases:
VolumeTransform
Crop a random portion of a 3d volume and resize it.
It is a generalization of
torchvision.transforms.RandomResizedCrop
to the 3d case.It handles
np.ndarray
ortorch.Tensor
as input and returns a consistent output (same type).- Parameters:
target_shape : int or tuple of (int, int, int)
Expected output shape. If int, apply the same size across all dimensions.
scale : tuple of (float, float), default=(0.08, 1.0)
Specifies lower and upper bounds for the random area of the crop, before resizing. The scale is defined with respect to the area of the original image.
ratio : tuple of (float, float), default=(1.0, 1.33)
Range of the aspect ratio of the crop, before resizing.
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. Check
nidl.volume.transforms.Resample
for more details.kwargs : dict
Keyword arguments given to
nidl.transforms.Transform
.
Notes
In 3d, we define the “aspect ratio” as the ratio between each dimension size relatively to their geometric mean. It is a simple generalization from 2d to nd and we don’t particularize any dimension. The aspect ratio is sampled three times for a 3d volume (one for each dimension).
- apply_transform(data: ndarray | Tensor) ndarray | Tensor [source]¶
Crop and resize the input volume.
- Parameters:
data : np.ndarray or torch.Tensor
The input data with shape
or
. Cropped area is the same across channels.
- Returns:
data : np.ndarray or torch.Tensor
Cropped and resized data. Output type is the same as input.
Follow us