Applying KMeans clustering from OpenCV cannot return a Bitmap with alpha channel

the color of (or under?) an ‘alpha’ pixel is basically undefined.
(it can be anything, and a lot of artists don’t bother)

you could try to extractChannel() the alpha before the kmeans, and merge int back to your reconstructed image.

however, you’re also sampling nonsense rgb pixels for the kmeans algorithm.

all in all, it’s a bad choice of input. avoid images with alpha in for computer-vision.

1 Like