ZoomBlur

Targets:
image
volume
Image Types:uint8, float32

Apply zoom blur transform.

This transform simulates the effect of zooming during exposure, creating a dynamic radial blur. It works by averaging multiple versions of the image at different zoom levels, creating a smooth transition from the center outward.

Arguments
max_factor
tuple[float, float] | float
[1,1.31]

range for max factor for blurring. If max_factor is a single float, the range will be (1, limit). Default: (1, 1.31). All max_factor values should be larger than 1.

step_factor
tuple[float, float] | float
[0.01,0.03]

If single float will be used as step parameter for np.arange. If tuple of float step_factor will be in range [step_factor[0], step_factor[1]). Default: (0.01, 0.03). All step_factor values should be positive.

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 zoom 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.line(image, (50, 150), (250, 150), (0, 0, 255), 5)  # Blue line
>>>
>>> # Example 1: Subtle zoom blur
>>> subtle_transform = A.Compose([
...     A.ZoomBlur(
...         max_factor=(1.05, 1.10),  # Small zoom range
...         step_factor=0.01,         # Fine steps
...         p=1.0                     # Always apply
...     )
... ])
>>>
>>> subtle_result = subtle_transform(image=image)
>>> subtle_blur = subtle_result["image"]
>>> # The image will have a subtle zoom blur effect, simulating a slight zoom during exposure
>>>
>>> # Example 2: Moderate zoom blur
>>> moderate_transform = A.Compose([
...     A.ZoomBlur(
...         max_factor=(1.15, 1.25),  # Medium zoom range
...         step_factor=0.02,         # Medium steps
...         p=1.0
...     )
... ])
>>>
>>> moderate_result = moderate_transform(image=image)
>>> moderate_blur = moderate_result["image"]
>>> # The image will have a more noticeable zoom blur effect
>>>
>>> # Example 3: Strong zoom blur
>>> strong_transform = A.Compose([
...     A.ZoomBlur(
...         max_factor=(1.3, 1.5),    # Large zoom range
...         step_factor=(0.03, 0.05), # Larger steps (randomly chosen)
...         p=1.0
...     )
... ])
>>>
>>> strong_result = strong_transform(image=image)
>>> strong_blur = strong_result["image"]
>>> # The image will have a strong zoom blur effect, simulating fast zooming
>>>
>>> # Example 4: In a pipeline with other transforms
>>> pipeline = A.Compose([
...     A.RandomBrightnessContrast(brightness_limit=0.2, contrast_limit=0.2, p=0.7),
...     A.ZoomBlur(max_factor=(1.1, 1.3), step_factor=0.02, p=0.5),
...     A.HorizontalFlip(p=0.5)
... ])
>>>
>>> pipeline_result = pipeline(image=image)
>>> transformed_image = pipeline_result["image"]
>>> # The image may have zoom blur applied with 50% probability