AlbumentationsExplore
DocumentationExploreAdoptionPricingBlog
GitHub

GaussianBlur

Targets:
image
volume
Image Types:uint8, float32

Smooth an image with Gaussian blur to reduce noise and fine detail. Blur strength and size are sampled independently on every call.

This transform blurs the input image using a Gaussian filter with a random kernel size and sigma value. Gaussian blur is a widely used image processing technique that reduces image noise and detail, creating a smoothing effect.

Arguments
sigma_range
tuple[float, float]
[0.5, 3]

Inclusive range for the Gaussian kernel standard deviation (sigma). Both ends must be >= 0. Default: (0.5, 3.0)

blur_range
tuple[int, int]
[0, 0]

Inclusive range of the Gaussian kernel size. Both ends must be 0 or odd and >= 0. The default (0, 0) uses Pillow's three-pass extended-box approximation. Positive values use a discrete Gaussian kernel with the sampled size. Default: (0, 0)

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 for demonstration
>>> image = np.zeros((300, 300, 3), dtype=np.uint8)
>>> # Add some shapes to visualize blur effects
>>> cv2.rectangle(image, (100, 100), (200, 200), (255, 0, 0), -1)  # Red square
>>> cv2.circle(image, (150, 150), 30, (0, 255, 0), -1)  # Green circle
>>> cv2.putText(image, "Sample Text", (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
>>>
>>> # Example 1: Default Pillow-compatible Gaussian blur
>>> default_blur = A.Compose([
...     A.GaussianBlur(p=1.0)  # Using default parameters
... ])
>>>
>>> default_result = default_blur(image=image)
>>> default_blurred = default_result["image"]
>>> # The image will have a medium Gaussian blur with sigma between 0.5 and 3.0
>>>
>>> # Example 2: Light Gaussian blur
>>> light_blur = A.Compose([
...     A.GaussianBlur(
...         sigma_range=(0.2, 0.5),  # Small sigma for subtle blur
...         blur_range=(0, 0),       # Use Pillow-compatible automatic blur
...         p=1.0
...     )
... ])
>>>
>>> light_result = light_blur(image=image)
>>> light_blurred = light_result["image"]
>>> # The image will have a subtle Gaussian blur effect
>>>
>>> # Example 3: Strong Gaussian blur
>>> strong_blur = A.Compose([
...     A.GaussianBlur(
...         sigma_range=(3.0, 7.0),  # Larger sigma for stronger blur
...         blur_range=(0, 0),       # Use Pillow-compatible automatic blur
...         p=1.0
...     )
... ])
>>>
>>> strong_result = strong_blur(image=image)
>>> strong_blurred = strong_result["image"]
>>> # The image will have a strong Gaussian blur effect
>>>
>>> # Example 4: Fixed kernel size
>>> fixed_kernel = A.Compose([
...     A.GaussianBlur(
...         sigma_range=(0.5, 2.0),
...         blur_range=(9, 9),       # Fixed 9x9 kernel size
...         p=1.0
...     )
... ])
>>>
>>> fixed_result = fixed_kernel(image=image)
>>> fixed_kernel_blur = fixed_result["image"]
>>> # The image will have Gaussian blur with a fixed 9x9 kernel
>>>
>>> # Example 5: Random kernel size range
>>> random_kernel = A.Compose([
...     A.GaussianBlur(
...         sigma_range=(1.0, 2.0),
...         blur_range=(5, 9),       # Kernel size between 5x5 and 9x9
...         p=1.0
...     )
... ])
>>>
>>> random_result = random_kernel(image=image)
>>> random_kernel_blur = random_result["image"]
>>> # The image will have Gaussian blur with a kernel size between 5x5 and 9x9
>>>
>>> # Example 6: In an augmentation pipeline
>>> pipeline = A.Compose([
...     A.RandomBrightnessContrast(brightness_range=(-0.2, 0.2), contrast_range=(-0.2, 0.2), p=0.5),
...     A.GaussianBlur(sigma_range=(0.5, 1.5), p=0.3),  # 30% chance of applying
...     A.RGBShift(r_shift_range=(-10, 10), g_shift_range=(-10, 10), b_shift_range=(-10, 10), p=0.3)
... ])
>>>
>>> pipeline_result = pipeline(image=image)
>>> transformed_image = pipeline_result["image"]
>>> # The image may have Gaussian blur applied with 30% probability along with other effects
Notes
  • For uint8 images, blur_range=(0, 0) matches Pillow's GaussianBlur pixel for pixel, including its fixed-point rounding and replicated border handling.
  • Float32 images use the same extended-box approximation without uint8 quantization.
  • Positive blur_range values select a discrete Gaussian kernel independently of sigma, so some size and sigma combinations can truncate the blur substantially.
  • The default sigma range (0.5, 3.0) provides a good balance between subtle
References
  • OpenCV Gaussian Blurhttps://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#gaabe8c836e97159a9193fb0b11ac52cf1
  • PIL GaussianBlurhttps://pillow.readthedocs.io/en/stable/reference/ImageFilter.html#PIL.ImageFilter.GaussianBlur