RandomRain
Add rain streaks (semi-transparent lines), optional blur and brightness reduction. Good for outdoor or driving robustness to rainy conditions.
Streaks are drawn with configurable slant, length, and width; blur and darkening simulate wet, low-contrast views. Density and style are configurable (e.g. drizzle, heavy, torrential).
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"]
>>>
>>> # Heavy rain
>>> transform = A.RandomRain(rain_type="heavy", p=1.0)
>>> heavy_rain_image = transform(image=image)["image"]- Rain is drawn as semi-transparent lines; slant simulates wind.
- rain_type (drizzle, heavy, torrential, default) controls drop count and style.
- Blur and brightness reduction mimic wet, darker scenes.
- RandomSnow: Snow overlay for winter conditions.
- RandomFog: Patch-based fog without depth.
- AtmosphericFog: Depth-dependent fog via scattering.
- 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