RandomSnow

Targets:
image
volume
Image Types:uint8, float32

Applies a random snow effect to the input image.

This transform simulates snowfall by either bleaching out some pixel values or adding a snow texture to the image, depending on the chosen method.

Arguments
snow_point_range
tuple[float, float]
[0.1,0.3]

Range for the snow point threshold. Both values should be in the (0, 1) range. Default: (0.1, 0.3).

brightness_coeff
float
2.5

Coefficient applied to increase the brightness of pixels below the snow_point threshold. Larger values lead to more pronounced snow effects. Should be > 0. Default: 2.5.

method
bleach | texture
bleach

The snow simulation method to use. Options are:

  • "bleach": Uses a simple pixel value thresholding technique.
  • "texture": Applies a more realistic snow texture overlay. Default: "texture".
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 (bleach method)
>>> transform = A.RandomSnow(p=1.0)
>>> snowy_image = transform(image=image)["image"]

# Using texture method with custom parameters
>>> transform = A.RandomSnow(
...     snow_point_range=(0.2, 0.4),
...     brightness_coeff=2.0,
...     method="texture",
...     p=1.0
... )
>>> snowy_image = transform(image=image)["image"]
Notes
  • The "bleach" method increases the brightness of pixels above a certain threshold, creating a simple snow effect. This method is faster but may look less realistic.
  • The "texture" method creates a more realistic snow effect through the following steps:
    1. Converts the image to HSV color space for better control over brightness.
    2. Increases overall image brightness to simulate the reflective nature of snow.
    3. Generates a snow texture using Gaussian noise, which is then smoothed with a Gaussian filter.
    4. Applies a depth effect to the snow texture, making it more prominent at the top of the image.
    5. Blends the snow texture with the original image using alpha compositing.
    6. Adds a slight blue tint to simulate the cool color of snow.
    7. Adds random sparkle effects to simulate light reflecting off snow crystals. This method produces a more realistic result but is computationally more expensive.