Stay updated
News & Insightsalbumentations.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, glass blur, defocus, and zoom effects. These functions form the foundation for the corresponding transform classes.
Members
- functionbox_blur
- functionglass_blur
- functioncreate_defocus_kernel
- functiondefocus
- functioncentral_zoom
- functionzoom_blur
- functionprocess_blur_limit
- functioncreate_motion_kernel
- functionsample_odd_from_range
- functioncreate_gaussian_kernel
- functioncreate_gaussian_kernel_1d
- functioncreate_gaussian_kernel_input_array
box_blurfunction
box_blur(
img: ImageType,
ksize: int
)Blur an image. This function applies a blur to an image. Args: img (np.ndarray): Input image. ksize (int): Kernel size. Returns: np.ndarray: Blurred image.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| img | ImageType | - | - |
| ksize | int | - | - |
glass_blurfunction
glass_blur(
img: ImageType,
sigma: float,
max_delta: int,
iterations: int,
dxy: np.ndarray,
mode: Literal['fast', 'exact']
)Glass blur an image. This function applies a glass blur to an image. Args: img (np.ndarray): Input image. sigma (float): Sigma. max_delta (int): Maximum delta. iterations (int): Number of iterations. dxy (np.ndarray): Dxy. mode (Literal["fast", "exact"]): Mode. Returns: np.ndarray: Glass blurred image.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| img | ImageType | - | - |
| sigma | float | - | - |
| max_delta | int | - | - |
| iterations | int | - | - |
| dxy | np.ndarray | - | - |
| mode | One of:
| - | - |
create_defocus_kernelfunction
create_defocus_kernel(
radius: int,
alias_blur: float
)Create a defocus (aliased disk) convolution kernel.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| radius | int | - | - |
| alias_blur | float | - | - |
defocusfunction
defocus(
img: ImageType,
radius: int,
alias_blur: float
)Defocus an image.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| img | ImageType | - | - |
| radius | int | - | - |
| alias_blur | float | - | - |
central_zoomfunction
central_zoom(
img: ImageType,
zoom_factor: int
)Central zoom an image. This function zooms an image. Args: img (np.ndarray): Input image. zoom_factor (int): Zoom factor. Returns: np.ndarray: Zoomed image.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| img | ImageType | - | - |
| zoom_factor | int | - | - |
zoom_blurfunction
zoom_blur(
img: ImageType,
zoom_factors: np.ndarray | Sequence[int]
)Zoom blur an image. This function zooms and blurs an image. Args: img (np.ndarray): Input image. zoom_factors (np.ndarray | Sequence[int]): Zoom factors. Returns: np.ndarray: Zoomed and blurred image.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| img | ImageType | - | - |
| zoom_factors | One of:
| - | - |
process_blur_limitfunction
process_blur_limit(
value: int | tuple[int, int],
info: ValidationInfo,
min_value: int = 0
)Process blur limit to ensure valid kernel sizes.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| value | One of:
| - | - |
| info | ValidationInfo | - | - |
| min_value | int | 0 | - |
create_motion_kernelfunction
create_motion_kernel(
kernel_size: int,
angle: float,
direction: float,
allow_shifted: bool,
random_state: random.Random
)Create a motion blur kernel. Args: kernel_size (int): Size of the kernel (must be odd) angle (float): Angle in degrees (counter-clockwise) direction (float): Blur direction (-1.0 to 1.0) allow_shifted (bool): Allow kernel to be randomly shifted from center random_state (random.Random): Python's random.Random instance Returns: np.ndarray: Motion blur kernel
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| kernel_size | int | - | - |
| angle | float | - | - |
| direction | float | - | - |
| allow_shifted | bool | - | - |
| random_state | random.Random | - | - |
sample_odd_from_rangefunction
sample_odd_from_range(
random_state: random.Random,
low: int,
high: int
)Sample an odd number from the range [low, high] (inclusive). Args: random_state (random.Random): instance of random.Random low (int): lower bound (will be converted to nearest valid odd number) high (int): upper bound (will be converted to nearest valid odd number) Returns: int: Randomly sampled odd number from the range Note: - 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
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| random_state | random.Random | - | - |
| low | int | - | - |
| high | int | - | - |
create_gaussian_kernelfunction
create_gaussian_kernel(
sigma: float,
ksize: int = 0
)Create a Gaussian kernel following PIL's approach. Args: sigma (float): Standard deviation for Gaussian kernel. ksize (int): Kernel 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.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| sigma | float | - | - |
| ksize | int | 0 | - |
create_gaussian_kernel_1dfunction
create_gaussian_kernel_1d(
sigma: float,
ksize: int = 0
)Create a 1D Gaussian kernel following PIL's approach. Args: sigma (float): Standard deviation for Gaussian kernel. ksize (int): Kernel 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.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| sigma | float | - | - |
| ksize | int | 0 | - |
create_gaussian_kernel_input_arrayfunction
create_gaussian_kernel_input_array(
size: int
)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 Args: size (int): kernel size Returns: np.ndarray: x-coordinate array which will be input for gaussian function that will be used for separable gaussian blur
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| size | int | - | - |