A comprehensive guide to Color Lookup Tables (LUTs) - mathematical tables that map input color values to output values, essential for color correction, grading, calibration, and ensuring consistent color reproduction across different devices and workflows.
A Color Lookup Table (LUT) is a mathematical table that maps input color values to corresponding output values, enabling precise color transformations and corrections. LUTs are fundamental tools in digital imaging, video production, color grading, and display calibration, providing a way to apply complex color transformations efficiently and consistently across different devices and workflows.
LUTs work by storing pre-calculated color transformation values in a table format. Instead of performing complex mathematical calculations for each pixel, the system simply looks up the corresponding output value for each input value. This approach provides both speed and consistency in color processing.
// Color Lookup Table Implementation
class ColorLookupTable {
constructor(size = 256, dimensions = 3) {
this.size = size;
this.dimensions = dimensions;
this.table = this.initializeTable();
this.interpolation = 'trilinear';
this.metadata = {
created: new Date().toISOString(),
colorSpace: 'RGB',
bitDepth: 8,
purpose: 'Color correction'
};
}
// Initialize empty LUT table
initializeTable() {
const table = [];
const step = 1 / (this.size - 1);
for (let r = 0; r < this.size; r++) {
table[r] = [];
for (let g = 0; g < this.size; g++) {
table[r][g] = [];
for (let b = 0; b < this.size; b++) {
// Initialize with identity transformation
table[r][g][b] = {
r: r * step,
g: g * step,
b: b * step
};
}
}
}
return table;
}
// Apply LUT to color values
applyLUT(inputColor) {
const { r, g, b } = this.normalizeColor(inputColor);
// Convert normalized values to table indices
const rIndex = r * (this.size - 1);
const gIndex = g * (this.size - 1);
const bIndex = b * (this.size - 1);
// Use interpolation for non-integer indices
if (this.interpolation === 'trilinear') {
return this.trilinearInterpolation(rIndex, gIndex, bIndex);
} else {
return this.nearestNeighborLookup(rIndex, gIndex, bIndex);
}
}
// Trilinear interpolation for smooth color transitions
trilinearInterpolation(rIndex, gIndex, bIndex) {
const r0 = Math.floor(rIndex);
const r1 = Math.min(r0 + 1, this.size - 1);
const g0 = Math.floor(gIndex);
const g1 = Math.min(g0 + 1, this.size - 1);
const b0 = Math.floor(bIndex);
const b1 = Math.min(b0 + 1, this.size - 1);
const rFrac = rIndex - r0;
const gFrac = gIndex - g0;
const bFrac = bIndex - b0;
// Get 8 corner values
const c000 = this.table[r0][g0][b0];
const c001 = this.table[r0][g0][b1];
const c010 = this.table[r0][g1][b0];
const c011 = this.table[r0][g1][b1];
const c100 = this.table[r1][g0][b0];
const c101 = this.table[r1][g0][b1];
const c110 = this.table[r1][g1][b0];
const c111 = this.table[r1][g1][b1];
// Interpolate along each axis
const interpolateChannel = (channel) => {
const c00 = c000[channel] * (1 - bFrac) + c001[channel] * bFrac;
const c01 = c010[channel] * (1 - bFrac) + c011[channel] * bFrac;
const c10 = c100[channel] * (1 - bFrac) + c101[channel] * bFrac;
const c11 = c110[channel] * (1 - bFrac) + c111[channel] * bFrac;
const c0 = c00 * (1 - gFrac) + c01 * gFrac;
const c1 = c10 * (1 - gFrac) + c11 * gFrac;
return c0 * (1 - rFrac) + c1 * rFrac;
};
return {
r: Math.max(0, Math.min(1, interpolateChannel('r'))),
g: Math.max(0, Math.min(1, interpolateChannel('g'))),
b: Math.max(0, Math.min(1, interpolateChannel('b')))
};
}
// Create gamma correction LUT
createGammaLUT(gamma) {
for (let r = 0; r < this.size; r++) {
for (let g = 0; g < this.size; g++) {
for (let b = 0; b < this.size; b++) {
const rNorm = r / (this.size - 1);
const gNorm = g / (this.size - 1);
const bNorm = b / (this.size - 1);
this.table[r][g][b] = {
r: Math.pow(rNorm, 1 / gamma),
g: Math.pow(gNorm, 1 / gamma),
b: Math.pow(bNorm, 1 / gamma)
};
}
}
}
this.metadata.purpose = `Gamma correction (γ=${gamma})`;
return this;
}
// Create color temperature adjustment LUT
createColorTemperatureLUT(sourceTemp, targetTemp) {
const sourceWhite = this.calculateWhitePoint(sourceTemp);
const targetWhite = this.calculateWhitePoint(targetTemp);
const adaptationMatrix = this.calculateBradfordMatrix(sourceWhite, targetWhite);
for (let r = 0; r < this.size; r++) {
for (let g = 0; g < this.size; g++) {
for (let b = 0; b < this.size; b++) {
const rNorm = r / (this.size - 1);
const gNorm = g / (this.size - 1);
const bNorm = b / (this.size - 1);
// Convert RGB to XYZ
const xyz = this.rgbToXYZ(rNorm, gNorm, bNorm);
// Apply chromatic adaptation
const adaptedXYZ = this.applyMatrix(adaptationMatrix, xyz);
// Convert back to RGB
const adaptedRGB = this.xyzToRGB(adaptedXYZ.X, adaptedXYZ.Y, adaptedXYZ.Z);
this.table[r][g][b] = {
r: Math.max(0, Math.min(1, adaptedRGB.r)),
g: Math.max(0, Math.min(1, adaptedRGB.g)),
b: Math.max(0, Math.min(1, adaptedRGB.b))
};
}
}
}
this.metadata.purpose = `Color temperature: ${sourceTemp}K → ${targetTemp}K`;
return this;
}
// Create saturation adjustment LUT
createSaturationLUT(saturationFactor) {
for (let r = 0; r < this.size; r++) {
for (let g = 0; g < this.size; g++) {
for (let b = 0; b < this.size; b++) {
const rNorm = r / (this.size - 1);
const gNorm = g / (this.size - 1);
const bNorm = b / (this.size - 1);
// Convert to HSL for saturation adjustment
const hsl = this.rgbToHSL(rNorm, gNorm, bNorm);
hsl.s = Math.max(0, Math.min(1, hsl.s * saturationFactor));
// Convert back to RGB
const rgb = this.hslToRGB(hsl.h, hsl.s, hsl.l);
this.table[r][g][b] = {
r: Math.max(0, Math.min(1, rgb.r)),
g: Math.max(0, Math.min(1, rgb.g)),
b: Math.max(0, Math.min(1, rgb.b))
};
}
}
}
this.metadata.purpose = `Saturation adjustment (×${saturationFactor})`;
return this;
}
// Create color grading LUT
createColorGradingLUT(shadows, midtones, highlights) {
for (let r = 0; r < this.size; r++) {
for (let g = 0; g < this.size; g++) {
for (let b = 0; b < this.size; b++) {
const rNorm = r / (this.size - 1);
const gNorm = g / (this.size - 1);
const bNorm = b / (this.size - 1);
// Calculate luminance for tone mapping
const luminance = 0.299 * rNorm + 0.587 * gNorm + 0.114 * bNorm;
// Apply tone-specific adjustments
const shadowWeight = this.calculateToneWeight(luminance, 0, 0.3);
const midtoneWeight = this.calculateToneWeight(luminance, 0.3, 0.7);
const highlightWeight = this.calculateToneWeight(luminance, 0.7, 1.0);
const adjustedR = rNorm +
(shadows.r * shadowWeight) +
(midtones.r * midtoneWeight) +
(highlights.r * highlightWeight);
const adjustedG = gNorm +
(shadows.g * shadowWeight) +
(midtones.g * midtoneWeight) +
(highlights.g * highlightWeight);
const adjustedB = bNorm +
(shadows.b * shadowWeight) +
(midtones.b * midtoneWeight) +
(highlights.b * highlightWeight);
this.table[r][g][b] = {
r: Math.max(0, Math.min(1, adjustedR)),
g: Math.max(0, Math.min(1, adjustedG)),
b: Math.max(0, Math.min(1, adjustedB))
};
}
}
}
this.metadata.purpose = 'Color grading (shadows/midtones/highlights)';
return this;
}
// Combine multiple LUTs
combineLUTs(otherLUT) {
const combinedLUT = new ColorLookupTable(this.size, this.dimensions);
for (let r = 0; r < this.size; r++) {
for (let g = 0; g < this.size; g++) {
for (let b = 0; b < this.size; b++) {
// Apply first LUT
const intermediate = this.table[r][g][b];
// Apply second LUT to the result
const final = otherLUT.applyLUT(intermediate);
combinedLUT.table[r][g][b] = final;
}
}
}
combinedLUT.metadata.purpose = `Combined: ${this.metadata.purpose} + ${otherLUT.metadata.purpose}`;
return combinedLUT;
}
// Export LUT in various formats
exportLUT(format = 'cube') {
switch (format.toLowerCase()) {
case 'cube':
return this.exportCubeFormat();
case '3dl':
return this.export3DLFormat();
case 'csp':
return this.exportCSPFormat();
default:
throw new Error(`Unsupported export format: ${format}`);
}
}
// Export in .cube format (Adobe/Autodesk standard)
exportCubeFormat() {
let cubeData = `# LUT created by RGBmatic\n`;
cubeData += `# ${this.metadata.purpose}\n`;
cubeData += `# Created: ${this.metadata.created}\n\n`;
cubeData += `LUT_3D_SIZE ${this.size}\n\n`;
for (let b = 0; b < this.size; b++) {
for (let g = 0; g < this.size; g++) {
for (let r = 0; r < this.size; r++) {
const color = this.table[r][g][b];
cubeData += `${color.r.toFixed(6)} ${color.g.toFixed(6)} ${color.b.toFixed(6)}\n`;
}
}
}
return cubeData;
}
// Analyze LUT characteristics
analyzeLUT() {
const analysis = {
size: this.size,
totalEntries: Math.pow(this.size, 3),
colorRange: this.calculateColorRange(),
gamutMapping: this.analyzeGamutMapping(),
smoothness: this.analyzeSmoothness(),
neutralPreservation: this.analyzeNeutralPreservation(),
metadata: this.metadata
};
return analysis;
}
// Utility methods
normalizeColor(color) {
return {
r: Math.max(0, Math.min(1, color.r)),
g: Math.max(0, Math.min(1, color.g)),
b: Math.max(0, Math.min(1, color.b))
};
}
calculateWhitePoint(temperature) {
// Simplified Planckian locus calculation
const x = temperature >= 4000 ?
-4.607e9 / Math.pow(temperature, 3) + 2.9678e6 / Math.pow(temperature, 2) + 0.09911e3 / temperature + 0.244063 :
-2.0064e9 / Math.pow(temperature, 3) + 1.9018e6 / Math.pow(temperature, 2) + 0.24748e3 / temperature + 0.23704;
const y = -3 * x * x + 2.87 * x - 0.275;
return { x: x, y: y };
}
rgbToHSL(r, g, b) {
const max = Math.max(r, g, b);
const min = Math.min(r, g, b);
const diff = max - min;
const sum = max + min;
const l = sum / 2;
if (diff === 0) {
return { h: 0, s: 0, l: l };
}
const s = l > 0.5 ? diff / (2 - sum) : diff / sum;
let h;
switch (max) {
case r: h = (g - b) / diff + (g < b ? 6 : 0); break;
case g: h = (b - r) / diff + 2; break;
case b: h = (r - g) / diff + 4; break;
}
h /= 6;
return { h: h, s: s, l: l };
}
hslToRGB(h, s, l) {
const hue2rgb = (p, q, t) => {
if (t < 0) t += 1;
if (t > 1) t -= 1;
if (t < 1/6) return p + (q - p) * 6 * t;
if (t < 1/2) return q;
if (t < 2/3) return p + (q - p) * (2/3 - t) * 6;
return p;
};
if (s === 0) {
return { r: l, g: l, b: l };
}
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
const p = 2 * l - q;
return {
r: hue2rgb(p, q, h + 1/3),
g: hue2rgb(p, q, h),
b: hue2rgb(p, q, h - 1/3)
};
}
calculateToneWeight(luminance, rangeStart, rangeEnd) {
if (luminance < rangeStart || luminance > rangeEnd) return 0;
const center = (rangeStart + rangeEnd) / 2;
const width = rangeEnd - rangeStart;
const distance = Math.abs(luminance - center);
return Math.max(0, 1 - (distance / (width / 2)));
}
rgbToXYZ(r, g, b) {
// sRGB to XYZ conversion matrix
const X = 0.4124564 * r + 0.3575761 * g + 0.1804375 * b;
const Y = 0.2126729 * r + 0.7151522 * g + 0.0721750 * b;
const Z = 0.0193339 * r + 0.1191920 * g + 0.9503041 * b;
return { X: X * 100, Y: Y * 100, Z: Z * 100 };
}
xyzToRGB(X, Y, Z) {
X /= 100; Y /= 100; Z /= 100;
// XYZ to sRGB conversion matrix
const r = 3.2404542 * X - 1.5371385 * Y - 0.4985314 * Z;
const g = -0.9692660 * X + 1.8760108 * Y + 0.0415560 * Z;
const b = 0.0556434 * X - 0.2040259 * Y + 1.0572252 * Z;
return { r: r, g: g, b: b };
}
}One-dimensional LUTs operate on individual color channels independently. They're commonly used for gamma correction, contrast adjustment, and basic color grading. Each input value maps to a corresponding output value within the same channel.
Three-dimensional LUTs consider the interaction between all color channels, enabling complex color transformations like color space conversions, creative color grading, and device calibration. They provide more sophisticated control over color relationships.
Specifically designed for display and printer calibration, these LUTs correct device-specific color characteristics to achieve accurate color reproduction according to established standards.
LUTs can be generated mathematically using color science formulas for specific transformations like gamma correction, color temperature adjustment, or color space conversion.
Professional color grading software allows artists to create LUTs visually by adjusting colors and having the software generate the corresponding mathematical transformation.
Calibration LUTs are created by measuring device output and calculating the corrections needed to achieve target color values.
Modern graphics hardware provides dedicated LUT processing capabilities, enabling real-time color transformations for video playback and interactive applications.
Large 3D LUTs can consume significant memory. Optimization techniques include LUT compression, adaptive sizing, and efficient caching strategies.
Evaluating LUT smoothness helps identify potential banding or discontinuities that could affect image quality.
Assessing how well a LUT preserves the original color gamut or maps out-of-gamut colors appropriately.
Checking whether neutral colors (grays) remain neutral after LUT application, which is crucial for maintaining color balance.
Machine learning techniques are being developed to automatically generate LUTs based on content analysis and desired aesthetic outcomes.
Dynamic LUTs that adjust based on image content, viewing conditions, or user preferences for optimal color reproduction.
Research into 4D and higher-dimensional LUTs that consider additional factors like luminance, time, or viewing angle for more sophisticated color transformations.
Explore these comprehensive pillar articles related to Color Lookup Table (LUT)
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 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.
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 Lookup Table (LUT) and related color theory concepts
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.
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.
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 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 color terminology and concepts in our comprehensive glossary.
Browse Full Glossary