Skip to main content

raygeo.image.transparency

Functions

make_transparent_by_brightness()

make_transparent_by_brightness(
rgba: numpy.NDArray[numpy.uint8],
width: int,
height: int,
stride: int,
threshold: int = 250,
) -> None

Clear alpha for bright pixels in an ARGB32 buffer (in-place).

Pixels with BT.601-weighted brightness >= threshold have their alpha channel set to 0.

ParameterTypeDescription
rgbanumpy.NDArray[numpy.uint8]Flattened uint8 buffer of shape (stride * height * 4,).
widthintImage width in pixels.
heightintImage height in pixels.
strideintRow stride in pixels (may be larger than width).
thresholdint = 250Brightness threshold (0-255).
ReturnsNone
ComplexityO(w*h)

make_transparent_except_color()

make_transparent_except_color(
rgba: numpy.NDArray[numpy.uint8],
width: int,
height: int,
stride: int,
target_r: int,
target_g: int,
target_b: int,
) -> None

Clear alpha for non-matching pixels in an ARGB32 buffer (in-place).

Pixels that do not match the target RGB color have their alpha channel set to 0.

ParameterTypeDescription
rgbanumpy.NDArray[numpy.uint8]Flattened uint8 buffer of shape (stride * height * 4,).
widthintImage width in pixels.
heightintImage height in pixels.
strideintRow stride in pixels.
target_rintTarget red channel value (0-255).
target_gintTarget green channel value (0-255).
target_bintTarget blue channel value (0-255).
ReturnsNone
ComplexityO(w*h)