RGB ↔ CIELAB Conversion Guide
This explains the full mathematical conversion pipeline between sRGB and CIELAB (Lab) color spaces.
1. Conversion Pipeline Overview
RGB → CIELAB
- sRGB → Linear RGB
- Linear RGB → XYZ
- XYZ → CIELAB
CIELAB → RGB
- CIELAB → XYZ
- XYZ → Linear RGB
- Linear RGB → sRGB
2. sRGB to Linear RGB
sRGB values are gamma‑compressed. Convert them to linear light:
This is applied independently to (R), (G), and (B).
3. Linear RGB to XYZ
Using the sRGB color space matrix with a D65 white point:
4. XYZ to CIELAB
Normalize XYZ by the D65 reference white:
Define the nonlinear function:
Then compute Lab:
5. CIELAB to XYZ
The inverse of (f(t)):
Compute:
6. XYZ to Linear RGB
7. Linear RGB to sRGB
Clamp results to ([0,1]) and scaled by 255 before converting to 8‑bit.
8. Summary
RGB → Lab
- Remove gamma (sRGB → linear)
- Convert to XYZ
- Normalize by D65
- Apply nonlinear transform
- Produce L*, a*, b*
Lab → RGB
- Convert Lab → XYZ via inverse nonlinear transform
- XYZ → linear RGB
- Linear RGB → sRGB (gamma)
- Clamp to valid output
9. References
- CIE 1976 L*a*b* Specification
- IEC 61966‑2‑1 sRGB Standard