← Back to all transforms
GridDistortion
Description
Applies grid distortion augmentation to images, masks, and bounding boxes. This technique involves dividing the image into a grid of cells and randomly displacing the intersection points of the grid, resulting in localized distortions. Args: num_steps (int): Number of grid cells on each side (minimum 1). distort_limit (float, (float, float)): Range of distortion limits. If a single float is provided, the range will be from (-distort_limit, distort_limit). Default: (-0.3, 0.3). interpolation (OpenCV flag): Interpolation algorithm used for image transformation. Options are: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4. Default: cv2.INTER_LINEAR. border_mode (OpenCV flag): Pixel extrapolation method used when pixels outside the image are required. Options are: cv2.BORDER_CONSTANT, cv2.BORDER_REPLICATE, cv2.BORDER_REFLECT, cv2.BORDER_WRAP, cv2.BORDER_REFLECT_101. Default: cv2.BORDER_REFLECT_101. value (int, float, list of ints, list of floats, optional): Value used for padding when border_mode is cv2.BORDER_CONSTANT. mask_value (int, float, list of ints, list of floats, optional): Padding value for masks when border_mode is cv2.BORDER_CONSTANT. normalized (bool): If True, ensures that distortion does not exceed image boundaries. Default: False. Reference: https://github.com/albumentations-team/albumentations/pull/722 Targets: image, mask, bboxes Image types: uint8, float32 Note: This transform is helpful in medical imagery, Optical Character Recognition, and other tasks where local distance may not be preserved.
Parameters
- p: float (default: 0.5)
- num_steps: int (default: 5)
- distort_limit: int | tuple[int, int] | float | tuple[float, float] (default: (-0.3, 0.3))
- 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)
- border_mode: Literal['cv2.BORDER_CONSTANT', 'cv2.BORDER_REPLICATE', 'cv2.BORDER_REFLECT', 'cv2.BORDER_WRAP', 'cv2.BORDER_DEFAULT', 'cv2.BORDER_TRANSPARENT'] (default: 4)
- value: float | Sequence[float] | None (default: null)
- mask_value: float | Sequence[float] | None (default: null)
- normalized: bool (default: false)
Targets
- Image
- Mask
- BBoxes
Try it out
Original Image (width = 484, height = 733):
Transformed Image:
Transform not yet applied