Similarity Between Colors

2020-02-07 02:41发布

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.

3条回答
老娘就宠你
2楼-- · 2020-02-07 03:23

Just a comment if you are going to move to HSV (or similar spaces):

  • Diffing on H: difference between 0° and 359° is numerically big but perceptually is negligible.

  • H difference if V or S are small - is small.

  • For computer vision apps, more important not perceptual difference (used mostly by paint manufacturers) but are these colors belong to the same object/segment or not. Which means that we might partially ignore V, which can change from lighting conditions.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2020-02-07 03:29

What do you mean by "posterize the image"?

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

查看更多
▲ chillily
4楼-- · 2020-02-07 03:33

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 Lab* color space) with the cutoff being around 2 or 2.3.

查看更多
登录 后发表回答