Simulate lens occlusion from rain or mud: splatter patterns and optional blur. fill and spread control appearance. Good for dirty or wet lens robustness.
mean_rangeMean of the normal distribution for generating the
liquid layer; sampled per image from (mean_range[0], mean_range[1]). For a
constant value use (mean, mean). Default: (0.65, 0.65).
std_rangeStandard deviation of the normal distribution for
generating the liquid layer; sampled per image from
(std_range[0], std_range[1]). For a constant value use (std, std).
Default: (0.3, 0.3).
gauss_sigma_rangeSigma for Gaussian filtering of the liquid
layer; sampled per image from (gauss_sigma_range[0], gauss_sigma_range[1]). For a
constant value use (sigma, sigma). Default: (2, 3).
cutout_threshold_rangeThreshold for filtering the liquid layer
(controls number of drops); sampled per image from
(cutout_threshold_range[0], cutout_threshold_range[1]). For a constant value use
(t, t). Default: (0.68, 0.68).
intensity_rangeIntensity of corruption; sampled per image from
(intensity_range[0], intensity_range[1]). For a constant value use (i, i).
Default: (0.6, 0.6).
modeType of corruption. Default: "rain".
colorCorruption elements color. If list uses provided list as color for the effect. If None uses default colors based on mode (rain: (238, 238, 175), mud: (20, 42, 63)).
pprobability of applying the transform. Default: 0.5.
>>> import numpy as np
>>> import albumentations as A
>>> import cv2
>>>
>>> # Create a sample image
>>> image = np.ones((300, 300, 3), dtype=np.uint8) * 200 # Light gray background
>>> # Add some gradient to make effects more visible
>>> for i in range(300):
... image[i, :, :] = np.clip(image[i, :, :] - i // 3, 0, 255)
>>>
>>> # Example 1: Rain effect with default parameters
>>> rain_transform = A.Spatter(
... mode="rain",
... p=1.0
... )
>>> rain_result = rain_transform(image=image)
>>> rain_image = rain_result['image'] # Image with rain drops
>>>
>>> # Example 2: Heavy rain with custom parameters
>>> heavy_rain = A.Spatter(
... mode="rain",
... mean_range=(0.7, 0.7), # Higher mean = more coverage
... std_range=(0.2, 0.2), # Lower std = more uniform effect
... cutout_threshold_range=(0.65, 0.65), # Lower threshold = more drops
... intensity_range=(0.8, 0.8), # Higher intensity = more visible effect
... color=(200, 200, 255), # Blueish rain drops
... p=1.0
... )
>>> heavy_rain_result = heavy_rain(image=image)
>>> heavy_rain_image = heavy_rain_result['image']
>>>
>>> # Example 3: Mud effect
>>> mud_transform = A.Spatter(
... mode="mud",
... mean_range=(0.6, 0.6),
... std_range=(0.3, 0.3),
... cutout_threshold_range=(0.62, 0.62),
... intensity_range=(0.7, 0.7),
... p=1.0
... )
>>> mud_result = mud_transform(image=image)
>>> mud_image = mud_result['image'] # Image with mud splatters
>>>
>>> # Example 4: Custom colored mud
>>> red_mud = A.Spatter(
... mode="mud",
... mean_range=(0.55, 0.55),
... std_range=(0.25, 0.25),
... cutout_threshold_range=(0.7, 0.7),
... intensity_range=(0.6, 0.6),
... color=(120, 40, 40), # Reddish-brown mud
... p=1.0
... )
>>> red_mud_result = red_mud(image=image)
>>> red_mud_image = red_mud_result['image']
>>>
>>> # Example 5: Random effect (50% chance of applying)
>>> random_spatter = A.Compose([
... A.Spatter(
... mode="rain" if np.random.random() < 0.5 else "mud",
... p=0.5
... )
... ])
>>> random_result = random_spatter(image=image)
>>> result_image = random_result['image'] # May or may not have spatter effect