Converting sRGB to LCH when: Red Green and Blue are Equal (Bug)
See original GitHub issueWhen attempting to convert an sRGB to LCH, where the chroma should be 0, produces unexpected values in the Chroma and Hue channels. The chroma value appears to have a floating point error when it should be 0, and the hue value is always NaN, which causes math problems.
Take the following examples:
new Color('srgb', [0.1, 0.1, 0.1]).to('lch').coords
(3) [9.010443527068848, 0.000006337680094534959, NaN]
new Color('srgb', [0.13333, 0.13333, 0.13333]).to('lch').coords
(3) [13.227498037447411, 0.000007406287423610401, NaN]
new Color('srgb', [0.4, 0.4, 0.4]).to('lch').coords
(3) [43.192291386569806, 0.000014999406423138985, NaN]
Issue Analytics
- State:
- Created 2 years ago
- Comments:16 (1 by maintainers)
Top Results From Across the Web
s RGB ↔L*a*b*↔LCh ab conversions - mina86.com
Importantly, the conversion between s RGB and L*a*b* goes through XYZ colour space. As such, the full process has multiple steps with a...
Read more >LCH colors in CSS: what, why, and how? – Lea Verou
E.g. 0 is not red, but more of a magenta and 180 is not turquoise but more of a bluish green, and is...
Read more >RGB Color Space Conversion - RyanJuckett.com
Red, Green and Blue Primaries. Chromaticity coordinates are given for each primary of the display. For sRGB space, they are as follows: red...
Read more >How the L C H Values Could Be Seen as a value on an Image
I am trying to check an image file to reach its color values and I could see RGB but while trying to check...
Read more >Better than Lab? Gamut reduction CIE Lab & OKLab - W3C
sRGB blue to neutral: CIE Lab. red is higher than green. Play Play. Compare that to the same thing in CIE LCH Again ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Unless I do the first-principles spectral conversion and get different results in the first 5 figures, it will be these ones going forward.
I ran your Python program with these XYZ values, and got the same results as my JavaScript program.
So I’ve gone through the math, I now understand why color.js is so off.
The sRGB matrix that color.js uses is based off a calculated white point for D65:
This gives us
But then we use the following D65 white point any time we do chromatic adaption:
This gives us quite a bit of error.
With the following code, doing nothing tricky, I follow the algorithm calculating the XYZ conversion matrix based on this algorithm: http://www.brucelindbloom.com/index.html?Math.html.
I will output the first results based on using a consistent white point with what is used in chromatic adaption and then I’ll output the same matrix with a calculated white point.
The first results match what is used in the brucelindbloom calculator and give much better results. The second matches the matrix that is currently used.
Based on this, I am much more confident with my opinion on this. My recommendation would be to use the matrix that is consistent with the white point that is being used everywhere else or update the white point in chromatic adaption to match what is used in the matrix calculations.