A comprehensive guide to the CIE LAB color space - a perceptually uniform color space that represents colors in terms of lightness (L*) and opponent color dimensions (a* and b*), widely used in color management, quality control, and accurate color conversions.
The CIE LAB color space, also known as CIELAB or L*a*b*, is a perceptually uniform color space developed by the International Commission on Illumination (CIE) in 1976. It represents colors using three coordinates: L* (lightness), a* (green-red opponent dimension), and b* (blue-yellow opponent dimension). This color space is designed so that equal distances correspond to equal perceived color differences, making it invaluable for color management, quality control, and precise color conversions.
The LAB color space separates color information into perceptually meaningful components that align with human vision processing:
// Comprehensive CIE LAB color space implementation
class CIELABColorSpace {
constructor() {
// Standard illuminants for LAB conversions
this.illuminants = {
'D50': { X: 96.422, Y: 100.000, Z: 82.521 },
'D65': { X: 95.047, Y: 100.000, Z: 108.883 },
'A': { X: 109.850, Y: 100.000, Z: 35.585 },
'C': { X: 98.074, Y: 100.000, Z: 118.232 },
'E': { X: 100.000, Y: 100.000, Z: 100.000 }
};
// LAB color space characteristics
this.characteristics = {
lightness: { min: 0, max: 100, description: 'L* - Lightness from black to white' },
aAxis: { min: -128, max: 127, description: 'a* - Green (negative) to Red (positive)' },
bAxis: { min: -128, max: 127, description: 'b* - Blue (negative) to Yellow (positive)' },
perceptualUniformity: true,
deviceIndependent: true
};
// Common LAB color ranges for different applications
this.applicationRanges = {
'printing': { L: [0, 95], a: [-90, 90], b: [-90, 90] },
'display': { L: [0, 100], a: [-128, 127], b: [-128, 127] },
'textiles': { L: [10, 90], a: [-60, 60], b: [-60, 60] },
'photography': { L: [0, 100], a: [-128, 127], b: [-128, 127] }
};
}
// Convert XYZ to LAB
xyzToLab(X, Y, Z, illuminant = 'D65') {
const wp = this.illuminants[illuminant];
if (!wp) {
throw new Error(`Unknown illuminant: ${illuminant}`);
}
// Normalize by white point
const xn = X / wp.X;
const yn = Y / wp.Y;
const zn = Z / wp.Z;
// Apply LAB transformation function
const fx = this.labFunction(xn);
const fy = this.labFunction(yn);
const fz = this.labFunction(zn);
// Calculate LAB coordinates
const L = 116 * fy - 16;
const a = 500 * (fx - fy);
const b = 200 * (fy - fz);
return {
L: Math.max(0, Math.min(100, L)),
a: Math.max(-128, Math.min(127, a)),
b: Math.max(-128, Math.min(127, b)),
illuminant
};
}
// Convert LAB to XYZ
labToXyz(L, a, b, illuminant = 'D65') {
const wp = this.illuminants[illuminant];
if (!wp) {
throw new Error(`Unknown illuminant: ${illuminant}`);
}
// Calculate intermediate values
const fy = (L + 16) / 116;
const fx = a / 500 + fy;
const fz = fy - b / 200;
// Apply inverse LAB transformation
const xn = this.invLabFunction(fx);
const yn = this.invLabFunction(fy);
const zn = this.invLabFunction(fz);
// Scale by white point
const X = xn * wp.X;
const Y = yn * wp.Y;
const Z = zn * wp.Z;
return { X, Y, Z, illuminant };
}
// LAB transformation function
labFunction(t) {
const delta = 6 / 29;
const deltaSquared = delta * delta;
const deltaCubed = delta * delta * delta;
if (t > deltaCubed) {
return Math.pow(t, 1/3);
} else {
return (t / (3 * deltaSquared)) + (4 / 29);
}
}
// Inverse LAB transformation function
invLabFunction(t) {
const delta = 6 / 29;
const deltaSquared = delta * delta;
if (t > delta) {
return Math.pow(t, 3);
} else {
return 3 * deltaSquared * (t - 4/29);
}
}
// Convert RGB to LAB
rgbToLab(r, g, b, illuminant = 'D65') {
// First convert RGB to XYZ
const xyz = this.rgbToXyz(r, g, b);
// Then convert XYZ to LAB
return this.xyzToLab(xyz.X, xyz.Y, xyz.Z, illuminant);
}
// Convert LAB to RGB
labToRgb(L, a, b, illuminant = 'D65') {
// First convert LAB to XYZ
const xyz = this.labToXyz(L, a, b, illuminant);
// Then convert XYZ to RGB
return this.xyzToRgb(xyz.X, xyz.Y, xyz.Z);
}
// RGB to XYZ conversion (sRGB)
rgbToXyz(r, g, b) {
// Normalize RGB values
let rNorm = r / 255;
let gNorm = g / 255;
let bNorm = b / 255;
// Apply gamma correction (sRGB)
rNorm = this.srgbToLinear(rNorm);
gNorm = this.srgbToLinear(gNorm);
bNorm = this.srgbToLinear(bNorm);
// Convert to XYZ using sRGB matrix
const X = rNorm * 0.4124564 + gNorm * 0.3575761 + bNorm * 0.1804375;
const Y = rNorm * 0.2126729 + gNorm * 0.7151522 + bNorm * 0.0721750;
const Z = rNorm * 0.0193339 + gNorm * 0.1191920 + bNorm * 0.9503041;
return {
X: X * 100,
Y: Y * 100,
Z: Z * 100
};
}
// XYZ to RGB conversion (sRGB)
xyzToRgb(X, Y, Z) {
// Normalize XYZ values
const xNorm = X / 100;
const yNorm = Y / 100;
const zNorm = Z / 100;
// Convert to linear RGB using inverse sRGB matrix
let rLin = xNorm * 3.2404542 + yNorm * -1.5371385 + zNorm * -0.4985314;
let gLin = xNorm * -0.9692660 + yNorm * 1.8760108 + zNorm * 0.0415560;
let bLin = xNorm * 0.0556434 + yNorm * -0.2040259 + zNorm * 1.0572252;
// Apply gamma correction
rLin = this.linearToSrgb(rLin);
gLin = this.linearToSrgb(gLin);
bLin = this.linearToSrgb(bLin);
// Convert to 8-bit RGB
return {
r: Math.max(0, Math.min(255, Math.round(rLin * 255))),
g: Math.max(0, Math.min(255, Math.round(gLin * 255))),
b: Math.max(0, Math.min(255, Math.round(bLin * 255)))
};
}
// sRGB gamma correction
srgbToLinear(value) {
if (value <= 0.04045) {
return value / 12.92;
} else {
return Math.pow((value + 0.055) / 1.055, 2.4);
}
}
// Inverse sRGB gamma correction
linearToSrgb(value) {
if (value <= 0.0031308) {
return value * 12.92;
} else {
return 1.055 * Math.pow(value, 1/2.4) - 0.055;
}
}
// Calculate Delta E color difference in LAB space
calculateDeltaE(lab1, lab2, formula = 'CIE2000') {
const deltaL = lab2.L - lab1.L;
const deltaA = lab2.a - lab1.a;
const deltaB = lab2.b - lab1.b;
switch (formula) {
case 'CIE76':
return Math.sqrt(deltaL * deltaL + deltaA * deltaA + deltaB * deltaB);
case 'CIE94':
return this.deltaE94(lab1, lab2);
case 'CIE2000':
return this.deltaE2000(lab1, lab2);
default:
return Math.sqrt(deltaL * deltaL + deltaA * deltaA + deltaB * deltaB);
}
}
deltaE94(lab1, lab2, textiles = false) {
const kL = textiles ? 2 : 1;
const kC = 1;
const kH = 1;
const k1 = textiles ? 0.048 : 0.045;
const k2 = textiles ? 0.014 : 0.015;
const deltaL = lab1.L - lab2.L;
const deltaA = lab1.a - lab2.a;
const deltaB = lab1.b - lab2.b;
const c1 = Math.sqrt(lab1.a * lab1.a + lab1.b * lab1.b);
const c2 = Math.sqrt(lab2.a * lab2.a + lab2.b * lab2.b);
const deltaC = c1 - c2;
const deltaH = Math.sqrt(deltaA * deltaA + deltaB * deltaB - deltaC * deltaC);
const sL = 1;
const sC = 1 + k1 * c1;
const sH = 1 + k2 * c1;
const term1 = deltaL / (kL * sL);
const term2 = deltaC / (kC * sC);
const term3 = deltaH / (kH * sH);
return Math.sqrt(term1 * term1 + term2 * term2 + term3 * term3);
}
deltaE2000(lab1, lab2) {
// Simplified CIE Delta E 2000 calculation
const avgL = (lab1.L + lab2.L) / 2;
const c1 = Math.sqrt(lab1.a * lab1.a + lab1.b * lab1.b);
const c2 = Math.sqrt(lab2.a * lab2.a + lab2.b * lab2.b);
const avgC = (c1 + c2) / 2;
const g = 0.5 * (1 - Math.sqrt(Math.pow(avgC, 7) / (Math.pow(avgC, 7) + Math.pow(25, 7))));
const a1Prime = (1 + g) * lab1.a;
const a2Prime = (1 + g) * lab2.a;
const c1Prime = Math.sqrt(a1Prime * a1Prime + lab1.b * lab1.b);
const c2Prime = Math.sqrt(a2Prime * a2Prime + lab2.b * lab2.b);
const deltaL = lab2.L - lab1.L;
const deltaC = c2Prime - c1Prime;
// Simplified calculation (full formula is more complex)
return Math.sqrt(deltaL * deltaL + deltaC * deltaC + Math.pow(lab1.b - lab2.b, 2));
}
// Analyze LAB color properties
analyzeLABColor(L, a, b) {
const chroma = Math.sqrt(a * a + b * b);
const hue = Math.atan2(b, a) * 180 / Math.PI;
const normalizedHue = hue < 0 ? hue + 360 : hue;
return {
lightness: {
value: L,
description: this.describeLightness(L),
category: this.categorizeLightness(L)
},
chroma: {
value: chroma,
description: this.describeChroma(chroma),
category: this.categorizeChroma(chroma)
},
hue: {
value: normalizedHue,
description: this.describeHue(normalizedHue),
quadrant: this.getHueQuadrant(normalizedHue)
},
colorfulness: this.assessColorfulness(L, chroma),
warmth: this.assessWarmth(a, b)
};
}
describeLightness(L) {
if (L < 10) return 'Very dark';
if (L < 25) return 'Dark';
if (L < 50) return 'Medium dark';
if (L < 75) return 'Medium light';
if (L < 90) return 'Light';
return 'Very light';
}
categorizeLightness(L) {
if (L < 20) return 'shadow';
if (L < 40) return 'dark';
if (L < 60) return 'medium';
if (L < 80) return 'light';
return 'highlight';
}
describeChroma(chroma) {
if (chroma < 5) return 'Very low saturation (nearly neutral)';
if (chroma < 15) return 'Low saturation';
if (chroma < 30) return 'Medium saturation';
if (chroma < 50) return 'High saturation';
return 'Very high saturation';
}
categorizeChroma(chroma) {
if (chroma < 10) return 'neutral';
if (chroma < 25) return 'muted';
if (chroma < 45) return 'moderate';
return 'vivid';
}
describeHue(hue) {
if (hue >= 345 || hue < 15) return 'Red';
if (hue < 45) return 'Red-Orange';
if (hue < 75) return 'Orange-Yellow';
if (hue < 105) return 'Yellow-Green';
if (hue < 135) return 'Green';
if (hue < 165) return 'Green-Cyan';
if (hue < 195) return 'Cyan-Blue';
if (hue < 225) return 'Blue';
if (hue < 255) return 'Blue-Magenta';
if (hue < 285) return 'Magenta';
if (hue < 315) return 'Magenta-Red';
return 'Red';
}
getHueQuadrant(hue) {
if (hue >= 0 && hue < 90) return 'I (Red-Yellow)';
if (hue >= 90 && hue < 180) return 'II (Yellow-Green)';
if (hue >= 180 && hue < 270) return 'III (Green-Blue)';
return 'IV (Blue-Red)';
}
assessColorfulness(L, chroma) {
// Colorfulness depends on both chroma and lightness
const lightnessWeight = Math.sin((L / 100) * Math.PI); // Peak at L=50
const colorfulness = chroma * lightnessWeight;
if (colorfulness < 5) return 'Low colorfulness';
if (colorfulness < 15) return 'Medium colorfulness';
if (colorfulness < 30) return 'High colorfulness';
return 'Very high colorfulness';
}
assessWarmth(a, b) {
const warmthIndex = a * 0.6 + b * 0.4; // Weight red-green more than blue-yellow
if (warmthIndex > 10) return 'Warm';
if (warmthIndex < -10) return 'Cool';
return 'Neutral';
}
// Generate LAB color palette
generateLABPalette(baseColor, options = {}) {
const {
type = 'analogous',
count = 5,
lightnessVariation = 10,
chromaVariation = 15
} = options;
const palette = [baseColor];
const { L, a, b } = baseColor;
const baseChroma = Math.sqrt(a * a + b * b);
const baseHue = Math.atan2(b, a) * 180 / Math.PI;
switch (type) {
case 'analogous':
for (let i = 1; i < count; i++) {
const hueShift = (i * 30) - (count * 15); // ±15° per step
const newHue = (baseHue + hueShift) * Math.PI / 180;
const newA = baseChroma * Math.cos(newHue);
const newB = baseChroma * Math.sin(newHue);
palette.push({
L: Math.max(0, Math.min(100, L + (Math.random() - 0.5) * lightnessVariation)),
a: newA,
b: newB
});
}
break;
case 'monochromatic':
for (let i = 1; i < count; i++) {
const lightnessStep = (100 / (count + 1)) * i;
const chromaFactor = Math.sin((lightnessStep / 100) * Math.PI); // Reduce chroma at extremes
palette.push({
L: lightnessStep,
a: a * chromaFactor,
b: b * chromaFactor
});
}
break;
case 'complementary':
const compHue = (baseHue + 180) * Math.PI / 180;
palette.push({
L,
a: baseChroma * Math.cos(compHue),
b: baseChroma * Math.sin(compHue)
});
break;
}
return palette;
}
// LAB color space gamut analysis
analyzeGamut(colorList, targetGamut = 'sRGB') {
const analysis = {
totalColors: colorList.length,
inGamut: 0,
outOfGamut: 0,
gamutUtilization: 0,
extremeColors: {
lightestL: -Infinity,
darkestL: Infinity,
maxChroma: 0,
minChroma: Infinity
}
};
colorList.forEach(lab => {
const rgb = this.labToRgb(lab.L, lab.a, lab.b);
const inGamut = this.isInGamut(rgb, targetGamut);
if (inGamut) {
analysis.inGamut++;
} else {
analysis.outOfGamut++;
}
// Track extremes
const chroma = Math.sqrt(lab.a * lab.a + lab.b * lab.b);
analysis.extremeColors.lightestL = Math.max(analysis.extremeColors.lightestL, lab.L);
analysis.extremeColors.darkestL = Math.min(analysis.extremeColors.darkestL, lab.L);
analysis.extremeColors.maxChroma = Math.max(analysis.extremeColors.maxChroma, chroma);
analysis.extremeColors.minChroma = Math.min(analysis.extremeColors.minChroma, chroma);
});
analysis.gamutUtilization = analysis.inGamut / analysis.totalColors;
return analysis;
}
isInGamut(rgb, gamut) {
// Check if RGB values are within valid range
return rgb.r >= 0 && rgb.r <= 255 &&
rgb.g >= 0 && rgb.g <= 255 &&
rgb.b >= 0 && rgb.b <= 255;
}
}The LAB color space is designed to be perceptually uniform, meaning that equal distances in the color space correspond to equal perceived color differences. This makes it ideal for color quality control and color difference calculations.
LAB is a device-independent color space, meaning colors are defined absolutely rather than relative to a specific device's capabilities. This makes it perfect for color management workflows where colors need to be accurately reproduced across different devices.
LAB is extensively used in manufacturing and printing for color quality control. Delta E calculations in LAB space provide meaningful measurements of color differences that correlate well with human perception.
Professional color correction often uses LAB mode because it allows independent adjustment of lightness and color information, providing precise control over color appearance.
LAB serves as an intermediate color space for converting between different device color spaces, ensuring accurate color matching across different devices and media.
Explore these comprehensive pillar articles related to CIE LAB Color Space
A comprehensive guide to color theory, its fundamental principles, and practical applications in digital design and web development.
Comprehensive guide to complementary colors - opposing hues on the color wheel that create maximum visual contrast, dynamic tension, and powerful design impact through scientific color relationships and perceptual phenomena.
Comprehensive guide to analogous color schemes - adjacent hues on the color wheel that create natural harmony, visual cohesion, and sophisticated design solutions through subtle color relationships and graduated transitions.
Comprehensive guide to triadic color schemes - three colors evenly spaced around the color wheel that create balanced, vibrant, and dynamic visual compositions with mathematical precision and artistic appeal.
Discover more about CIE LAB Color Space and related color theory concepts
A comprehensive guide to color theory, its fundamental principles, and practical applications in digital design and web development.
Comprehensive guide to analogous color schemes - adjacent hues on the color wheel that create natural harmony, visual cohesion, and sophisticated design solutions through subtle color relationships and graduated transitions.
Comprehensive guide to complementary colors - opposing hues on the color wheel that create maximum visual contrast, dynamic tension, and powerful design impact through scientific color relationships and perceptual phenomena.
A comprehensive guide to monochromatic color schemes - sophisticated single-hue harmonies that create unified visual experiences through systematic variations in saturation, lightness, and tonal relationships, essential for elegant design compositions, brand consistency, and advanced color theory applications requiring cohesive aesthetic unity.
A comprehensive guide to split-complementary color schemes - sophisticated three-color harmonies that combine a base color with two colors adjacent to its complement, creating balanced visual contrast with reduced tension compared to direct complementary pairs, essential for refined design compositions, brand identity systems, and advanced color theory applications.
A comprehensive guide to tetradic color schemes - sophisticated four-color harmonies that use two complementary pairs arranged in rectangular or square formations on the color wheel, providing maximum color variety while maintaining structured relationships essential for dynamic design compositions, brand systems, and advanced color theory applications.
Discover more color terminology and concepts in our comprehensive glossary.
Browse Full Glossary