A comprehensive guide to Delta E - the standard metric for measuring perceptual color differences in CIE color spaces, essential for color accuracy assessment, quality control, and color matching in digital imaging and printing.
Delta E (ΔE) is a metric for understanding how the human eye perceives color difference. It represents the distance between two colors in a perceptually uniform color space, typically CIE LAB or CIE LUV. Delta E values help quantify whether color differences are noticeable to the human eye, making it essential for color matching, quality control, and display calibration.
// Delta E calculation system
class DeltaECalculator {
constructor() {
this.illuminants = {
D65: { x: 95.047, y: 100.000, z: 108.883 },
D50: { x: 96.422, y: 100.000, z: 82.521 },
A: { x: 109.850, y: 100.000, z: 35.585 }
};
}
// Calculate Delta E CIE76 (original formula)
deltaE76(lab1, lab2) {
const deltaL = lab1.l - lab2.l;
const deltaA = lab1.a - lab2.a;
const deltaB = lab1.b - lab2.b;
return Math.sqrt(deltaL * deltaL + deltaA * deltaA + deltaB * deltaB);
}
// Calculate Delta E CIE94 (improved formula)
deltaE94(lab1, lab2, application = 'graphic') {
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(
Math.max(0, deltaA * deltaA + deltaB * deltaB - deltaC * deltaC)
);
// Application-specific weighting factors
const weights = application === 'textiles' ?
{ kL: 2, kC: 1, kH: 1, k1: 0.048, k2: 0.014 } :
{ kL: 1, kC: 1, kH: 1, k1: 0.045, k2: 0.015 };
const sL = 1;
const sC = 1 + weights.k1 * c1;
const sH = 1 + weights.k2 * c1;
const deltaLTerm = deltaL / (weights.kL * sL);
const deltaCTerm = deltaC / (weights.kC * sC);
const deltaHTerm = deltaH / (weights.kH * sH);
return Math.sqrt(
deltaLTerm * deltaLTerm +
deltaCTerm * deltaCTerm +
deltaHTerm * deltaHTerm
);
}
// Calculate Delta E CIEDE2000 (most accurate formula)
deltaE2000(lab1, lab2) {
const { l: L1, a: a1, b: b1 } = lab1;
const { l: L2, a: a2, b: b2 } = lab2;
// Calculate C and h values
const C1 = Math.sqrt(a1 * a1 + b1 * b1);
const C2 = Math.sqrt(a2 * a2 + b2 * b2);
const Cab = (C1 + C2) / 2;
const G = 0.5 * (1 - Math.sqrt(Math.pow(Cab, 7) / (Math.pow(Cab, 7) + Math.pow(25, 7))));
const ap1 = (1 + G) * a1;
const ap2 = (1 + G) * a2;
const Cp1 = Math.sqrt(ap1 * ap1 + b1 * b1);
const Cp2 = Math.sqrt(ap2 * ap2 + b2 * b2);
const hp1 = this.calculateHue(ap1, b1);
const hp2 = this.calculateHue(ap2, b2);
// Calculate differences
const deltaLp = L2 - L1;
const deltaCp = Cp2 - Cp1;
let deltahp = 0;
if (Cp1 * Cp2 !== 0) {
const dhp = hp2 - hp1;
if (Math.abs(dhp) <= 180) {
deltahp = dhp;
} else if (dhp > 180) {
deltahp = dhp - 360;
} else {
deltahp = dhp + 360;
}
}
const deltaHp = 2 * Math.sqrt(Cp1 * Cp2) * Math.sin(this.toRadians(deltahp / 2));
// Calculate means
const Lp = (L1 + L2) / 2;
const Cpp = (Cp1 + Cp2) / 2;
let Hpp = 0;
if (Cp1 * Cp2 !== 0) {
const sum = hp1 + hp2;
const diff = Math.abs(hp1 - hp2);
if (diff <= 180) {
Hpp = sum / 2;
} else if (sum < 360) {
Hpp = (sum + 360) / 2;
} else {
Hpp = (sum - 360) / 2;
}
}
// Calculate weighting functions
const T = 1 - 0.17 * Math.cos(this.toRadians(Hpp - 30)) +
0.24 * Math.cos(this.toRadians(2 * Hpp)) +
0.32 * Math.cos(this.toRadians(3 * Hpp + 6)) -
0.20 * Math.cos(this.toRadians(4 * Hpp - 63));
const deltaTheta = 30 * Math.exp(-Math.pow((Hpp - 275) / 25, 2));
const RC = 2 * Math.sqrt(Math.pow(Cpp, 7) / (Math.pow(Cpp, 7) + Math.pow(25, 7)));
const SL = 1 + (0.015 * Math.pow(Lp - 50, 2)) / Math.sqrt(20 + Math.pow(Lp - 50, 2));
const SC = 1 + 0.045 * Cpp;
const SH = 1 + 0.015 * Cpp * T;
const RT = -Math.sin(this.toRadians(2 * deltaTheta)) * RC;
// Calculate final Delta E 2000
const kL = 1, kC = 1, kH = 1; // Weighting factors
const deltaE = Math.sqrt(
Math.pow(deltaLp / (kL * SL), 2) +
Math.pow(deltaCp / (kC * SC), 2) +
Math.pow(deltaHp / (kH * SH), 2) +
RT * (deltaCp / (kC * SC)) * (deltaHp / (kH * SH))
);
return deltaE;
}
calculateHue(a, b) {
if (a === 0 && b === 0) return 0;
let hue = this.toDegrees(Math.atan2(b, a));
return hue < 0 ? hue + 360 : hue;
}
toRadians(degrees) {
return degrees * Math.PI / 180;
}
toDegrees(radians) {
return radians * 180 / Math.PI;
}
// Convert RGB to LAB for Delta E calculations
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);
}
rgbToXyz(r, g, b) {
// Normalize RGB values
r = r / 255;
g = g / 255;
b = b / 255;
// Apply gamma correction
r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
// Apply transformation matrix (sRGB to XYZ)
const x = r * 0.4124564 + g * 0.3575761 + b * 0.1804375;
const y = r * 0.2126729 + g * 0.7151522 + b * 0.0721750;
const z = r * 0.0193339 + g * 0.1191920 + b * 0.9503041;
return { x: x * 100, y: y * 100, z: z * 100 };
}
xyzToLab(x, y, z, illuminant = 'D65') {
const ref = this.illuminants[illuminant];
x = x / ref.x;
y = y / ref.y;
z = z / ref.z;
x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x + 16/116);
y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y + 16/116);
z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z + 16/116);
return {
l: 116 * y - 16,
a: 500 * (x - y),
b: 200 * (y - z)
};
}
}// Advanced Delta E applications for color matching
class ColorMatchingSystem {
constructor() {
this.calculator = new DeltaECalculator();
this.tolerances = {
critical: 1.0, // Medical, automotive
commercial: 2.3, // General printing
acceptable: 6.0 // Consumer displays
};
}
// Analyze color accuracy of an image against reference
analyzeColorAccuracy(testImageData, referenceImageData, samplePoints = 100) {
const { data: testData, width: testWidth, height: testHeight } = testImageData;
const { data: refData, width: refWidth, height: refHeight } = referenceImageData;
const results = [];
const deltaEValues = [];
// Generate sample points
for (let i = 0; i < samplePoints; i++) {
const x = Math.floor(Math.random() * Math.min(testWidth, refWidth));
const y = Math.floor(Math.random() * Math.min(testHeight, refHeight));
const testIndex = (y * testWidth + x) * 4;
const refIndex = (y * refWidth + x) * 4;
const testRGB = {
r: testData[testIndex],
g: testData[testIndex + 1],
b: testData[testIndex + 2]
};
const refRGB = {
r: refData[refIndex],
g: refData[refIndex + 1],
b: refData[refIndex + 2]
};
// Convert to LAB
const testLab = this.calculator.rgbToLab(testRGB.r, testRGB.g, testRGB.b);
const refLab = this.calculator.rgbToLab(refRGB.r, refRGB.g, refRGB.b);
// Calculate Delta E
const deltaE76 = this.calculator.deltaE76(testLab, refLab);
const deltaE94 = this.calculator.deltaE94(testLab, refLab);
const deltaE2000 = this.calculator.deltaE2000(testLab, refLab);
deltaEValues.push(deltaE2000);
results.push({
position: { x, y },
testColor: testRGB,
referenceColor: refRGB,
testLab,
referenceLab: refLab,
deltaE: {
cie76: deltaE76,
cie94: deltaE94,
ciede2000: deltaE2000
},
perceptible: deltaE2000 > 1,
acceptable: deltaE2000 < this.tolerances.acceptable
});
}
// Calculate statistics
deltaEValues.sort((a, b) => a - b);
const analysis = {
sampleCount: samplePoints,
averageDeltaE: deltaEValues.reduce((sum, val) => sum + val, 0) / deltaEValues.length,
medianDeltaE: deltaEValues[Math.floor(deltaEValues.length / 2)],
maxDeltaE: Math.max(...deltaEValues),
minDeltaE: Math.min(...deltaEValues),
percentile95: deltaEValues[Math.floor(deltaEValues.length * 0.95)],
// Quality metrics
perceptibleDifferences: results.filter(r => r.perceptible).length,
acceptableMatches: results.filter(r => r.acceptable).length,
// Tolerance analysis
withinCritical: results.filter(r => r.deltaE.ciede2000 < this.tolerances.critical).length,
withinCommercial: results.filter(r => r.deltaE.ciede2000 < this.tolerances.commercial).length,
withinAcceptable: results.filter(r => r.deltaE.ciede2000 < this.tolerances.acceptable).length
};
analysis.overallQuality = this.assessOverallQuality(analysis);
analysis.recommendations = this.generateRecommendations(analysis);
return {
analysis,
detailedResults: results
};
}
assessOverallQuality(analysis) {
const criticalPercentage = (analysis.withinCritical / analysis.sampleCount) * 100;
const commercialPercentage = (analysis.withinCommercial / analysis.sampleCount) * 100;
const acceptablePercentage = (analysis.withinAcceptable / analysis.sampleCount) * 100;
if (criticalPercentage > 95) return 'excellent';
if (commercialPercentage > 90) return 'good';
if (acceptablePercentage > 80) return 'acceptable';
return 'poor';
}
generateRecommendations(analysis) {
const recommendations = [];
if (analysis.averageDeltaE > this.tolerances.commercial) {
recommendations.push({
type: 'color_accuracy',
message: 'Color accuracy is below commercial standards',
suggestion: 'Consider display calibration or color profile adjustment',
priority: 'high'
});
}
if (analysis.maxDeltaE > 10) {
recommendations.push({
type: 'outliers',
message: 'Some colors show significant deviation',
suggestion: 'Check for specific color gamut issues or calibration problems',
priority: 'medium'
});
}
if (analysis.percentile95 > this.tolerances.acceptable) {
recommendations.push({
type: 'consistency',
message: 'Color consistency issues detected',
suggestion: 'Review color management workflow and display uniformity',
priority: 'medium'
});
}
return recommendations;
}
// Find closest color match from palette
findClosestMatch(targetRGB, paletteRGBs, method = 'ciede2000') {
const targetLab = this.calculator.rgbToLab(targetRGB.r, targetRGB.g, targetRGB.b);
let closestMatch = null;
let smallestDeltaE = Infinity;
paletteRGBs.forEach((paletteRGB, index) => {
const paletteLab = this.calculator.rgbToLab(paletteRGB.r, paletteRGB.g, paletteRGB.b);
let deltaE;
switch (method) {
case 'cie76':
deltaE = this.calculator.deltaE76(targetLab, paletteLab);
break;
case 'cie94':
deltaE = this.calculator.deltaE94(targetLab, paletteLab);
break;
case 'ciede2000':
default:
deltaE = this.calculator.deltaE2000(targetLab, paletteLab);
break;
}
if (deltaE < smallestDeltaE) {
smallestDeltaE = deltaE;
closestMatch = {
index,
color: paletteRGB,
deltaE,
perceptible: deltaE > 1,
acceptable: deltaE < this.tolerances.acceptable
};
}
});
return closestMatch;
}
// Generate color difference heatmap
generateDifferenceHeatmap(imageData1, imageData2) {
const { data: data1, width, height } = imageData1;
const { data: data2 } = imageData2;
const heatmapData = new ImageData(width, height);
const heatmapPixels = heatmapData.data;
const deltaEValues = [];
for (let i = 0; i < data1.length; i += 4) {
const rgb1 = { r: data1[i], g: data1[i + 1], b: data1[i + 2] };
const rgb2 = { r: data2[i], g: data2[i + 1], b: data2[i + 2] };
const lab1 = this.calculator.rgbToLab(rgb1.r, rgb1.g, rgb1.b);
const lab2 = this.calculator.rgbToLab(rgb2.r, rgb2.g, rgb2.b);
const deltaE = this.calculator.deltaE2000(lab1, lab2);
deltaEValues.push(deltaE);
}
// Normalize Delta E values for visualization
const maxDeltaE = Math.max(...deltaEValues);
for (let i = 0, j = 0; i < deltaEValues.length; i++, j += 4) {
const normalizedDeltaE = deltaEValues[i] / maxDeltaE;
const heatmapColor = this.deltaEToHeatmapColor(normalizedDeltaE);
heatmapPixels[j] = heatmapColor.r;
heatmapPixels[j + 1] = heatmapColor.g;
heatmapPixels[j + 2] = heatmapColor.b;
heatmapPixels[j + 3] = 255;
}
return {
heatmap: heatmapData,
statistics: {
maxDeltaE,
averageDeltaE: deltaEValues.reduce((sum, val) => sum + val, 0) / deltaEValues.length,
deltaEValues
}
};
}
deltaEToHeatmapColor(normalizedDeltaE) {
// Convert normalized Delta E to heatmap color (blue = low, red = high)
if (normalizedDeltaE < 0.5) {
return {
r: 0,
g: Math.round(normalizedDeltaE * 2 * 255),
b: 255
};
} else {
return {
r: Math.round((normalizedDeltaE - 0.5) * 2 * 255),
g: Math.round((1 - normalizedDeltaE) * 2 * 255),
b: 0
};
}
}
}// Delta E applications for calibration and quality control
class CalibrationDeltaE {
constructor() {
this.calculator = new DeltaECalculator();
this.matching = new ColorMatchingSystem();
}
// Evaluate display calibration accuracy
evaluateDisplayCalibration(measuredColors, targetColors) {
const results = [];
for (let i = 0; i < measuredColors.length; i++) {
const measured = measuredColors[i];
const target = targetColors[i];
const measuredLab = this.calculator.rgbToLab(measured.r, measured.g, measured.b);
const targetLab = this.calculator.rgbToLab(target.r, target.g, target.b);
const deltaE = this.calculator.deltaE2000(measuredLab, targetLab);
results.push({
patchNumber: i + 1,
measured,
target,
deltaE,
acceptable: deltaE < 2.3, // Commercial tolerance
excellent: deltaE < 1.0 // Critical tolerance
});
}
const analysis = {
totalPatches: results.length,
averageDeltaE: results.reduce((sum, r) => sum + r.deltaE, 0) / results.length,
maxDeltaE: Math.max(...results.map(r => r.deltaE)),
acceptablePatches: results.filter(r => r.acceptable).length,
excellentPatches: results.filter(r => r.excellent).length,
calibrationQuality: this.assessCalibrationQuality(results)
};
return {
analysis,
patchResults: results,
recommendations: this.generateCalibrationRecommendations(analysis)
};
}
assessCalibrationQuality(results) {
const excellentPercentage = (results.filter(r => r.excellent).length / results.length) * 100;
const acceptablePercentage = (results.filter(r => r.acceptable).length / results.length) * 100;
if (excellentPercentage > 90) return 'excellent';
if (acceptablePercentage > 95) return 'good';
if (acceptablePercentage > 80) return 'acceptable';
return 'poor';
}
generateCalibrationRecommendations(analysis) {
const recommendations = [];
if (analysis.calibrationQuality === 'poor') {
recommendations.push({
type: 'recalibration',
message: 'Display requires recalibration',
action: 'Perform full display calibration with colorimeter',
priority: 'high'
});
}
if (analysis.averageDeltaE > 3.0) {
recommendations.push({
type: 'profile_update',
message: 'Color profile may be outdated',
action: 'Update or recreate display color profile',
priority: 'medium'
});
}
if (analysis.maxDeltaE > 10) {
recommendations.push({
type: 'hardware_check',
message: 'Significant color deviations detected',
action: 'Check display hardware and aging',
priority: 'high'
});
}
return recommendations;
}
// Generate test patterns for Delta E measurement
generateTestPatterns(patternType = 'grayscale', count = 21) {
const patterns = [];
switch (patternType) {
case 'grayscale':
for (let i = 0; i < count; i++) {
const value = Math.round((i / (count - 1)) * 255);
patterns.push({ r: value, g: value, b: value, name: `Gray ${i + 1}` });
}
break;
case 'primary':
patterns.push(
{ r: 255, g: 0, b: 0, name: 'Red' },
{ r: 0, g: 255, b: 0, name: 'Green' },
{ r: 0, g: 0, b: 255, name: 'Blue' },
{ r: 255, g: 255, b: 0, name: 'Yellow' },
{ r: 255, g: 0, b: 255, name: 'Magenta' },
{ r: 0, g: 255, b: 255, name: 'Cyan' },
{ r: 255, g: 255, b: 255, name: 'White' },
{ r: 0, g: 0, b: 0, name: 'Black' }
);
break;
case 'skin_tones':
patterns.push(
{ r: 241, g: 194, b: 125, name: 'Light Skin' },
{ r: 230, g: 162, b: 115, name: 'Medium Light Skin' },
{ r: 194, g: 120, b: 87, name: 'Medium Skin' },
{ r: 161, g: 102, b: 77, name: 'Medium Dark Skin' },
{ r: 112, g: 66, b: 52, name: 'Dark Skin' },
{ r: 85, g: 51, b: 38, name: 'Very Dark Skin' }
);
break;
}
return patterns;
}
}Explore these comprehensive pillar articles related to Delta E
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 Delta E 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