Interested in advertising?

Contact us

Stay updated

News & Insights
transform
utils
check_version
transforms
API Documentation | Albumentations

albumentations.augmentations.blur.functional


Functional implementations of various blur operations for image processing. This module provides a collection of low-level functions for applying different blur effects to images, including standard blur, median blur, glass blur, defocus, and zoom effects. These functions form the foundation for the corresponding transform classes.

box_blurfunction

Blur an image. This function applies a blur to an image.

Parameters

NameTypeDefaultDescription
imgnp.ndarray-Input image.
ksizeint-Kernel size.

Returns

  • np.ndarray: Blurred image.

central_zoomfunction

Central zoom an image. This function zooms an image.

Parameters

NameTypeDefaultDescription
imgnp.ndarray-Input image.
zoom_factorint-Zoom factor.

Returns

  • np.ndarray: Zoomed image.

create_gaussian_kernelfunction

Create a Gaussian kernel following PIL's approach.

Parameters

NameTypeDefaultDescription
sigmafloat-Standard deviation for Gaussian kernel.
ksizeint0Kernel size. If 0, size is computed as int(sigma * 3.5) * 2 + 1 to match PIL's implementation. Otherwise, must be positive and odd.

Returns

  • np.ndarray: 2D normalized Gaussian kernel.

create_gaussian_kernel_1dfunction

Create a 1D Gaussian kernel following PIL's approach.

Parameters

NameTypeDefaultDescription
sigmafloat-Standard deviation for Gaussian kernel.
ksizeint0Kernel size. If 0, size is computed as int(sigma * 3.5) * 2 + 1 to match PIL's implementation. Otherwise, must be positive and odd.

Returns

  • np.ndarray: 1D normalized Gaussian kernel.

create_gaussian_kernel_input_arrayfunction

Creates a 1-D array which will create an array of x-coordinates which will be input for the gaussian function (values from -size/2 to size/2 with step size of 1) Piecewise function is needed as equivalent python list comprehension is faster than np.linspace for values of size < 100

Parameters

NameTypeDefaultDescription
sizeint-kernel size

Returns

  • np.ndarray: x-coordinate array which will be input for gaussian function that will be used for

create_motion_kernelfunction

Create a motion blur kernel.

Parameters

NameTypeDefaultDescription
kernel_sizeint-Size of the kernel (must be odd)
anglefloat-Angle in degrees (counter-clockwise)
directionfloat-Blur direction (-1.0 to 1.0)
allow_shiftedbool-Allow kernel to be randomly shifted from center
random_staterandom.Random-Python's random.Random instance

Returns

  • np.ndarray: Motion blur kernel

defocusfunction

Defocus an image. This function defocuses an image.

Parameters

NameTypeDefaultDescription
imgnp.ndarray-Input image.
radiusint-Radius.
alias_blurfloat-Alias blur.

Returns

  • np.ndarray: Defocused image.

glass_blurfunction

Glass blur an image. This function applies a glass blur to an image.

Parameters

NameTypeDefaultDescription
imgnp.ndarray-Input image.
sigmafloat-Sigma.
max_deltaint-Maximum delta.
iterationsint-Number of iterations.
dxynp.ndarray-Dxy.
mode
One of:
  • 'fast'
  • 'exact'
-Mode.

Returns

  • np.ndarray: Glass blurred image.

median_blurfunction

Median blur an image. This function applies a median blur to an image.

Parameters

NameTypeDefaultDescription
imgnp.ndarray-Input image.
ksizeint-Kernel size.

Returns

  • np.ndarray: Median blurred image.

process_blur_limitfunction

Process blur limit to ensure valid kernel sizes.

Parameters

NameTypeDefaultDescription
value
One of:
  • int
  • tuple[int, int]
--
infoValidationInfo--
min_valueint0-

sample_odd_from_rangefunction

Sample an odd number from the range [low, high] (inclusive).

Parameters

NameTypeDefaultDescription
random_staterandom.Random-instance of random.Random
lowint-lower bound (will be converted to nearest valid odd number)
highint-upper bound (will be converted to nearest valid odd number)

Returns

  • int: Randomly sampled odd number from the range

Notes

- Input values will be converted to nearest valid odd numbers: * Values less than 3 will become 3 * Even values will be rounded up to next odd number - After normalization, high must be >= low

zoom_blurfunction

Zoom blur an image. This function zooms and blurs an image.

Parameters

NameTypeDefaultDescription
imgnp.ndarray-Input image.
zoom_factors
One of:
  • np.ndarray
  • Sequence[int]
-Zoom factors.

Returns

  • np.ndarray: Zoomed and blurred image.