albumentations.core.transforms_interface


Module containing base interfaces for all transform implementations. This module defines the fundamental transform interfaces that form the base hierarchy for all transformation classes in Albumentations. It provides abstract classes and mixins that define common behavior for image, keypoint, bounding box, and volumetric transformations. The interfaces handle parameter validation, random state management, target type checking, and serialization capabilities that are inherited by concrete transform implementations.

BaseTransformInitSchemaclass

BaseTransformInitSchema(
    p: Annotated,
    strict: bool = False
)

Parameters

NameTypeDefaultDescription
pAnnotated--
strictboolFalse-

BasicTransformclass

BasicTransform(
    p: float = 0.5
)

Base class for all transforms in Albumentations. This class provides core functionality for transform application, serialization, and parameter handling. It defines the interface that all transforms must follow and implements common methods used across different transform types. Class Attributes: _targets (tuple[Targets, ...] | Targets): Target types this transform can work with. _available_keys (set[str]): String representations of valid target keys. _key2func (dict[str, Callable[..., Any]]): Mapping between target keys and their processing functions.

Parameters

NameTypeDefaultDescription
pfloat0.5Probability of applying the transform.

CombinedMetaclass

CombinedMeta(
    name: str,
    bases: tuple[type, ...]
)

Parameters

NameTypeDefaultDescription
namestr--
basestuple[type, ...]--

DualTransformclass

DualTransform(
    p: float = 0.5
)

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.

Parameters

NameTypeDefaultDescription
pfloat0.5-

Notes

- 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.

ImageOnlyTransformclass

ImageOnlyTransform(
    p: float = 0.5
)

Transform applied to image only.

Parameters

NameTypeDefaultDescription
pfloat0.5-

Interpolationclass

Interpolation(
    downscale: int = 0,
    upscale: int = 0
)

Parameters

NameTypeDefaultDescription
downscaleint0-
upscaleint0-

NoOpclass

NoOp(
    p: float = 0.5
)

Identity transform (does nothing). Targets: image, mask, bboxes, keypoints, volume, mask3d

Parameters

NameTypeDefaultDescription
pfloat0.5-

Transform3Dclass

Transform3D(
    p: float = 0.5
)

Base class for all 3D transforms. Transform3D inherits from DualTransform because 3D transforms can be applied to both volumes and masks, similar to how 2D DualTransforms work with images and masks. Targets: volume: 3D numpy array of shape (D, H, W) or (D, H, W, C) volumes: Batch of 3D arrays of shape (N, D, H, W) or (N, D, H, W, C) mask: 3D numpy array of shape (D, H, W) masks: Batch of 3D arrays of shape (N, D, H, W) keypoints: 3D numpy array of shape (N, 3)

Parameters

NameTypeDefaultDescription
pfloat0.5-