Apply bounded XY deformations from a compact control grid to images and annotations. Use it for shape variation in segmentation and medical imaging.
displacement_range is measured relative to the shorter span between the first and last
pixel centers. The sampled cubic B-spline coefficients use pixel units after scaling. One map
is shared by every raster and annotation target in an invocation; volumes receive the same XY
deformation on every depth slice.
displacement_rangeRange for the sampled relative displacement magnitude.
control_grid_shapeNumber of cubic B-spline coefficient rows and columns, each at least 4.
interpolationInterpolation used for images.
mask_interpolationInterpolation used for masks.
border_modeOpenCV border mode for raster targets.
fillFill value for images.
fill_maskFill value for masks.
pProbability of applying the transform.
>>> import numpy as np
>>> import albumentations as A
>>> image = np.zeros((100, 100, 3), dtype=np.uint8)
>>> mask = np.zeros((100, 100), dtype=np.uint8)
>>> bboxes = np.array([[10, 10, 50, 50]], dtype=np.float32)
>>> bbox_labels = [1]
>>> keypoints = np.array([[20, 30]], dtype=np.float32)
>>> keypoint_labels = [0]
>>> transform = A.Compose(
... [A.ElasticTransform(displacement_range=(0.02, 0.05), control_grid_shape=(7, 7), p=1.0)],
... bbox_params=A.BboxParams(coord_format="pascal_voc", label_fields=["bbox_labels"]),
... keypoint_params=A.KeypointParams(
... coord_format="xy", label_fields=["keypoint_labels"], label_mapping={}
... ),
... )
>>> transformed = transform(
... image=image,
... mask=mask,
... bboxes=bboxes,
... bbox_labels=bbox_labels,
... keypoints=keypoints,
... keypoint_labels=keypoint_labels,
... )
>>> transformed_image = transformed["image"]
>>> transformed_mask = transformed["mask"]
>>> transformed_bboxes = transformed["bboxes"]
>>> transformed_bbox_labels = transformed["bbox_labels"]
>>> transformed_keypoints = transformed["keypoints"]
>>> transformed_keypoint_labels = transformed["keypoint_labels"]The constructor enforces 2 * high * sqrt((rows - 3)^2 + (columns - 3)^2) < 0.75.
ReplayCompose stores the compact sampled coefficient lattice and replays it for the same
spatial shape. Applied configuration fixes the realized magnitude but samples a new lattice.