9
$\begingroup$

I have some colors in RGB in [0,1] and want to find a way to rate their similarity, as perceived by a human.

I have two ideas in mind, but I am sure there are other options as well, but am unsure which is best, or if perhaps there is no best, but only trade offs.

My first idea is to treat the RGB colors as XYZ points and calculate their distance.

Another idea I have is to treat the RGB values as a histogram and use dot product to get a similarity value between them, where a larger value is better.

I know however, that not all of the color channels have the same perceived brightness so maybe I ought to weight the color channels differently for both cases?

I'm also thinking I perhaps would need to do sRGB correction on the color values (such as, sqrt each color channel).

I also know other color spaces exist, so maybe one of those would be better at giving a similarity value.

Another challenge to this may be that different displays will display the same color values differently. Not sure if that's relevant in this case.

Anyone able to provide some help/direction?

$\endgroup$
  • 4
    $\begingroup$ Have you taken a look at this? RGB isn't a great color space for doing comparisons related to human perception. $\endgroup$ – aces Nov 28 '16 at 2:37
  • $\begingroup$ Good info thanks! I was looking at cielab but that article says that isn't the best. I'm doing work with RGB source data unfortunately so have to figure out how to convert from RGB to something better, but the challenge seems to be that RGB is device dependant, while eg cielab are not. Fortunately, a lesser approximation is good enough for my needs, if device independence isn't really feasible with RGB source data. $\endgroup$ – Alan Wolfe Nov 28 '16 at 2:48
  • $\begingroup$ Check out Bruce Lindbloom's site, especiall the various DeltaE metrics: brucelindbloom.com $\endgroup$ – David Kuri Nov 28 '16 at 12:53
  • $\begingroup$ There is a whole Python package for color science that includes some transformations: colour-science.org . $\endgroup$ – KAE Jan 17 '17 at 14:53
4
$\begingroup$

I have some colors in RGB in [0,1] and want to find a way to rate their similarity, as percieved by a human.

This is a huge subject, and loosely is found under the banner of colour appearance models. Why is it not strictly a more simple formation is due to the psychophysical nature of colour in that colour does not exist beyond the human organism.

My first idea is to treat the RGB colors as XYZ points and calculate their distance.

Another idea I have is to treat the RGB values as a histogram and use dot product to get a similarity value between them, where a larger value is better.

I know however, that not all of the color channels have the same percieved brightness so maybe i ought to weight the color channels differently for both cases?

Best advice is, much like cryptography, do not roll your own; you are likely to arrive at a sub-optimal system that will, in the best of cases, hit walls already hit by other researchers in the field. If you base your work on existing models and research, you might find it to be more accurate for your needs[1].

One could point at the historical developments around CAMs, but it is easier here to suggest that you research the IPT colour encoding model and its cylindrical equivalent that models colourfulness and hue as an angle. The evolutions in the IPT model overcome most of the issues of the earlier Lab model, and simplifies some of the work involved in CIECAM02.

Another challenge to this may be that different displays will display the same color values differently. Not sure if that's relevant in this case.

IPT, and every RGB colour space for that matter, are anchored in the 1931 CIE research. As such, these sorts of issues are solved at a lower level.

[1] This expanded answer is due to Mr. Wolfe's comment below in an attempt to explain why rolling your own solution might be a sub-optimal approach.

$\endgroup$
  • 3
    $\begingroup$ Discouraging people from experimenting in graphics and putting it on par with shipping hand crafted crypto algorithms is ridiculous. $\endgroup$ – Alan Wolfe Jan 15 '17 at 19:34
  • $\begingroup$ @AlanWolfe Given that there are quite a few extremely brilliant PhD types out there that have already spent countless hours and effort solving the problems in the original question, I find your context of ridiculous ridiculous. Not to discourage one from filling their boots and attempting to reinvent the wheel. $\endgroup$ – troy_s Jan 15 '17 at 20:51
  • $\begingroup$ You should hear the simple hacks recommended by active graphics researchers. Such as "dot product RGB, it really does work amazingly well" from Peter Shirley. $\endgroup$ – Alan Wolfe Jan 15 '17 at 20:56
  • 2
    $\begingroup$ I've moved on but there's application of wave function collapse for procedural image and content creation. It works in part by exact matching pixels so works best with pixel art. I was looking at seeing it be able to do softer matching for use with more realistic images, or for less strict procedural content rules. Check out this link for the basic thing: github.com/mxgmn/WaveFunctionCollapse $\endgroup$ – Alan Wolfe Jan 15 '17 at 23:04
  • 2
    $\begingroup$ It's not my work but I was trying to extend it. I totally agree, it's cool stuff! Off topic but here's my unrelated work hehe. blog.demofox.org/2016/02/22/… $\endgroup$ – Alan Wolfe Jan 15 '17 at 23:26
4
$\begingroup$

If complex metric is acceptable I would suggest to look at perceptual based approach described here. The metric is designed to pick perceptual difference of two images. There are two main tests for that : luminance based and color based. First one allows to answer the question how important luminance change is by estimating a non uniform threshold factor based on sensitivity to contrast changes depending on spatial frequencies of the image. The second one is based on euclidean distance in CIE LAB color space, but slightly modified to make color difference less important when luminance is in mesopic and scotopic ranges. A list of papers related to that metric can be found here.

$\endgroup$
  • 3
    $\begingroup$ Welcome to Computer Graphics SE! In general, link-only answers are strongly discouraged on SE, because they might become useless should those links ever go down. Please include a short summary of their content, so that people can still figure out what exactly you're actually suggesting without having to rely on the links. $\endgroup$ – Martin Ender Nov 28 '16 at 13:15

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.