Stay updated

News & Insights
transform
utils
transforms
API Documentation | Albumentations

albumentations.augmentations.pixel.dithering_functional


Functional implementations of dithering algorithms for color depth reduction.

apply_ditheringfunction

Apply dithering to an image.

Parameters

NameTypeDefaultDescription
imgnp.ndarray-Input image in [0, 1] range with shape (H, W, C).
methodstr-Dithering method to use.
n_colorsint-Number of colors per channel.
color_modestrper_channelHow to handle colors ("grayscale", "per_channel", "rgb").

Returns

  • : Dithered image in [0, 1] range with shape (H, W, C).

error_diffusion_ditherfunction

Apply error diffusion dithering.

Parameters

NameTypeDefaultDescription
imgnp.ndarray-Input image in [0, 1] range with shape (H, W, C).
n_colorsint-Number of colors per channel.
algorithmstrfloyd_steinbergError diffusion algorithm name.
serpentineboolFalseUse serpentine (back-and-forth) scanning.

Returns

  • : Dithered image in [0, 1] range.

ordered_ditherfunction

Apply ordered dithering using Bayer matrix.

Parameters

NameTypeDefaultDescription
imgnp.ndarray-Input image in [0, 1] range with shape (H, W, C).
n_colorsint-Number of colors per channel.
matrix_sizeint4Size of Bayer matrix (2, 4, 8, or 16).

Returns

  • : Dithered image in [0, 1] range.

ordered_dither_uint8function

Apply ordered dithering optimized for uint8 images.

Parameters

NameTypeDefaultDescription
imgnp.ndarray-Input uint8 image with shape (H, W, C).
n_colorsint-Number of colors per channel.
matrix_sizeint4Size of Bayer matrix (2, 4, 8, or 16).

Returns

  • : Dithered uint8 image.

quantize_arrayfunction

Quantize an array to n discrete levels efficiently using vectorized operations.

Parameters

NameTypeDefaultDescription
arrnp.ndarray-Input array in [0, 1] range.
n_levelsint-Number of discrete levels.

Returns

  • : Quantized array in [0, 1] range.

quantize_valuefunction

Quantize a single value to n discrete levels.

Parameters

NameTypeDefaultDescription
valuefloat-Input value in [0, 1] range.
n_levelsint-Number of discrete levels.

Returns

  • : Quantized value in [0, 1] range.

random_ditherfunction

Apply random dithering for float32 images.

Parameters

NameTypeDefaultDescription
imgnp.ndarray-Input float32 image with shape (H, W, C) in [0, 1] range.
n_colorsint-Number of colors per channel after quantization.
noise_rangetuple[float, float]-Range of noise to add (min_noise, max_noise).
random_generatornp.random.Generator-Random number generator for reproducible results.

Returns

  • : Dithered float32 image in [0, 1] range.

random_dither_uint8function

Apply random dithering optimized for uint8 images.

Parameters

NameTypeDefaultDescription
imgnp.ndarray-Input uint8 image with shape (H, W, C) in [0, 255] range.
n_colorsint-Number of colors per channel after quantization.
noise_rangetuple[float, float]-Range of noise to add (min_noise, max_noise) in [0, 1] range.
random_generatornp.random.Generator-Random number generator for reproducible results.

Returns

  • : Dithered uint8 image in [0, 255] range.