Apply coarse dropout only in regions containing specified objects (mask or bbox labels). mask_indices or bbox_labels; num_holes_range, hole size ranges.
This augmentation creates holes (dropout regions) for each target object in the image. Objects can be specified either by their class indices in a segmentation mask or by their labels in bounding box annotations.
The hole generation differs between mask and box modes:
Mask mode:
Box mode:
In both modes:
num_holes_rangeRange for number of holes per object (min, max)
hole_height_rangeRange for hole height as proportion of object height/size (min, max). E.g., (0.2, 0.4) means:
hole_width_rangeRange for hole width, similar to height
fillValue used to fill the erased regions. Can be:
fill_maskValue used to fill erased regions in the mask. If None, mask regions are not modified. Default: None
pProbability of applying the transform
mask_indicesList of class indices in segmentation mask to target. Only objects of these classes will be considered for hole placement.
bbox_labelsList of object labels in bbox annotations to target. String labels will be automatically encoded. When multiple label fields are specified in BboxParams, only the first label field is used for filtering.
>>> # Using segmentation mask
>>> transform = ConstrainedCoarseDropout(
... num_holes_range=(2, 4), # 2-4 holes per object
... hole_height_range=(0.2, 0.4), # 20-40% of sqrt(object area)
... hole_width_range=(0.2, 0.4), # 20-40% of sqrt(object area)
... mask_indices=[1, 2], # Target objects of class 1 and 2
... fill=0, # Fill holes with black
... )
>>> # Apply to image and its segmentation mask
>>> transformed = transform(image=image, mask=mask)
>>> # Using bounding boxes with Compose
>>> transform = A.Compose([
... ConstrainedCoarseDropout(
... num_holes_range=(1, 3),
... hole_height_range=(0.3, 0.5), # 30-50% of box height
... hole_width_range=(0.3, 0.5), # 30-50% of box width
... bbox_labels=['person'], # Target people
... fill=127, # Fill holes with gray
... )
... ], bbox_params=A.BboxParams(
... format='pascal_voc', # [x_min, y_min, x_max, y_max]
... label_fields=['labels'] # Specify field containing labels
... ))
>>> # Apply to image and its bounding boxes
>>> transformed = transform(
... image=image,
... bboxes=[[0, 0, 100, 100, 'car'], [150, 150, 300, 300, 'person']],
... labels=['car', 'person']
... )At least one of mask_indices or bbox_labels must be provided. If both are provided, mask_indices takes precedence.