# Questions about CIE L*a*b*, requesting investigation :)

281 views

### Evan Czaplicki

May 15, 2018, 12:22:42 PM5/15/18
to elm-dev
As I mentioned on #elm-dev recently, I am working through RGB <=> Lab color conversions and I have found three different formulas that all do different things:
I would like to understand exactly why they ended up with different formulas in each case. (Theories like “I guess they did it different” are not helpful. I want to know why they use different magic constants. Where did they get them? Can we pin down exactly where they are from? Maybe there are reports that have changed in certain years?

My specific questions include:
• Why does D3 use different constants in the RGB-to-XYZ transformation matrix?
• Why does D3 use a `rgb2lrgb` conversion?
• It seems like people recommend Luv over Lab for computers. Is D3 using Lab though. Why?
• When converting to Lab (or Luv) to cylindrical coordinates, how do they get those constants? Shouldn’t they be illuminant D65, not illuminant C?
• What illuminant is D3 using? Does not seem to be D50 or D60? Why?
Very curious where the primary sources are on all this too. Would welcome links to that!

### art yerkes

May 16, 2018, 10:43:46 AM5/16/18
to elm-dev
I'm a bit of a student of color space theory (my father worked at tektronix during my childhood on color printers and display devices) also I worked in media streaming for a while and got familiar with the limitations and eccentricities of computer color spaces such as CCIR-601, the most popular YCrCb type color space and Rec 709 and their many many relatives:

Note that human perceivable color is mostly represented by what's referred to as CIE 1931* which is at present a superset of colors and shades representable by display devices, which is why much of this is inexact, up to interpretation or depends on uncontrollable environmental factors such as interior lighting or the weather, which is crudely modeled in the form of a white point coordinate.

I wasn't able to retrieve t_convert.html but I gleaned the following from the other two:

d3 uses the recommended conversion method broadly described in the CSS color TR described here https://www.w3.org/TR/css-color-4/

The specific matrix constants use appear to come from here (at least):

So it can be explained that while the CSS TR converts first to CIEXYZ at D65 white point* (Note that white point affects human color perception) then to CIEXYZ at D50 white point, then to linear rgb, the d3 code skips a step by cribbing a matrix approximation of CIEXYZ directly to linear rgb at D50.  Therefore, I believe the D3 code is using (implicitly) illuminant d65 as specified for the standard ciexyz coordinate system.

My read of the lab2xyz and xyz2lab functions in the d3 code is that they precisely mirror the function described on the CIE description on wikipedia*  Note the definitions of t2 and t3 equal 3δ² and δ³.

rgb2lrgb is converting sRGB (the gamma corrected, "standard" sRGB* color space to linear RGB space with no gamma correction).  Their exact representation appears to match the wikipedia entry.  This conversion is necessary because CIEXYZ is a linear color space and standard RGB is not.

Regarding CIELUV, I might be missing the context, but cylindrical CIELUV appears to be a simple polar conversion in the XZ CIELUV plane, and not hue corrected as in relatives of the conic HLS space.  My read is that CIELUV does not bias color coordinates by supposing perceptual overlap between primaries as the CIELAB space attempts to, making it simpler to reason about (since each primary axis is separately offset in the direction of the white point's color temperature).

Hope some of this helps and it isn't tl;dr or missing the point (or stuff you already researched).

### Mark Hamburg

May 21, 2018, 8:19:23 AM5/21/18
The D3 code references https://beta.observablehq.com/@mbostock/lab-and-rgb which pretty much walks through where all of the constants came from.

The RIT page talks about RGB without specifying which RGB which makes its conversion between RGB and XYZ meaningless. One could reverse engineer it from the matrix provided but as a reference for how to do the conversion, it isn't really telling you what is being converted. (My guess based on the reference to YIQ is that it is working with NTSC color, but that's just a guess.)

The Wikipedia page is a good rundown on L*a*b* but it assumes you know how to get to XYZ which is where all of the matrix values come in.

Mark

--
You received this message because you are subscribed to the Google Groups "elm-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elm-dev/936bd697-dd50-4d7e-8f90-6bcb5cb174d7%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

### Mark Hamburg

May 21, 2018, 8:19:26 AM5/21/18
As for reference sources, the primary sources would mostly be various CIE and ICC standards, but The Reproduction of Colour by R.W.G. Hunt provides more detail than you probably want. It's dated but covers most of the theory.

Mark