RandomRain

Targets:
image
Image Types:uint8, float32

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).

Arguments
slant_range
tuple[float, float]
[-10,10]

Range for the rain slant angle in degrees. Negative values slant to the left, positive to the right. Default: (-10, 10).

drop_length
int | None

Length 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_width
int
1

Width of the rain drops in pixels. Default: 1.

drop_color
tuple[int, int, int]
[200,200,200]

Color of the rain drops in RGB format. Default: (200, 200, 200).

blur_value
int
7

Blur value for simulating rain effect. Rainy views are typically blurry. Default: 7.

brightness_coefficient
float
0.7

Coefficient to adjust the brightness of the image. Rainy scenes are usually darker. Should be in the range (0, 1]. Default: 0.7.

rain_type
drizzle | heavy | torrential | default
default

Type of rain to simulate.

p
float
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.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"]
Notes
  • 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.
See Also
  • RandomSnow: Snow overlay for winter conditions.
  • RandomFog: Patch-based fog without depth.
  • AtmosphericFog: Depth-dependent fog via scattering.