RandomShadow
Simulate cast shadows by darkening random regions. shadow_roi, num_shadows, shadow_dimension control placement and softness. Improves lighting robustness.
This transform adds realistic shadow effects to images, which can be useful for augmenting datasets for outdoor scene analysis, autonomous driving, or any computer vision task where shadows may be present.
shadow_roiRegion of the image where shadows will appear (x_min, y_min, x_max, y_max). All values should be in range [0, 1]. Default: (0, 0.5, 1, 1).
num_shadows_limitLower and upper limits for the possible number of shadows. Default: (1, 2).
shadow_dimensionNumber of edges in the shadow polygons. Default: 5.
shadow_intensity_rangeRange for the shadow intensity. Larger value means darker shadow. Should be two float values between 0 and 1. Default: (0.5, 0.5).
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)
# Default usage
>>> transform = A.RandomShadow(p=1.0)
>>> shadowed_image = transform(image=image)["image"]
# Custom shadow parameters
>>> transform = A.RandomShadow(
... shadow_roi=(0.2, 0.2, 0.8, 0.8),
... num_shadows_limit=(2, 4),
... shadow_dimension=8,
... shadow_intensity_range=(0.3, 0.7),
... p=1.0
... )
>>> shadowed_image = transform(image=image)["image"]
# Combining with other transforms
>>> transform = A.Compose([
... A.RandomShadow(p=0.5),
... A.RandomBrightnessContrast(p=0.5),
... ])
>>> augmented_image = transform(image=image)["image"]- Shadows are created by generating random polygons within the specified ROI and reducing the brightness of the image in these areas.
- The number of shadows, their shapes, and intensities can be randomized for variety.
- This transform is particularly useful for:
- Augmenting datasets for outdoor scene understanding
- Improving robustness of object detection models to shadowed conditions
- Simulating different lighting conditions in synthetic datasets
- Shadow detection and removalhttps://www.sciencedirect.com/science/article/pii/S1047320315002035
- Shadows in computer visionhttps://en.wikipedia.org/wiki/Shadow_detection