RGB to LAB Color Space Converter
Convert colors between RGB and CIE L*a*b* color spaces with real-time preview. Calculate perceptual color distance (ÎE) between any two colors.
About
RGB triplets encode color as additive light intensities. They map poorly to human perception. Two colors separated by identical Euclidean distance in RGB space can appear drastically different to the eye, or nearly identical despite large numeric gaps. The CIE L*a*b* color space, standardized in 1976, was engineered to be perceptually uniform. A unit change in any axis corresponds to roughly the same perceived shift regardless of position in the gamut. This tool performs the full conversion pipeline: sRGB â linear RGB (inverse gamma, Îł ≈ 2.2) â CIE XYZ (D65 illuminant matrix) â L*a*b*. The reverse path is also implemented. Floating-point rounding means round-trip results may differ by ±1 in the least significant RGB digit.
Comparing colors by their RGB distance is unreliable for quality control, accessibility contrast checks, or palette design. The ÎE metric (CIE76) computes Euclidean distance in L*a*b* space, producing a single number that correlates with what a trained observer actually sees. Values below 1.0 are imperceptible to most humans. Values above 5.0 indicate clearly distinct colors. This converter assumes standard sRGB with D65 reference white (Xn = 95.047, Yn = 100.0, Zn = 108.883). Results outside the sRGB gamut are clamped to [0, 255].
Formulas
The conversion from sRGB to CIE L*a*b* proceeds in two stages. First, each sRGB channel is normalized to [0, 1] and linearized by removing the gamma companding.
The linearized channels are then multiplied by the sRGB-to-XYZ matrix (D65 illuminant) and scaled by 100.
The XYZ values are converted to L*a*b* using the CIE 1976 formulas. Define the helper function f with threshold Δ = 0.008856 and Îș = 903.3.
The perceptual color distance ÎE (CIE76) between two colors in L*a*b* space is the Euclidean distance.
Where L* = lightness (0 black, 100 white), a* = green-red axis, b* = blue-yellow axis, Xn, Yn, Zn = D65 reference white tristimulus values, Δ = 0.008856 (threshold), Îș = 903.3 (CIE constant), and CsRGB = integer channel value in [0, 255].
Reference Data
| ÎE Range | Perceptual Meaning | Typical Use Case |
|---|---|---|
| 0 - 1.0 | Imperceptible difference | Instrument-grade color matching |
| 1.0 - 2.0 | Perceptible through close observation | Print proofing, textile QC |
| 2.0 - 3.5 | Perceptible at a glance | Packaging color consistency |
| 3.5 - 5.0 | Clearly different but same hue family | General industrial tolerance |
| 5.0 - 10.0 | Different color impression | Interior design palettes |
| 10.0 - 49.0 | Colors appear unrelated | Contrast accessibility (WCAG) |
| > 49.0 | Opposite ends of gamut | Maximum visibility signage |
| CIE L*a*b* Channel Ranges | ||
| L* | 0 (black) to 100 (white) | Lightness / luminance axis |
| a* | ≈ â128 to +127 | Green (â) to Red (+) axis |
| b* | ≈ â128 to +127 | Blue (â) to Yellow (+) axis |
| D65 Reference White (XYZ) | ||
| Xn | 95.047 | Standard daylight illuminant |
| Yn | 100.000 | Perfect reflecting diffuser |
| Zn | 108.883 | Blue-weighted component |
| sRGB â XYZ Matrix (D65) | ||
| Row 1 | 0.4124564, 0.3575761, 0.1804375 | X |
| Row 2 | 0.2126729, 0.7151522, 0.0721750 | Y |
| Row 3 | 0.0193339, 0.1191920, 0.9503041 | Z |
| Common Named Colors in L*a*b* | ||
| Pure Red (255,0,0) | L*=53.23, a*=80.11, b*=67.22 | High chroma, mid lightness |
| Pure Green (0,128,0) | L*=46.23, a*=â51.70, b*=49.90 | Moderate chroma |
| Pure Blue (0,0,255) | L*=32.30, a*=79.20, b*=â107.86 | Low lightness, extreme b* |
| White (255,255,255) | L*=100, a*=0, b*=0 | Achromatic, max lightness |
| Black (0,0,0) | L*=0, a*=0, b*=0 | Achromatic, min lightness |
| Mid Gray (128,128,128) | L*≈53.59, a*≈0, b*≈0 | Achromatic, perceptual midpoint |