Apply grid distortion by dividing the image into cells and warping each. Params: num_steps, distort_range, interpolation, normalized.
This transformation divides the image into a grid and randomly distorts each cell, creating localized warping effects. It's particularly useful for data augmentation in tasks like medical image analysis, OCR, and other domains where local geometric variations are meaningful.
num_stepsNumber of grid cells on each side of the image. Higher values create more granular distortions. Must be at least 1. Default: 5.
distort_rangeRange of distortion, sampled per image. Higher absolute values create stronger distortions. Should be in [-1, 1]. Default: (-0.3, 0.3).
interpolationOpenCV interpolation method used for image transformation. Options include cv2.INTER_LINEAR, cv2.INTER_CUBIC, etc. Default: cv2.INTER_LINEAR.
normalizedIf True, ensures that the distortion does not move pixels outside the image boundaries. This can result in less extreme distortions but guarantees that no information is lost. Default: True.
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.
keypoint_remapping_methodMethod to use for keypoint remapping.
pProbability of applying the transform. Default: 0.5.
>>> import albumentations as A
>>> transform = A.Compose([
... A.GridDistortion(num_steps=5, distort_range=(-0.3, 0.3), p=1.0),
... ])
>>> 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']