Apply coarse dropout within a caller-supplied binary region while preserving selected bounding boxes and filtering annotations by the actual dropout mask.
The caller supplies a two-dimensional binary region as top-level metadata. A pixel value of True or 1 permits dropout; False or 0 leaves the pixel unchanged. Hole centers are sampled uniformly over the entire eligible region, after subtracting protected bounding boxes and their margins.
region_keyTop-level key containing the binary (H, W) dropout region. Default: "dropout_region".
protected_bbox_labelsLabels of boxes to protect. String labels use the configured bbox label encoder. Default: None.
protection_marginRelative expansion applied to every protected box side. A margin m expands horizontally by m * box_width and vertically by m * box_height. Default: 0.0.
num_holes_rangeInclusive number of holes sampled per image. Default: (1, 1).
hole_height_rangeHole-height fraction of the full image height. Default: (0.05, 0.20).
hole_width_rangeHole-width fraction of the full image width. Default: (0.05, 0.20).
fillValue used for dropped image pixels. Default: 0.
fill_maskValue used for dropped mask pixels. None leaves masks unchanged. Default: None.
pProbability of applying the transform. Default: 0.5.
>>> import albumentations as A
>>> import numpy as np
>>> image = np.full((100, 100, 3), 255, dtype=np.uint8)
>>> dropout_region = np.zeros((100, 100), dtype=np.uint8)
>>> dropout_region[20:80, 20:80] = 1
>>> transform = A.Compose(
... [A.GuidedCoarseDropout(fill=0, p=1.0)],
... bbox_params=A.BboxParams(coord_format="pascal_voc", label_fields=["labels"]),
... )
>>> result = transform(
... image=image,
... dropout_region=dropout_region,
... bboxes=[[40, 40, 60, 60]],
... labels=["person"],
... )