I think you need to state your problem a little more clearly for us. Are you trying to reduce the number of colors in a color image, or are you trying to convert a color image to greyscale? Or something else?
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
This is not a trivial algorithm to implement. I'm familiar with it in general terms, and you can find some sample implementations to give you an idea of where to go.
The idea is not to segment the image, but to segment the color values found in it. Then replace the colors at each pixel with the palette color that it maps to in the color segmentations.
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
Kind of sort of. The final step would be something like that, but it's a long way to get there.
Here's my understanding of the basis of Median Cut. First find what colors exist in the image, essentially a 3D histogram. Find the plane that divides the unique color triplets in half, making two boxes with equal number of colors. Divide each of those boxes at the plane (not necessarily the same in each box) that cuts the number of colors in each of the now 4 boxes to equal numbers. Keep dividing till you have the number of boxes representing the desired number of colors in the target palette. Find the median color in each box - these will be your palette colors. Then map each color in the image to that median color in the box in which the image color exists.
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228