How to Convert CIELAB to RGB
Converting CIELAB (Lab) to RGB bridges the gap between theoretical color science and practical digital display technology. Lab models human vision, while RGB dictates hardware light output.
Understanding the Lab Axes
The Lab color space uses three axes to define a color:
- L (Lightness): Ranges from 0 (black) to 100 (white).
- a (Green-Red): Negative values indicate green, positive values indicate red.
- b (Blue-Yellow): Negative values indicate blue, positive values indicate yellow.
The Math Behind the Conversion
To convert Lab to RGB, the color must first be translated into the CIE XYZ color space. This involves reversing the non-linear cube-root function used to create Lab. Once in XYZ space, a matrix multiplication converts the coordinates into linear RGB values.
Finally, the sRGB gamma correction curve is applied to the linear values, and the results are scaled to the standard 0-255 range used in CSS.
Handling Out-of-Gamut Colors
Because Lab can describe colors that exist in the real world but cannot be reproduced by standard monitors, the resulting RGB values may fall below 0 or above 255. In standard CSS, these out-of-bounds values are clamped to the nearest displayable color, which reduces the saturation of the original Lab value.