hi i have an image which i can get RGB values, i have to quantitize it , a new to this i think i know the principle but need a few pointers as to how to go about "mapping" the image to a range of colours. basically i am doing a grey scale whic works but on colours not black thru to white it is greying only slightly. so i need to reduce the colour values.
hope someone can help.



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?

hi sorry about late reply, am trying to reduce the colours. i have whittled it down to performing something called a median cut. but unsure as to how to start . ie i need to first section the whole image and then break down the image into clusters of fewer colours. i think i know the principle but unsure of how to section etc..hope this helps explain. basically it works but colours are to many. thnx

the source image is a fixed palet of eight squares of different colours red, yellow, green orange etc, the code works fine on the black thru to grey and white , but not on the colours.

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.

commented: You are always patient and very helpful to people! =) +4

ok..do you mean something like the following.

if RGB values fall into a certain value range.
then make them a pre-defined values.

ie red is R=255, G=0, B=0. so if a pixel in the image has same values +or - a tolerance such as 20, then make that pixel same as red.

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.