Skip to main content

raygeo.image.dither

Functions

apply_bayer_dither()

apply_bayer_dither(
grayscale: numpy.NDArray[numpy.uint8],
bayer_matrix: numpy.NDArray[numpy.float32],
invert: bool,
cell_size: int = 1,
) -> numpy.NDArray[numpy.uint8]

Apply ordered (Bayer) dithering using a threshold matrix.

ParameterTypeDescription
grayscalenumpy.NDArray[numpy.uint8]2D grayscale image as uint8 array.
bayer_matrixnumpy.NDArray[numpy.float32]2D Bayer threshold matrix as float32.
invertboolIf True, invert the output.
cell_sizeint = 1Pixel grouping size for the threshold.
Returnsnumpy.NDArray[numpy.uint8]2D binary uint8 array (values 0 or 1).
ComplexityO(w*h)

Bayer 4x4 ordered dithering

Bayer 4x4 ordered dithering

apply_floyd_steinberg_dither()

apply_floyd_steinberg_dither(
grayscale: numpy.NDArray[numpy.uint8],
invert: bool,
) -> numpy.NDArray[numpy.uint8]

Apply Floyd-Steinberg error-diffusion dithering.

ParameterTypeDescription
grayscalenumpy.NDArray[numpy.uint8]2D grayscale image as uint8 array.
invertboolIf True, invert the output (swap black/white).
Returnsnumpy.NDArray[numpy.uint8]2D binary uint8 array (values 0 or 1).
ComplexityO(w*h)

Floyd-Steinberg dithering

Floyd-Steinberg dithering

apply_minimum_run_length()

apply_minimum_run_length(
binary: numpy.NDArray[numpy.uint8],
min_run_length: int,
) -> numpy.NDArray[numpy.uint8]

Remove binary runs shorter than the given minimum.

ParameterTypeDescription
binarynumpy.NDArray[numpy.uint8]2D binary uint8 array (values 0 or 1).
min_run_lengthintMinimum run length to keep.
Returnsnumpy.NDArray[numpy.uint8]2D binary uint8 array with short runs removed.
ComplexityO(w*h)

Minimum run length applied to binary image

Minimum run length applied to binary image