CoarseDropout

Targets:
image
mask
bboxes
keypoints
volume
mask3d
Image Types:uint8, float32

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.

Arguments
num_holes_range
tuple[int, int]
[1,2]

Range (min, max) for the number of rectangular regions to drop out. Default: (1, 1)

hole_height_range
tuple[float, float] | tuple[int, int]
[0.1,0.2]

Range (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_range
tuple[float, float] | tuple[int, int]
[0.1,0.2]

Range (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)

fill
tuple[float, ...] | float | random | random_uniform | inpaint_telea | inpaint_ns
0

Value 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_mask
tuple[float, ...] | float | None

Fill value for dropout regions in the mask. If None, mask regions corresponding to image dropouts are unchanged. Default: None

p
float
0.5

Probability of applying the transform. Default: 0.5

Examples
>>> 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"]
Notes
  • 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.