A base class for transformations that should be applied both to an image and its corresponding properties
such as masks, bounding boxes, and keypoints. This class ensures that when a transform is applied to an image,
all associated entities are transformed accordingly to maintain consistency between the image and its annotations.
Methods:
apply(img: np.ndarray, **params: Any) -> np.ndarray:
Apply the transform to the image.
img: Input image of shape (H, W, C) or (H, W) for grayscale.
**params: Additional parameters specific to the transform.
Returns Transformed image of the same shape as input.
apply_to_images(images: np.ndarray, **params: Any) -> np.ndarray:
Apply the transform to multiple images.
images: Input images of shape (N, H, W, C) or (N, H, W) for grayscale.
**params: Additional parameters specific to the transform.
Returns Transformed images in the same format as input.
apply_to_mask(mask: np.ndarray, **params: Any) -> np.ndarray:
Apply the transform to a mask.
mask: Input mask of shape (H, W), (H, W, C) for multi-channel masks
**params: Additional parameters specific to the transform.
Returns Transformed mask in the same format as input.
apply_to_masks(masks: np.ndarray, **params: Any) -> np.ndarray | list[np.ndarray]:
Apply the transform to multiple masks.
masks: Array of shape (N, H, W) or (N, H, W, C) where N is number of masks
**params: Additional parameters specific to the transform.
Returns Transformed masks in the same format as input.
apply_to_keypoints(keypoints: np.ndarray, **params: Any) -> np.ndarray:
Apply the transform to keypoints.
keypoints: Array of shape (N, 2+) where N is the number of keypoints.
**params: Additional parameters specific to the transform.
Returns Transformed keypoints array of shape (N, 2+).
apply_to_bboxes(bboxes: np.ndarray, **params: Any) -> np.ndarray:
Apply the transform to bounding boxes.
bboxes: Array of shape (N, 4+) where N is the number of bounding boxes,
and each row is in the format [x_min, y_min, x_max, y_max].
**params: Additional parameters specific to the transform.
Returns Transformed bounding boxes array of shape (N, 4+).
apply_to_volume(volume: np.ndarray, **params: Any) -> np.ndarray:
Apply the transform to a volume.
volume: Input volume of shape (D, H, W) or (D, H, W, C).
**params: Additional parameters specific to the transform.
Returns Transformed volume of the same shape as input.
apply_to_volumes(volumes: np.ndarray, **params: Any) -> np.ndarray:
Apply the transform to multiple volumes.
volumes: Input volumes of shape (N, D, H, W) or (N, D, H, W, C).
**params: Additional parameters specific to the transform.
Returns Transformed volumes in the same format as input.
apply_to_mask3d(mask: np.ndarray, **params: Any) -> np.ndarray:
Apply the transform to a 3D mask.
mask: Input 3D mask of shape (D, H, W) or (D, H, W, C)
**params: Additional parameters specific to the transform.
Returns Transformed 3D mask in the same format as input.
apply_to_masks3d(masks: np.ndarray, **params: Any) -> np.ndarray:
Apply the transform to multiple 3D masks.
masks: Input 3D masks of shape (N, D, H, W) or (N, D, H, W, C)
**params: Additional parameters specific to the transform.
Returns Transformed 3D masks in the same format as input.
Note:
- All `apply_*` methods should maintain the input shape and format of the data.
- When applying transforms to masks, ensure that discrete values (e.g., class labels) are preserved.
- For keypoints and bounding boxes, the transformation should maintain their relative positions
with respect to the transformed image.
- The difference between `apply_to_mask` and `apply_to_masks` is mainly in how they handle 3D arrays:
`apply_to_mask` treats a 3D array as a multi-channel mask, while `apply_to_masks` treats it as
multiple single-channel masks.