albumentations.augmentations.pixel.dithering_functional
Functional implementations of dithering algorithms for color depth reduction.
Members
- functionapply_dithering
- functionerror_diffusion_dither
- functionordered_dither
- functionordered_dither_uint8
- functionquantize_array
- functionquantize_value
- functionrandom_dither
- functionrandom_dither_uint8
apply_ditheringfunction
Apply dithering to an image.
Parameters
Name | Type | Default | Description |
---|---|---|---|
img | np.ndarray | - | Input image in [0, 1] range with shape (H, W, C). |
method | str | - | Dithering method to use. |
n_colors | int | - | Number of colors per channel. |
color_mode | str | per_channel | How 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
Name | Type | Default | Description |
---|---|---|---|
img | np.ndarray | - | Input image in [0, 1] range with shape (H, W, C). |
n_colors | int | - | Number of colors per channel. |
algorithm | str | floyd_steinberg | Error diffusion algorithm name. |
serpentine | bool | False | Use serpentine (back-and-forth) scanning. |
Returns
- : Dithered image in [0, 1] range.
ordered_ditherfunction
Apply ordered dithering using Bayer matrix.
Parameters
Name | Type | Default | Description |
---|---|---|---|
img | np.ndarray | - | Input image in [0, 1] range with shape (H, W, C). |
n_colors | int | - | Number of colors per channel. |
matrix_size | int | 4 | Size 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
Name | Type | Default | Description |
---|---|---|---|
img | np.ndarray | - | Input uint8 image with shape (H, W, C). |
n_colors | int | - | Number of colors per channel. |
matrix_size | int | 4 | Size 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
Name | Type | Default | Description |
---|---|---|---|
arr | np.ndarray | - | Input array in [0, 1] range. |
n_levels | int | - | Number of discrete levels. |
Returns
- : Quantized array in [0, 1] range.
quantize_valuefunction
Quantize a single value to n discrete levels.
Parameters
Name | Type | Default | Description |
---|---|---|---|
value | float | - | Input value in [0, 1] range. |
n_levels | int | - | Number of discrete levels. |
Returns
- : Quantized value in [0, 1] range.
random_ditherfunction
Apply random dithering for float32 images.
Parameters
Name | Type | Default | Description |
---|---|---|---|
img | np.ndarray | - | Input float32 image with shape (H, W, C) in [0, 1] range. |
n_colors | int | - | Number of colors per channel after quantization. |
noise_range | tuple[float, float] | - | Range of noise to add (min_noise, max_noise). |
random_generator | np.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
Name | Type | Default | Description |
---|---|---|---|
img | np.ndarray | - | Input uint8 image with shape (H, W, C) in [0, 255] range. |
n_colors | int | - | Number of colors per channel after quantization. |
noise_range | tuple[float, float] | - | Range of noise to add (min_noise, max_noise) in [0, 1] range. |
random_generator | np.random.Generator | - | Random number generator for reproducible results. |
Returns
- : Dithered uint8 image in [0, 255] range.