RandomShadow
Targets:
image
volume
Image Types:uint8, float32
Simulates shadows for the image by reducing the brightness of the image in shadow regions.
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.
Arguments
shadow_roituple[float, float, float, float]
[0,0.5,1,1]
Region 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_limittuple[int, int]
[1,2]
Lower and upper limits for the possible number of shadows. Default: (1, 2).
shadow_dimensionint
5
Number of edges in the shadow polygons. Default: 5.
shadow_intensity_rangetuple[float, float]
[0.5,0.5]
Range for the shadow intensity. Larger value means darker shadow. Should be two float values between 0 and 1. Default: (0.5, 0.5).
pfloat
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)
# 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"]Notes
- 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
References
- Shadow detection and removalhttps://www.sciencedirect.com/science/article/pii/S1047320315002035
- Shadows in computer visionhttps://en.wikipedia.org/wiki/Shadow_detection