CoarseDropout
CoarseDropout randomly drops out rectangular regions from the image and optionally, the corresponding regions in an associated mask, to simulate occlusion and varied object sizes found in real-world settings.
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:
- int or float: all channels are filled with this value
- tuple: tuple of values for each channel
- 'random': each pixel is filled with random values
- 'random_uniform': each hole is filled with a single random color
- 'inpaint_telea': uses OpenCV Telea inpainting method
- 'inpaint_ns': uses OpenCV Navier-Stokes inpainting method Default: 0
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"]- The actual number and size of dropout regions are randomly chosen within the specified ranges for each application.
- When using float values for hole_height_range and hole_width_range, ensure they are between 0 and 1.
- This implementation includes deprecation warnings for older parameter names (min_holes, max_holes, etc.).
- Inpainting methods ('inpaint_telea', 'inpaint_ns') work only with grayscale or RGB images.
- For 'random_uniform' fill, each hole gets a single random color, unlike 'random' where each pixel gets its own random value.
- CutOuthttps://arxiv.org/abs/1708.04552
- Random Erasinghttps://arxiv.org/abs/1708.04896
- OpenCV Inpainting methodshttps://docs.opencv.org/master/df/d3d/tutorial_py_inpainting.html