Spatter

Targets:
image
volume
Image Types:uint8, float32

Apply spatter transform. It simulates corruption which can occlude a lens in the form of rain or mud.

Arguments
mean
tuple[float, float] | float
[0.65,0.65]

Mean value of normal distribution for generating liquid layer. If single float mean will be sampled from (0, mean) If tuple of float mean will be sampled from range (mean[0], mean[1]). If you want constant value use (mean, mean). Default (0.65, 0.65)

std
tuple[float, float] | float
[0.3,0.3]

Standard deviation value of normal distribution for generating liquid layer. If single float the number will be sampled from (0, std). If tuple of float std will be sampled from range (std[0], std[1]). If you want constant value use (std, std). Default: (0.3, 0.3).

gauss_sigma
tuple[float, float] | float
[2,2]

Sigma value for gaussian filtering of liquid layer. If single float the number will be sampled from (0, gauss_sigma). If tuple of float gauss_sigma will be sampled from range (gauss_sigma[0], gauss_sigma[1]). If you want constant value use (gauss_sigma, gauss_sigma). Default: (2, 3).

cutout_threshold
tuple[float, float] | float
[0.68,0.68]

Threshold for filtering liquid layer (determines number of drops). If single float it will used as cutout_threshold. If single float the number will be sampled from (0, cutout_threshold). If tuple of float cutout_threshold will be sampled from range (cutout_threshold[0], cutout_threshold[1]). If you want constant value use (cutout_threshold, cutout_threshold). Default: (0.68, 0.68).

intensity
tuple[float, float] | float
[0.6,0.6]

Intensity of corruption. If single float the number will be sampled from (0, intensity). If tuple of float intensity will be sampled from range (intensity[0], intensity[1]). If you want constant value use (intensity, intensity). Default: (0.6, 0.6).

mode
rain | mud
rain

Type of corruption. Default: "rain".

color
Sequence | None

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

p
float
0.5

probability of applying the transform. Default: 0.5.

Examples
>>> 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=(0.7, 0.7),             # Higher mean = more coverage
...     std=(0.2, 0.2),              # Lower std = more uniform effect
...     cutout_threshold=(0.65, 0.65),  # Lower threshold = more drops
...     intensity=(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=(0.6, 0.6),
...     std=(0.3, 0.3),
...     cutout_threshold=(0.62, 0.62),
...     intensity=(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=(0.55, 0.55),
...     std=(0.25, 0.25),
...     cutout_threshold=(0.7, 0.7),
...     intensity=(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
References