Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to measure perceptual difference between colors #76

Open
Frederik-Baetens opened this issue Aug 15, 2020 · 9 comments
Open

How to measure perceptual difference between colors #76

Frederik-Baetens opened this issue Aug 15, 2020 · 9 comments

Comments

@Frederik-Baetens
Copy link

How do I find the most similar color to a certain color in a set of colors? Is euclidean distance a decent way to do this? e.g. sqrt((ΔH)**2+(ΔS)**2+(ΔL)**2)

If not, would euclidean distance be decent when looking for the closest color within a certain Hue? e.g. sqrt((ΔS)**2+(ΔL)**2)

@boronine
Copy link
Member

I'm not sure that there is a precise answer, best bet would be to experiment and see how you like the results. Feel free to post your findings here.

@makew0rld
Copy link

Original image

peppers

Palette: red, green, yellow, black

Random noise added, using color distance in CIELAB for palette matching:

random_noise_rgb_red-green-yellow-black

Same operation, but using distance in HSLuv for palette matching:

random_noise_rgb_red-green-yellow-black

It appears that HSLuv is not very good for color distance. Maybe this is because the Hue value is weighted 3.6 times more than luminance or saturation? I tried scaling hue so it would be [0..100], but that looked even worse.

@boronine
Copy link
Member

Euclidean distance HSLuv is bad for this purpose, for two reasons:

  • It uses polar coordinates for H and S
  • It distorts chroma by turning it into saturation %

@mina86
Copy link

mina86 commented Mar 8, 2021

https://en.wikipedia.org/wiki/Color_difference#CIEDE2000

@isral
Copy link

isral commented Sep 20, 2023

Euclidean distance HSLuv is bad for this purpose, for two reasons:

* It uses polar coordinates for H and S

* It distorts chroma by turning it into saturation %

I played with your C# code using LUV, and convert UV to chroma and hue using trigonometry.
I found that the greatest chroma is 177 (L53 C177 H12) -> red.
And the opposite color has a chroma of 41 (L53 C41 H192) -> dark cyan.
The distance from red to dark cyan (177+41) is greater than black to white (100).
This doesn't make sense, I think black to white should be the farthest.

@boronine
Copy link
Member

@isral black and white both have chroma of 0.

@mina86
Copy link

mina86 commented Sep 20, 2023

and convert UV to chroma and hue using trigonometry.

Yeah, don’t do that. If you insist on not using CIE DE2000 use Euclidean distance in LAB or LUV space.

@isral
Copy link

isral commented Sep 20, 2023

TLDR: check last 3 lines.

@isral black and white both have chroma of 0.

Both chroma is 0, so the only difference is ΔL which is 100.

and convert UV to chroma and hue using trigonometry.

Yeah, don’t do that. If you insist on not using CIE DE2000 use Euclidean distance in LAB or LUV space.

I use LUV, note: all number rounded.
Red #FD0308 L53 U173 V37
Dark cyan #108D8D L53 U-40 V-9
Euclidean distance = √((53-53)² + (173+40)² + (37+9)²) = 218
Same with my previous post 177+41 = 218

Maybe euclidean distance can't be used here or both UV must be scaled down or I miss something else.
Sorry, I don't try CIE DE2000 because I confused when see complicated math.


Edit: I found online CIE DE2000 calculator (http://colormine.org/delta-e-calculator/cie2000) and the result is 75.872.
Black to white is 100.
Sadly the only source code I can found (CieDe2000Comparison.cs) is broken on green magenta comparison.

@boronine
Copy link
Member

Both chroma is 0, so the only difference is ΔL which is 100.

Ah okay, I misunderstood you.

You seem to be calculating Euclidean distance correctly [1], so the bad results you're getting must be the limitation of the Euclidean color distance method.

[1] https://en.wikipedia.org/wiki/CIELUV#Color_and_hue_difference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants