hsluv / hsluv

Human-friendly HSL, website and math
https://www.hsluv.org/
MIT License
1.27k stars 55 forks source link

How to measure perceptual difference between colors #76

Open Frederik-Baetens opened 4 years ago

Frederik-Baetens commented 4 years ago

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 commented 4 years ago

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 commented 3 years ago

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 commented 3 years ago

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

mina86 commented 3 years ago

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

isral commented 11 months ago

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 commented 11 months ago

@isral black and white both have chroma of 0.

mina86 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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