I need to solve the following problem:
INPUT: Image IM, Palette PA
OUTPUT: IM only with the colours of PA
The input image is in RGB but I can convert it to HSV. The colour target palette I specify contains at the moment: black, white, light gray, gray, dark gray, blue, pink, red, purple, green, yellow, brown, orange.
I searched a lot for that, but I can only find reducing an image to the most common colours or reducing it to a fixed palette like 16 colours EGA graphics.
I found the best answer of this: How do I convert any image to a 4-color paletted image using the Python Imaging Library?
It has an input palette and reduces the image to that. Is there an equal way to do in in OpenCV with C++ ?
Suppose that rgb color space is 3D cube
And Palette PA
is several points in this cube. So our problem is reduced to finding the nearest Palette PA
point for any given rgb
point in 3D space.
I think the better solution is k-d tree
At the end of wiki page you can find several links for c++ implementations
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With