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_rotation.RandomRotation(axes: tuple[int | str, int | str] | tuple[tuple[int | str, int | str], ...] = (0, 1), rotation_probability: float = 1.0, **kwargs)[source]¶
Bases:
VolumeTransform
Randomly rotates a 3d volume by 90-degree multiples around spatial axes.
- Parameters:
axes : (int or str, int or str), or tuple of (int or str, int or str), default=(0, 1)
2d axis tuple to potentially rotate over. Anatomical labels could be used as well such as “LR” (Left-Right), “AP” (Antero-Posterior) or “IS” (Inferior-Posterior). In that case, RAS-formated affine matrix is required when the transformation is called. If a tuple of pairs is given, multiple rotations are eventually applied around each plane.
rotation_probability : float, default=1.0
Probability to apply rotation for each axis pair.
kwargs : dict
Keyword arguments given to
nidl.transforms.Transform
.
Examples
>>> import torch >>> from nidl.volume.transforms.augmentation.spatial import RandomRotation >>> volume = torch.randn(1, 64, 64, 64) # shape: (C, H, W, D) >>> transform = RandomRotation(axes=("LR", "AP"), rotation_probability=0.5) >>> rotated = transform(volume) # shape (1, 64, 64, 64)
- apply_transform(data: ndarray | Tensor, affine: ndarray | None = None) ndarray | Tensor [source]¶
Apply random 90-degree rotations.
- Parameters:
data : np.ndarray or torch.Tensor
Input volume of shape
or
.
affine : np.ndarray of shape (4, 4) or None, default=None
Affine transformation matrix of the input data in RAS format defining orientation of the input image. This is typically given by Nibabel in this format. This is used only if anatomical labels are provided in the flipped axes (“LR”, “AP” or “IS”) and ignored otherwise. If None, the identity matrix is used, assuming RAS orientation.
- Returns:
Rotated volume of same type and shape as input.
Follow us