Radial blur from zoom-during-exposure: average the image with copies zoomed from the center at random factors. Creates motion-like streaks away from the center.
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.
max_factor_rangeRange for max zoom factor; sampled per image. Both ends must be >= 1. Default: (1, 1.31).
step_factor_rangeRange for step parameter passed to np.arange when building the zoom levels; sampled per image. Both ends must be > 0. Default: (0.01, 0.03).
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 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_range=(1.05, 1.10), # Small zoom range
... step_factor_range=(0.01, 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_range=(1.15, 1.25), # Medium zoom range
... step_factor_range=(0.02, 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_range=(1.3, 1.5), # Large zoom range
... step_factor_range=(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_range=(-0.2, 0.2), contrast_range=(-0.2, 0.2), p=0.7),
... A.ZoomBlur(max_factor_range=(1.1, 1.3), step_factor_range=(0.02, 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