Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Distance measure between HSL colours

Tags:

colors

I am coding a program that allows a user to choose various foreground and background colours in RGB. I want to not allow them to chose foreground and backgrounds that are too similar and decided to convert to HSL and use HSL euclidean distance as a way to check for similarity.

Is there a good weighting to use for HSL space (rather than equal weighting for H, S and L)? I've looked at various sites and not found the exact thing I need; just things saying that HSL or HSB is better than RGB.

like image 532
Sammo Avatar asked Dec 29 '22 10:12

Sammo


2 Answers

first convert the colors to Lab. This colorspace is designed so that the vectorial difference between any two colors closely approximate a 'subjective distance'.

In color management, a 'delta E' value is given as a measure of how perceptually faithful a given color transformation is. it's just the magnitude of the vector difference between original and final colors as expressed in Lab space.

like image 175
Javier Avatar answered Jan 12 '23 00:01

Javier


My advice would be to skip HSL/HSB entirely, and go directly from RGB to LAB. Once you've done that, you can do a standard delta E computation.

like image 29
Jerry Coffin Avatar answered Jan 11 '23 23:01

Jerry Coffin