← Back to all transforms
GridElasticDeform
Description
Apply elastic deformations to images, masks, bounding boxes, and keypoints using a grid-based approach. This transformation overlays a grid on the input and applies random displacements to the grid points, resulting in local elastic distortions. The granularity and intensity of the distortions can be controlled using the dimensions of the overlaying distortion grid and the magnitude parameter. Args: num_grid_xy (tuple[int, int]): Number of grid cells along the width and height. Specified as (grid_width, grid_height). Each value must be greater than 1. magnitude (int): Maximum pixel-wise displacement for distortion. Must be greater than 0. interpolation (int): Interpolation method to be used for the image transformation. Default: cv2.INTER_LINEAR mask_interpolation (int): Interpolation method to be used for mask transformation. Default: cv2.INTER_NEAREST p (float): Probability of applying the transform. Default: 1.0. Targets: image, mask, bboxes, keypoints Image types: uint8, float32 Example: >>> transform = GridElasticDeform(num_grid_xy=(4, 4), magnitude=10, p=1.0) >>> result = transform(image=image, mask=mask) >>> transformed_image, transformed_mask = result['image'], result['mask'] Note: This transformation is particularly useful for data augmentation in medical imaging and other domains where elastic deformations can simulate realistic variations.
Parameters
- num_grid_xy: tuple[int, int] (default: (8, 8))
- magnitude: int (default: 10)
- interpolation: Literal['cv2.INTER_NEAREST', 'cv2.INTER_LINEAR', 'cv2.INTER_CUBIC', 'cv2.INTER_AREA', 'cv2.INTER_LANCZOS4', 'cv2.INTER_BITS', 'cv2.INTER_NEAREST_EXACT', 'cv2.INTER_MAX'] (default: 1)
- mask_interpolation: Literal['cv2.INTER_NEAREST', 'cv2.INTER_LINEAR', 'cv2.INTER_CUBIC', 'cv2.INTER_AREA', 'cv2.INTER_LANCZOS4', 'cv2.INTER_BITS', 'cv2.INTER_NEAREST_EXACT', 'cv2.INTER_MAX'] (default: 0)
- p: float (default: 1)
Targets
- Image
- Mask
- BBoxes
- Keypoints
Try it out
ⓘ