|
|
|
|
|
by jcranmer
3388 days ago
|
|
> RGB and HSL are related, but I wouldn't say HSL is based on RGB. HSL is explicitly defined as a transformation from RGB space, so each RGB triangle has a corresponding HSL space. RGB is absolute garbage for doing anything other than displaying pixels. It's so bad, that the (piecewise) linear transformation to HSL is perceived by many to be good, when it's still equally terrible. The main problem is that not all wavelengths of light contribute equally to perceived brightness in our color vision. Any color space that puts red, green, and blue on equal footing for a transformation is going to produce bad results. If you really want a linear transformation from RGB, you'll want to use something like luma instead (Y = .21R + .72G + .07B, according to Wikipedia)--you'll go from bad to acceptable, as luma is only a few percent off from the accurate results. If you want to do color interpolation, you'll absolutely want to use CIELAB, which was explicitly designed for this purpose. Any good toolkit should provide CIELAB--d3 does, for example. If not, it's not hard to find snippets to do the conversion for you on places like stack overflow. |
|
To get a reasonably accurate correlate of lightness perception, you need to take your linear combination in a linear RGB space to get luminance (Y), and then afterward apply a non-linear correction to find lightness.