views:

190

answers:

3

I'm writing a program that works with images and at some point I need to posterize the image. This means I need to bin the colors, but I'm having trouble deciding how to tell how close one color is to another.

Given a color in RGB, I can think of at least 2 ways to see how different they are:

  1. |r1 - r2| + |g1 - g2| + |b1 - b2|
  2. sqrt((r1 - r2)^2 + (g1 - g2)^2 + (b1 - b2)^2)

And if I move into HSV, I can think of other ways of doing it.

So I ask, ignoring speed, what is the best way to tell how similar two colors are? Best meaning most accurate to the human eye.

A: 

What do you mean by "posterize the image"?

If you're trying to cluster the colors into bins, you should look at cluster analysis

Alex319
Fixed you link for ya'
Unkwntech
Right, but I need to be able to tell how different colors are to be able to cluster them.
ReaperUnreal
+1  A: 

Well, if speed is not an issue, the most accurate way would be to take some sample images and apply the filter to them using various cutoff values for the distance (distance being determined by one of the equations on the Color_difference page that astander linked to, meaning you'd have to use one of those color spaces listed there with the calculations, then convert to sRGB or something [which also means that you'd need to convert the image into the other color space first if it's not in it to begin with]), and then have a large number of people examine the images to see what looks best to them, then go with the cutoff value for the images that the majority agrees looks best.

Basically, it's largely a matter of subjectiveness; in fact, it also depends on how stylized you want the images, and you might even want to add in some sort of control so that you can alter the cutoff distance on the fly.

If speed does become a bit of an issue and/or you want more simplicity, then just use your second choice for distance calculation (which is simply the CIE76 equation; just make sure to use the L*a*b* color space) with the cutoff being around 2 or 2.3.

JAB