Similarity between colors

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

Given the color in RGB, I can imagine at least two ways to see how different they are:

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

And if I switch to HSV, I might think of other ways of doing this.

So, I ask, ignoring speed, what is the best way to say how the two colors look alike? The best value, the most accurate for the human eye.

+4
source share
4 answers

Well, if speed is not a problem, the most accurate way would be to take some sample images and apply a filter to them using different cutoff values ​​for the distance (the distance is determined by one of the equations on the Color_difference page, which you will need to use one of those color spaces that are listed there with calculations, and then convert to sRGB or something [which also means that you will need to first convert the image to a different color space if it is not in To begin with]), and then a large number of people explore the image to see what it is best suited, then go to the cutoff value for images that most agree with the best results.

Basically, this is largely a matter of subjectivity; In fact, it also depends on how stylized your images are, and you might even want to add some kind of control so you can change the clipping distance on the fly.

If speed becomes a bit of a problem and / or you need more simplicity, just use your second choice to calculate the distance (this is just the CIE76 equation, just make sure you use the Lab * color space) with cropping is around 2 or 2.3.

+1
source

What do you mean by "posterize the image"?

If you are trying to group colors into baskets, you should look at cluster analysis

0
source

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

  • Differential on H: the difference between 0 Β° and 359 Β° is numerically large, but not perceptible.

  • The difference H, if V or S is small, is small.

  • For computer vision applications, it’s more important not to perceive the differences (mainly used by paint manufacturers), but these colors refer to the same object / segment or not. This means that we can partially ignore V, which may change due to lighting conditions.

0
source

All Articles