RandomRain

Targets:
image
volume
Image Types:uint8, float32

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.

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"]
# Simulating heavy rain
>>> transform = A.RandomRain(rain_type="heavy", p=1.0)
>>> heavy_rain_image = transform(image=image)["image"]
Notes
  • 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