A comprehensive guide to color science - the interdisciplinary field studying color perception, measurement, and reproduction, encompassing physics, psychology, and technology to understand how humans perceive and process color information.
Color science is the interdisciplinary study of color, combining physics, psychology, neuroscience, and technology to understand how color is perceived, measured, and reproduced. It forms the foundation for color management, display technology, printing, and digital imaging, providing the scientific basis for accurate color reproduction across different media and devices.
Color is not an inherent property of objects but rather a perceptual phenomenon that results from the interaction of light, objects, and human vision:
// Color science calculation system
class ColorScienceCalculator {
constructor() {
// CIE standard illuminants
this.illuminants = {
A: { x: 109.850, y: 100.000, z: 35.585, temp: 2856 },
D50: { x: 96.422, y: 100.000, z: 82.521, temp: 5003 },
D65: { x: 95.047, y: 100.000, z: 108.883, temp: 6504 },
E: { x: 100.000, y: 100.000, z: 100.000, temp: 5454 }
};
}
// Convert wavelength to XYZ using color matching functions
wavelengthToXYZ(wavelength, intensity = 1) {
const cmf = this.interpolateCMF(wavelength);
return {
x: cmf.x * intensity,
y: cmf.y * intensity,
z: cmf.z * intensity
};
}
// Calculate XYZ from spectral power distribution
spectralToXYZ(spectralData, illuminant = 'D65') {
let X = 0, Y = 0, Z = 0;
const illum = this.illuminants[illuminant];
for (const [wavelength, power] of spectralData) {
const cmf = this.interpolateCMF(wavelength);
const illuminantPower = this.getIlluminantPower(wavelength, illuminant);
X += cmf.x * power * illuminantPower;
Y += cmf.y * power * illuminantPower;
Z += cmf.z * power * illuminantPower;
}
// Normalize to illuminant
const normalizationFactor = 100 / illum.y;
return {
x: X * normalizationFactor,
y: Y * normalizationFactor,
z: Z * normalizationFactor
};
}
interpolateCMF(wavelength) {
// Simplified CIE 1931 color matching functions
const x = this.gaussianCMF(wavelength, 599.8, 37.9, 1.056);
const y = this.gaussianCMF(wavelength, 568.8, 46.9, 0.821);
const z = this.gaussianCMF(wavelength, 437.0, 11.8, 1.217);
return { x: Math.max(0, x), y: Math.max(0, y), z: Math.max(0, z) };
}
gaussianCMF(wavelength, peak, width, amplitude) {
return amplitude * Math.exp(-0.5 * Math.pow((wavelength - peak) / width, 2));
}
getIlluminantPower(wavelength, illuminant) {
switch (illuminant) {
case 'A': return this.planckianDistribution(wavelength, 2856);
case 'D65': return this.daylightDistribution(wavelength, 6504);
case 'E': return 1.0;
default: return 1.0;
}
}
planckianDistribution(wavelength, temperature) {
const wl = wavelength * 1e-9;
const h = 6.626e-34, c = 3e8, k = 1.381e-23;
const numerator = 2 * h * c * c / Math.pow(wl, 5);
const denominator = Math.exp(h * c / (wl * k * temperature)) - 1;
return numerator / denominator;
}
daylightDistribution(wavelength, temperature) {
const base = this.planckianDistribution(wavelength, temperature);
const correction = 1 + 0.1 * Math.sin((wavelength - 500) * Math.PI / 200);
return base * correction;
}
}// Color space transformation system
class ColorSpaceTransformer {
constructor() {
this.matrices = {
sRGB_to_XYZ: [
[0.4124564, 0.3575761, 0.1804375],
[0.2126729, 0.7151522, 0.0721750],
[0.0193339, 0.1191920, 0.9503041]
],
XYZ_to_sRGB: [
[3.2404542, -1.5371385, -0.4985314],
[-0.9692660, 1.8760108, 0.0415560],
[0.0556434, -0.2040259, 1.0572252]
]
};
}
// Transform between color spaces
transform(color, fromSpace, toSpace, illuminant = 'D65') {
let xyz;
switch (fromSpace.toLowerCase()) {
case 'srgb': xyz = this.sRGBtoXYZ(color); break;
case 'lab': xyz = this.LABtoXYZ(color, illuminant); break;
case 'xyz': xyz = color; break;
default: throw new Error(`Unsupported source: ${fromSpace}`);
}
switch (toSpace.toLowerCase()) {
case 'srgb': return this.XYZtosRGB(xyz);
case 'lab': return this.XYZtoLAB(xyz, illuminant);
case 'xyz': return xyz;
default: throw new Error(`Unsupported target: ${toSpace}`);
}
}
sRGBtoXYZ(rgb) {
const r = this.sRGBGamma(rgb.r / 255);
const g = this.sRGBGamma(rgb.g / 255);
const b = this.sRGBGamma(rgb.b / 255);
return this.matrixTransform([r, g, b], this.matrices.sRGB_to_XYZ);
}
XYZtosRGB(xyz) {
const rgb = this.matrixTransform([xyz.x/100, xyz.y/100, xyz.z/100], this.matrices.XYZ_to_sRGB);
return {
r: Math.round(Math.max(0, Math.min(255, this.sRGBInverseGamma(rgb[0]) * 255))),
g: Math.round(Math.max(0, Math.min(255, this.sRGBInverseGamma(rgb[1]) * 255))),
b: Math.round(Math.max(0, Math.min(255, this.sRGBInverseGamma(rgb[2]) * 255)))
};
}
sRGBGamma(value) {
return value <= 0.04045 ? value / 12.92 : Math.pow((value + 0.055) / 1.055, 2.4);
}
sRGBInverseGamma(value) {
return value <= 0.0031308 ? value * 12.92 : 1.055 * Math.pow(value, 1/2.4) - 0.055;
}
matrixTransform(vector, matrix) {
const result = [];
for (let i = 0; i < matrix.length; i++) {
let sum = 0;
for (let j = 0; j < vector.length; j++) {
sum += matrix[i][j] * vector[j];
}
result.push(sum);
}
return matrix.length === 3 ? { x: result[0]*100, y: result[1]*100, z: result[2]*100 } : result;
}
XYZtoLAB(xyz, illuminant = 'D65') {
const illuminants = {
D65: { x: 95.047, y: 100.000, z: 108.883 },
D50: { x: 96.422, y: 100.000, z: 82.521 }
};
const ref = illuminants[illuminant];
const x = this.labFunction(xyz.x / ref.x);
const y = this.labFunction(xyz.y / ref.y);
const z = this.labFunction(xyz.z / ref.z);
return {
l: 116 * y - 16,
a: 500 * (x - y),
b: 200 * (y - z)
};
}
LABtoXYZ(lab, illuminant = 'D65') {
const illuminants = {
D65: { x: 95.047, y: 100.000, z: 108.883 },
D50: { x: 96.422, y: 100.000, z: 82.521 }
};
const ref = illuminants[illuminant];
const fy = (lab.l + 16) / 116;
const fx = lab.a / 500 + fy;
const fz = fy - lab.b / 200;
return {
x: this.labInverseFunction(fx) * ref.x,
y: this.labInverseFunction(fy) * ref.y,
z: this.labInverseFunction(fz) * ref.z
};
}
labFunction(t) {
const delta = 6/29;
return t > delta**3 ? Math.pow(t, 1/3) : t/(3*delta**2) + 4/29;
}
labInverseFunction(t) {
const delta = 6/29;
return t > delta ? t**3 : 3*delta**2*(t - 4/29);
}
}// Color perception and appearance modeling
class ColorPerceptionModel {
constructor() {
this.transformer = new ColorSpaceTransformer();
}
// Model color appearance under viewing conditions
colorAppearanceModel(color, viewingConditions = {}) {
const {
adaptingLuminance = 64,
background = 20,
surround = 'average',
illuminant = 'D65'
} = viewingConditions;
const xyz = this.transformer.transform(color, 'sRGB', 'XYZ');
const adaptedXYZ = this.chromaticAdaptation(xyz, illuminant, adaptingLuminance);
return {
lightness: this.calculateLightness(adaptedXYZ.y, adaptingLuminance),
chroma: this.calculateChroma(adaptedXYZ),
hue: this.calculateHue(adaptedXYZ),
brightness: this.calculateBrightness(adaptedXYZ, surround)
};
}
chromaticAdaptation(xyz, illuminant, adaptingLuminance) {
const factor = Math.log10(adaptingLuminance / 64) * 0.1;
return {
x: xyz.x * (1 + factor),
y: xyz.y,
z: xyz.z * (1 - factor)
};
}
calculateLightness(Y, adaptingLuminance) {
const ratio = Y / adaptingLuminance;
return ratio > 0.008856 ? 116 * Math.pow(ratio, 1/3) - 16 : 903.3 * ratio;
}
calculateChroma(xyz) {
const lab = this.transformer.transform(xyz, 'XYZ', 'LAB');
return Math.sqrt(lab.a**2 + lab.b**2);
}
calculateHue(xyz) {
const lab = this.transformer.transform(xyz, 'XYZ', 'LAB');
let hue = Math.atan2(lab.b, lab.a) * 180 / Math.PI;
return hue < 0 ? hue + 360 : hue;
}
calculateBrightness(xyz, surround) {
const factors = { dim: 0.9, average: 1.0, dark: 1.1 };
return this.calculateLightness(xyz.y, 64) * (factors[surround] || 1.0);
}
// Model metamerism
metamerismIndex(color1, color2, illuminant1, illuminant2) {
const xyz1_ill1 = this.chromaticAdaptation(
this.transformer.transform(color1, 'sRGB', 'XYZ'), illuminant1, 64
);
const xyz1_ill2 = this.chromaticAdaptation(
this.transformer.transform(color1, 'sRGB', 'XYZ'), illuminant2, 64
);
const deltaE1 = this.calculateDeltaE(
this.transformer.transform(xyz1_ill1, 'XYZ', 'LAB'),
this.transformer.transform(
this.chromaticAdaptation(
this.transformer.transform(color2, 'sRGB', 'XYZ'), illuminant1, 64
), 'XYZ', 'LAB'
)
);
const deltaE2 = this.calculateDeltaE(
this.transformer.transform(xyz1_ill2, 'XYZ', 'LAB'),
this.transformer.transform(
this.chromaticAdaptation(
this.transformer.transform(color2, 'sRGB', 'XYZ'), illuminant2, 64
), 'XYZ', 'LAB'
)
);
return {
index: Math.abs(deltaE1 - deltaE2),
deltaE_illuminant1: deltaE1,
deltaE_illuminant2: deltaE2,
isMetameric: deltaE1 < 1.0 && deltaE2 > 3.0
};
}
calculateDeltaE(lab1, lab2) {
const dL = lab1.l - lab2.l;
const da = lab1.a - lab2.a;
const db = lab1.b - lab2.b;
return Math.sqrt(dL**2 + da**2 + db**2);
}
}Explore these comprehensive pillar articles related to Color Science
A comprehensive guide to color theory, its fundamental principles, and practical applications in digital design and web development.
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.
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.
Discover more about Color Science and related color theory concepts
A comprehensive guide to color theory, its fundamental principles, and practical applications in digital design and web development.
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.
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 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