Apply elastic deformation to images, masks, bboxes, keypoints. Params: alpha, sigma, interpolation. Uses Gaussian-smoothed random displacement fields.
This transformation introduces random elastic distortions to the input data. It's particularly useful for data augmentation in training deep learning models, especially for tasks like image segmentation or object detection where you want to maintain the relative positions of features while introducing realistic deformations.
The transform works by generating random displacement fields and applying them to the input. These fields are smoothed using a Gaussian filter to create more natural-looking distortions.
Targets: image, mask, bboxes, keypoints, volume, mask3d
Image types: uint8, float32
Supported bboxes: hbb, obb
alphaScaling factor for the random displacement fields. Higher values result in more pronounced distortions. Default: 1.0
sigmaStandard deviation of the Gaussian filter used to smooth the displacement fields. Higher values result in smoother, more global distortions. Default: 50.0
interpolationInterpolation method to be used for image transformation. Should be one of the OpenCV interpolation types. Default: cv2.INTER_LINEAR
approximateWhether to use an approximate version of the elastic transform. If True, uses a fixed kernel size for Gaussian smoothing, which can be faster but potentially less accurate for large sigma values. Default: False
same_dxdyWhether to use the same random displacement field for both x and y directions. Can speed up the transform at the cost of less diverse distortions. Default: False
mask_interpolationFlag that is used to specify the interpolation algorithm for mask. Should be one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4. Default: cv2.INTER_NEAREST.
noise_distributionDistribution used to generate the displacement fields. "gaussian" generates fields using normal distribution (more natural deformations). "uniform" generates fields using uniform distribution (more mechanical deformations). Default: "gaussian".
keypoint_remapping_methodMethod to use for keypoint remapping.
pProbability of applying the transform. Default: 0.5
>>> import albumentations as A
>>> transform = A.Compose([
... A.ElasticTransform(alpha=1, sigma=50, p=0.5),
... ])
>>> transformed = transform(image=image, mask=mask, bboxes=bboxes, keypoints=keypoints)
>>> transformed_image = transformed['image']
>>> transformed_mask = transformed['mask']
>>> transformed_bboxes = transformed['bboxes']
>>> transformed_keypoints = transformed['keypoints']