Average pixels over a random square kernel (box filter). Fast, soft blur; kernel size from blur_limit. Good for mild smoothing or augmentation variety.
This transform uses OpenCV's cv2.blur function, which performs a simple box filter blur. The size of the blur kernel is randomly selected for each application, allowing for varying degrees of blur intensity.
blur_limitControls the range of the blur kernel size.
pProbability of applying the transform. Default: 0.5
>>> 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, (50, 50), (250, 250), (255, 0, 0), -1) # Red square
>>> cv2.circle(image, (150, 150), 60, (0, 255, 0), -1) # Green circle
>>> cv2.line(image, (50, 150), (250, 150), (0, 0, 255), 5) # Blue line
>>>
>>> # Example 1: Basic usage with default parameters
>>> transform = A.Compose([
... A.Blur(p=1.0) # Always apply with default blur_limit=(3, 7)
... ])
>>>
>>> result = transform(image=image)
>>> blurred_image = result["image"]
>>> # The image will have a random blur with kernel size between 3 and 7
>>>
>>> # Example 2: Using a fixed blur kernel size
>>> fixed_transform = A.Compose([
... A.Blur(blur_limit=5, p=1.0) # Always use kernel size 5x5
... ])
>>>
>>> fixed_result = fixed_transform(image=image)
>>> fixed_blurred_image = fixed_result["image"]
>>> # The image will have a consistent 5x5 kernel blur
>>>
>>> # Example 3: Using a custom range for blur kernel sizes
>>> strong_transform = A.Compose([
... A.Blur(blur_limit=(7, 13), p=1.0) # Use larger kernel for stronger blur
... ])
>>>
>>> strong_result = strong_transform(image=image)
>>> strong_blurred = strong_result["image"]
>>> # The image will have a stronger blur with kernel size between 7 and 13
>>>
>>> # Example 4: As part of a pipeline with other transforms
>>> pipeline = A.Compose([
... A.RandomBrightnessContrast(brightness_limit=0.2, contrast_limit=0.2, p=0.7),
... A.Blur(blur_limit=(3, 5), p=0.5), # 50% chance of applying blur
... A.HorizontalFlip(p=0.5)
... ])
>>>
>>> pipeline_result = pipeline(image=image)
>>> transformed_image = pipeline_result["image"]
>>> # The image may or may not be blurred depending on the random probability