← Back to all transforms
RandomGridShuffle
Description
Randomly shuffles the grid's cells on an image, mask, or keypoints, effectively rearranging patches within the image. This transformation divides the image into a grid and then permutes these grid cells based on a random mapping. Args: grid (tuple[int, int]): Size of the grid for splitting the image into cells. Each cell is shuffled randomly. p (float): Probability that the transform will be applied. Targets: image, mask, keypoints Image types: uint8, float32 Examples: >>> import albumentations as A >>> transform = A.Compose([ A.RandomGridShuffle(grid=(3, 3), p=1.0) ]) >>> transformed = transform(image=my_image, mask=my_mask) >>> image, mask = transformed['image'], transformed['mask'] # This will shuffle the 3x3 grid cells of `my_image` and `my_mask` randomly. # Mask and image are shuffled in a consistent way Note: This transform could be useful when only micro features are important for the model, and memorizing the global structure could be harmful. For example: - Identifying the type of cell phone used to take a picture based on micro artifacts generated by phone post-processing algorithms, rather than the semantic features of the photo. See more at https://ieeexplore.ieee.org/abstract/document/8622031 - Identifying stress, glucose, hydration levels based on skin images.
Parameters
- p: float (default: 0.5)
- grid: tuple[int, int] (default: (3, 3))
Targets
- Image
- Mask
- Keypoints
Try it out
Original Image (width = 484, height = 733):
Transformed Image:
Transform not yet applied