A comprehensive guide to chrominance - the color information component of video and image signals that carries hue and saturation data separately from brightness (luminance), essential for color reproduction, compression, and digital image processing.
Chrominance refers to the color information in an image or video signal, representing the hue and saturation components while excluding brightness information (luminance). This separation is fundamental to many color spaces like YUV, YCbCr, and YIQ, enabling efficient color processing, compression, and transmission in digital imaging and video systems.
The separation of chrominance and luminance is based on human visual perception:
// Chrominance processing and color space conversion system
class ChrominanceProcessor {
constructor() {
this.colorSpaces = {
yuv: {
name: 'YUV',
description: 'Analog color space used in PAL and NTSC',
components: ['Y', 'U', 'V']
},
ycbcr: {
name: 'YCbCr',
description: 'Digital color space used in JPEG and video compression',
components: ['Y', 'Cb', 'Cr']
},
yiq: {
name: 'YIQ',
description: 'Color space used in NTSC television broadcasting',
components: ['Y', 'I', 'Q']
}
};
}
// Convert RGB to YCbCr (ITU-R BT.601 standard)
rgbToYCbCr(r, g, b) {
// Normalize RGB values to 0-1 range
const rNorm = r / 255;
const gNorm = g / 255;
const bNorm = b / 255;
// ITU-R BT.601 conversion matrix
const y = 0.299 * rNorm + 0.587 * gNorm + 0.114 * bNorm;
const cb = -0.168736 * rNorm - 0.331264 * gNorm + 0.5 * bNorm + 0.5;
const cr = 0.5 * rNorm - 0.418688 * gNorm - 0.081312 * bNorm + 0.5;
return {
y: Math.round(y * 255),
cb: Math.round(cb * 255),
cr: Math.round(cr * 255),
luminance: y * 255,
chrominance: { cb: cb * 255, cr: cr * 255 }
};
}
// Convert YCbCr back to RGB
ycbcrToRgb(y, cb, cr) {
// Normalize to 0-1 range
const yNorm = y / 255;
const cbNorm = (cb / 255) - 0.5;
const crNorm = (cr / 255) - 0.5;
// ITU-R BT.601 inverse conversion
const r = yNorm + 1.402 * crNorm;
const g = yNorm - 0.344136 * cbNorm - 0.714136 * crNorm;
const b = yNorm + 1.772 * cbNorm;
return {
r: Math.max(0, Math.min(255, Math.round(r * 255))),
g: Math.max(0, Math.min(255, Math.round(g * 255))),
b: Math.max(0, Math.min(255, Math.round(b * 255)))
};
}
// Convert RGB to YUV (analog color space)
rgbToYuv(r, g, b) {
const rNorm = r / 255;
const gNorm = g / 255;
const bNorm = b / 255;
const y = 0.299 * rNorm + 0.587 * gNorm + 0.114 * bNorm;
const u = -0.14713 * rNorm - 0.28886 * gNorm + 0.436 * bNorm;
const v = 0.615 * rNorm - 0.51499 * gNorm - 0.10001 * bNorm;
return {
y: y * 255,
u: u * 255 + 128, // Offset for storage
v: v * 255 + 128,
luminance: y * 255,
chrominance: { u: u * 255, v: v * 255 }
};
}
// Separate chrominance channels from image
extractChrominanceChannels(imageData, colorSpace = 'ycbcr') {
const { data, width, height } = imageData;
const luminanceChannel = new Uint8ClampedArray(width * height);
const chrominanceU = new Uint8ClampedArray(width * height);
const chrominanceV = new Uint8ClampedArray(width * height);
for (let i = 0; i < data.length; i += 4) {
const r = data[i];
const g = data[i + 1];
const b = data[i + 2];
const pixelIndex = i / 4;
let converted;
if (colorSpace === 'ycbcr') {
converted = this.rgbToYCbCr(r, g, b);
luminanceChannel[pixelIndex] = converted.y;
chrominanceU[pixelIndex] = converted.cb;
chrominanceV[pixelIndex] = converted.cr;
} else if (colorSpace === 'yuv') {
converted = this.rgbToYuv(r, g, b);
luminanceChannel[pixelIndex] = converted.y;
chrominanceU[pixelIndex] = converted.u;
chrominanceV[pixelIndex] = converted.v;
}
}
return {
luminance: luminanceChannel,
chrominanceU,
chrominanceV,
width,
height,
colorSpace
};
}
// Reconstruct RGB image from separated channels
reconstructFromChannels(channels) {
const { luminance, chrominanceU, chrominanceV, width, height, colorSpace } = channels;
const result = new Uint8ClampedArray(width * height * 4);
for (let i = 0; i < luminance.length; i++) {
const y = luminance[i];
const u = chrominanceU[i];
const v = chrominanceV[i];
let rgb;
if (colorSpace === 'ycbcr') {
rgb = this.ycbcrToRgb(y, u, v);
} else if (colorSpace === 'yuv') {
rgb = this.yuvToRgb(y, u - 128, v - 128); // Remove offset
}
const pixelIndex = i * 4;
result[pixelIndex] = rgb.r;
result[pixelIndex + 1] = rgb.g;
result[pixelIndex + 2] = rgb.b;
result[pixelIndex + 3] = 255; // Alpha
}
return new ImageData(result, width, height);
}
yuvToRgb(y, u, v) {
const yNorm = y / 255;
const uNorm = u / 255;
const vNorm = v / 255;
const r = yNorm + 1.13983 * vNorm;
const g = yNorm - 0.39465 * uNorm - 0.58060 * vNorm;
const b = yNorm + 2.03211 * uNorm;
return {
r: Math.max(0, Math.min(255, Math.round(r * 255))),
g: Math.max(0, Math.min(255, Math.round(g * 255))),
b: Math.max(0, Math.min(255, Math.round(b * 255)))
};
}
// Apply chrominance subsampling (used in JPEG and video compression)
applyChrominanceSubsampling(channels, subsamplingRatio = '4:2:0') {
const { luminance, chrominanceU, chrominanceV, width, height } = channels;
let sampledU, sampledV, newWidth, newHeight;
switch (subsamplingRatio) {
case '4:4:4': // No subsampling
return channels;
case '4:2:2': // Horizontal subsampling by 2
newWidth = Math.ceil(width / 2);
newHeight = height;
sampledU = new Uint8ClampedArray(newWidth * newHeight);
sampledV = new Uint8ClampedArray(newWidth * newHeight);
for (let y = 0; y < height; y++) {
for (let x = 0; x < newWidth; x++) {
const srcIndex1 = y * width + (x * 2);
const srcIndex2 = y * width + (x * 2 + 1);
const dstIndex = y * newWidth + x;
// Average two horizontal pixels
sampledU[dstIndex] = Math.round((chrominanceU[srcIndex1] +
(srcIndex2 < chrominanceU.length ? chrominanceU[srcIndex2] : chrominanceU[srcIndex1])) / 2);
sampledV[dstIndex] = Math.round((chrominanceV[srcIndex1] +
(srcIndex2 < chrominanceV.length ? chrominanceV[srcIndex2] : chrominanceV[srcIndex1])) / 2);
}
}
break;
case '4:2:0': // Horizontal and vertical subsampling by 2
newWidth = Math.ceil(width / 2);
newHeight = Math.ceil(height / 2);
sampledU = new Uint8ClampedArray(newWidth * newHeight);
sampledV = new Uint8ClampedArray(newWidth * newHeight);
for (let y = 0; y < newHeight; y++) {
for (let x = 0; x < newWidth; x++) {
// Sample 2x2 block
const srcY1 = y * 2;
const srcY2 = Math.min(y * 2 + 1, height - 1);
const srcX1 = x * 2;
const srcX2 = Math.min(x * 2 + 1, width - 1);
const idx1 = srcY1 * width + srcX1;
const idx2 = srcY1 * width + srcX2;
const idx3 = srcY2 * width + srcX1;
const idx4 = srcY2 * width + srcX2;
const dstIndex = y * newWidth + x;
// Average 2x2 block
sampledU[dstIndex] = Math.round((
chrominanceU[idx1] + chrominanceU[idx2] +
chrominanceU[idx3] + chrominanceU[idx4]
) / 4);
sampledV[dstIndex] = Math.round((
chrominanceV[idx1] + chrominanceV[idx2] +
chrominanceV[idx3] + chrominanceV[idx4]
) / 4);
}
}
break;
}
return {
luminance, // Keep full resolution
chrominanceU: sampledU,
chrominanceV: sampledV,
width,
height,
chrominanceWidth: newWidth,
chrominanceHeight: newHeight,
subsamplingRatio,
colorSpace: channels.colorSpace
};
}
// Upsample chrominance channels back to full resolution
upsampleChrominance(subsampledChannels) {
const {
luminance, chrominanceU, chrominanceV,
width, height, chrominanceWidth, chrominanceHeight,
subsamplingRatio
} = subsampledChannels;
if (subsamplingRatio === '4:4:4') {
return subsampledChannels;
}
const fullU = new Uint8ClampedArray(width * height);
const fullV = new Uint8ClampedArray(width * height);
// Bilinear interpolation for upsampling
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
const dstIndex = y * width + x;
// Map to chrominance coordinates
const chromaX = (x / width) * chrominanceWidth;
const chromaY = (y / height) * chrominanceHeight;
// Bilinear interpolation
const x1 = Math.floor(chromaX);
const y1 = Math.floor(chromaY);
const x2 = Math.min(x1 + 1, chrominanceWidth - 1);
const y2 = Math.min(y1 + 1, chrominanceHeight - 1);
const fx = chromaX - x1;
const fy = chromaY - y1;
const idx11 = y1 * chrominanceWidth + x1;
const idx12 = y1 * chrominanceWidth + x2;
const idx21 = y2 * chrominanceWidth + x1;
const idx22 = y2 * chrominanceWidth + x2;
// Interpolate U channel
const u11 = chrominanceU[idx11];
const u12 = chrominanceU[idx12];
const u21 = chrominanceU[idx21];
const u22 = chrominanceU[idx22];
const uTop = u11 * (1 - fx) + u12 * fx;
const uBottom = u21 * (1 - fx) + u22 * fx;
fullU[dstIndex] = Math.round(uTop * (1 - fy) + uBottom * fy);
// Interpolate V channel
const v11 = chrominanceV[idx11];
const v12 = chrominanceV[idx12];
const v21 = chrominanceV[idx21];
const v22 = chrominanceV[idx22];
const vTop = v11 * (1 - fx) + v12 * fx;
const vBottom = v21 * (1 - fx) + v22 * fx;
fullV[dstIndex] = Math.round(vTop * (1 - fy) + vBottom * fy);
}
}
return {
luminance,
chrominanceU: fullU,
chrominanceV: fullV,
width,
height,
colorSpace: subsampledChannels.colorSpace
};
}
// Analyze chrominance quality and compression artifacts
analyzeChrominanceQuality(originalChannels, processedChannels) {
const { chrominanceU: origU, chrominanceV: origV } = originalChannels;
const { chrominanceU: procU, chrominanceV: procV } = processedChannels;
let totalErrorU = 0;
let totalErrorV = 0;
let maxErrorU = 0;
let maxErrorV = 0;
for (let i = 0; i < origU.length; i++) {
const errorU = Math.abs(origU[i] - procU[i]);
const errorV = Math.abs(origV[i] - procV[i]);
totalErrorU += errorU;
totalErrorV += errorV;
maxErrorU = Math.max(maxErrorU, errorU);
maxErrorV = Math.max(maxErrorV, errorV);
}
const avgErrorU = totalErrorU / origU.length;
const avgErrorV = totalErrorV / origV.length;
return {
averageError: {
u: avgErrorU,
v: avgErrorV,
combined: (avgErrorU + avgErrorV) / 2
},
maximumError: {
u: maxErrorU,
v: maxErrorV,
combined: Math.max(maxErrorU, maxErrorV)
},
qualityGrade: this.gradeChrominanceQuality((avgErrorU + avgErrorV) / 2),
compressionRatio: this.calculateCompressionRatio(originalChannels, processedChannels)
};
}
gradeChrominanceQuality(averageError) {
if (averageError < 2) return 'excellent';
if (averageError < 5) return 'very good';
if (averageError < 10) return 'good';
if (averageError < 20) return 'fair';
return 'poor';
}
calculateCompressionRatio(original, processed) {
// Estimate compression based on subsampling
if (processed.subsamplingRatio === '4:2:0') {
return 2.0; // 50% reduction in chrominance data
} else if (processed.subsamplingRatio === '4:2:2') {
return 1.33; // 25% reduction in chrominance data
}
return 1.0; // No compression
}
}// Advanced chrominance processing for video and image compression
class AdvancedChrominanceProcessor extends ChrominanceProcessor {
constructor() {
super();
this.compressionStandards = {
jpeg: { colorSpace: 'ycbcr', subsampling: '4:2:0', quantization: 'standard' },
h264: { colorSpace: 'ycbcr', subsampling: '4:2:0', quantization: 'adaptive' },
h265: { colorSpace: 'ycbcr', subsampling: '4:2:0', quantization: 'advanced' },
av1: { colorSpace: 'ycbcr', subsampling: '4:4:4', quantization: 'perceptual' }
};
}
// Apply perceptual chrominance optimization
applyPerceptualOptimization(channels, viewingConditions = {}) {
const {
viewingDistance = 'normal', // close, normal, far
displayType = 'srgb', // srgb, p3, rec2020
ambientLight = 'moderate' // dim, moderate, bright
} = viewingConditions;
const { luminance, chrominanceU, chrominanceV, width, height } = channels;
const optimizedU = new Uint8ClampedArray(chrominanceU.length);
const optimizedV = new Uint8ClampedArray(chrominanceV.length);
// Calculate perceptual weights based on viewing conditions
const perceptualWeight = this.calculatePerceptualWeight(viewingConditions);
for (let i = 0; i < chrominanceU.length; i++) {
const localLuminance = luminance[i] / 255;
// Apply luminance-dependent chrominance scaling
const luminanceWeight = this.getLuminanceChrominanceWeight(localLuminance);
// Combine perceptual and luminance weights
const totalWeight = perceptualWeight * luminanceWeight;
// Apply weighted chrominance reduction
const centerU = 128;
const centerV = 128;
optimizedU[i] = Math.round(centerU + (chrominanceU[i] - centerU) * totalWeight);
optimizedV[i] = Math.round(centerV + (chrominanceV[i] - centerV) * totalWeight);
}
return {
...channels,
chrominanceU: optimizedU,
chrominanceV: optimizedV,
optimization: 'perceptual',
optimizationWeight: perceptualWeight
};
}
calculatePerceptualWeight(conditions) {
let weight = 1.0;
// Viewing distance affects chrominance sensitivity
switch (conditions.viewingDistance) {
case 'close': weight *= 1.0; break;
case 'normal': weight *= 0.8; break;
case 'far': weight *= 0.6; break;
}
// Display gamut affects color precision needs
switch (conditions.displayType) {
case 'srgb': weight *= 0.8; break;
case 'p3': weight *= 0.9; break;
case 'rec2020': weight *= 1.0; break;
}
// Ambient light affects color perception
switch (conditions.ambientLight) {
case 'dim': weight *= 1.0; break;
case 'moderate': weight *= 0.9; break;
case 'bright': weight *= 0.7; break;
}
return Math.max(0.3, Math.min(1.0, weight));
}
getLuminanceChrominanceWeight(luminance) {
// Chrominance is less visible in very dark and very bright areas
if (luminance < 0.1 || luminance > 0.9) {
return 0.5;
} else if (luminance < 0.2 || luminance > 0.8) {
return 0.7;
}
return 1.0;
}
// Advanced chrominance noise reduction
reduceChrominanceNoise(channels, strength = 0.5) {
const { chrominanceU, chrominanceV, width, height } = channels;
const filteredU = new Uint8ClampedArray(chrominanceU.length);
const filteredV = new Uint8ClampedArray(chrominanceV.length);
const kernelSize = 3;
const halfKernel = Math.floor(kernelSize / 2);
for (let y = halfKernel; y < height - halfKernel; y++) {
for (let x = halfKernel; x < width - halfKernel; x++) {
const centerIndex = y * width + x;
let sumU = 0, sumV = 0, count = 0;
// Apply Gaussian-like filter to chrominance
for (let dy = -halfKernel; dy <= halfKernel; dy++) {
for (let dx = -halfKernel; dx <= halfKernel; dx++) {
const sampleIndex = (y + dy) * width + (x + dx);
const weight = Math.exp(-(dx * dx + dy * dy) / (2 * strength * strength));
sumU += chrominanceU[sampleIndex] * weight;
sumV += chrominanceV[sampleIndex] * weight;
count += weight;
}
}
filteredU[centerIndex] = Math.round(sumU / count);
filteredV[centerIndex] = Math.round(sumV / count);
}
}
// Copy edges
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
const index = y * width + x;
if (y < halfKernel || y >= height - halfKernel ||
x < halfKernel || x >= width - halfKernel) {
filteredU[index] = chrominanceU[index];
filteredV[index] = chrominanceV[index];
}
}
}
return {
...channels,
chrominanceU: filteredU,
chrominanceV: filteredV,
noiseReduction: strength
};
}
}Explore these comprehensive pillar articles related to Chrominance
A comprehensive guide to color theory, its fundamental principles, and practical applications in digital design and web development.
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.
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 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.
Discover more about Chrominance 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.
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.
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.
Discover more color terminology and concepts in our comprehensive glossary.
Browse Full Glossary