Randomly erase rectangular regions (Random Erasing). area_ratio_range, aspect_ratio_range, fill. Improves robustness; common in image classification.
This augmentation helps improve model robustness by randomly masking out rectangular regions in the image, simulating occlusions and encouraging the model to learn from partial information. It's particularly effective for image classification and person re-identification tasks.
scaleRange for the proportion of image area to erase. The actual area will be randomly sampled from (scale[0] * image_area, scale[1] * image_area). Default: (0.02, 0.33)
ratioRange for the aspect ratio (width/height) of the erased region. The actual ratio will be randomly sampled from (ratio[0], ratio[1]). Default: (0.3, 3.3)
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. Default: 0.5
>>> import numpy as np
>>> import albumentations as A
>>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
>>> # Basic usage with default parameters
>>> transform = A.Erasing()
>>> transformed = transform(image=image)
>>> # Custom configuration
>>> transform = A.Erasing(
... scale=(0.1, 0.4),
... ratio=(0.5, 2.0),
... fill_value="random_uniform",
... p=1.0
... )
>>> transformed = transform(image=image)