Skip to main content

black_threshold_image

Signature
def black_threshold_image(
image: npt.NDArray[np.uint8],
num_thresholds: int,
) -> npt.NDArray[np.uint8]

Force near-black pixels to pure black.

A pixel is set to black when all three of its colour channels are strictly below num_thresholds; every other pixel is left untouched. Because the comparison is applied per channel, num_thresholds is a brightness cutoff, not a number of output colour levels.

Parameters​

NameTypeDescription
imagenumpy.ndarrayInput image as a uint8 numpy array.
num_thresholdsintPer-channel brightness cutoff in the 0-255 range. Pixels whose red, green and blue values are all below this value become black. Values of 0 or less leave the image unchanged.

Returns​

TypeDescription
numpy.ndarrayA copy of the image with near-black pixels darkened to pure black, as a uint8 numpy array.
note

Darkened pixels also have their alpha channel set to an opaque 255.