Randomly drop rectangular regions from image (and optionally mask). num_holes_range, hole_size_range, fill. For robustness and regularization.
This transformation is an evolution of CutOut and RandomErasing, offering more flexibility in the size, number of dropout regions, and fill values.
num_holes_rangeRange (min, max) for the number of rectangular regions to drop out. Default: (1, 1)
hole_height_rangeRange (min, max) for the height of dropout regions. If int, specifies absolute pixel values. If float, interpreted as a fraction of the image height. Default: (0.1, 0.2)
hole_width_rangeRange (min, max) for the width of dropout regions. If int, specifies absolute pixel values. If float, interpreted as a fraction of the image width. Default: (0.1, 0.2)
fillValue for the dropped pixels. Can be:
fill_maskFill value for dropout regions in the mask. If None, mask regions corresponding to image dropouts are unchanged. Default: None
pProbability of applying the transform. Default: 0.5
>>> import numpy as np
>>> import albumentations as A
>>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
>>> mask = np.random.randint(0, 2, (100, 100), dtype=np.uint8)
>>> # Example with random uniform fill
>>> aug_random = A.CoarseDropout(
... num_holes_range=(3, 6),
... hole_height_range=(10, 20),
... hole_width_range=(10, 20),
... fill="random_uniform",
... p=1.0
... )
>>> # Example with inpainting
>>> aug_inpaint = A.CoarseDropout(
... num_holes_range=(3, 6),
... hole_height_range=(10, 20),
... hole_width_range=(10, 20),
... fill="inpaint_ns",
... p=1.0
... )
>>> transformed = aug_random(image=image, mask=mask)
>>> transformed_image, transformed_mask = transformed["image"], transformed["mask"]