RandomRain
Adds rain effects to an image.
This transform simulates rainfall by overlaying semi-transparent streaks onto the image, creating a realistic rain effect. It can be used to augment datasets for computer vision tasks that need to perform well in rainy conditions.
slant_rangeRange for the rain slant angle in degrees. Negative values slant to the left, positive to the right. Default: (-10, 10).
drop_lengthLength of the rain drops in pixels. If None, drop length will be automatically calculated as height // 8. This allows the rain effect to scale with the image size. Default: None
drop_widthWidth of the rain drops in pixels. Default: 1.
drop_colorColor of the rain drops in RGB format. Default: (200, 200, 200).
blur_valueBlur value for simulating rain effect. Rainy views are typically blurry. Default: 7.
brightness_coefficientCoefficient to adjust the brightness of the image. Rainy scenes are usually darker. Should be in the range (0, 1]. Default: 0.7.
rain_typeType of rain to simulate.
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.RandomRain(p=1.0)
>>> rainy_image = transform(image=image)["image"]
# Custom rain parameters
>>> transform = A.RandomRain(
... slant_range=(-15, 15),
... drop_length=30,
... drop_width=2,
... drop_color=(180, 180, 180),
... blur_value=5,
... brightness_coefficient=0.8,
... p=1.0
... )
>>> rainy_image = transform(image=image)["image"]
# Simulating heavy rain
>>> transform = A.RandomRain(rain_type="heavy", p=1.0)
>>> heavy_rain_image = transform(image=image)["image"]- The rain effect is created by drawing semi-transparent lines on the image.
- The slant of the rain can be controlled to simulate wind effects.
- Different rain types (drizzle, heavy, torrential) adjust the density and appearance of the rain.
- The transform also adjusts image brightness and applies a blur to simulate the visual effects of rain.
- This transform is particularly useful for:
- Augmenting datasets for autonomous driving in rainy conditions
- Testing the robustness of computer vision models to weather effects
- Creating realistic rainy scenes for image editing or film production
- Rain visualization techniqueshttps://developer.nvidia.com/gpugems/gpugems3/part-iv-image-effects/chapter-27-real-time-rain-rendering
- Weather effects in computer visionhttps://www.sciencedirect.com/science/article/pii/S1077314220300692