A comprehensive guide to gamut mapping - the process of transforming colors from one color gamut to another when the source contains colors that cannot be reproduced in the destination gamut, essential for accurate color reproduction across different devices and media in digital imaging workflows.
Gamut mapping is a critical process in color management that addresses the challenge of reproducing colors when the source color gamut contains colors that fall outside the destination gamut's reproducible range. This situation commonly occurs when converting between different color spaces, such as from a wide-gamut working space to a printer's CMYK gamut, or from an HDR display to a standard monitor. Effective gamut mapping algorithms preserve the overall appearance and color relationships while handling out-of-gamut colors in a visually pleasing manner.
Different devices and color spaces have different gamuts - the range of colors they can reproduce. When colors from a larger gamut need to be displayed or printed on a device with a smaller gamut, some colors will be out-of-gamut and cannot be reproduced exactly. Gamut mapping algorithms determine how to handle these problematic colors.
// Gamut Mapping System
class GamutMappingSystem {
constructor() {
// Gamut mapping algorithms
this.algorithms = {
'clipping': {
name: 'Nearest Point Clipping',
description: 'Maps out-of-gamut colors to nearest point on gamut boundary',
preserves: ['hue'],
characteristics: {
speed: 'very_fast',
quality: 'poor_to_moderate',
artifacts: 'clipping_artifacts',
best_for: 'simple_graphics'
}
},
'compression': {
name: 'Linear Compression',
description: 'Compresses entire gamut linearly to fit destination',
preserves: ['relationships', 'gradients'],
characteristics: {
speed: 'fast',
quality: 'moderate',
artifacts: 'desaturation',
best_for: 'photographs'
}
},
'cusp_knee': {
name: 'Cusp Knee Compression',
description: 'Applies knee compression near gamut boundary',
preserves: ['low_chroma_colors', 'hue'],
characteristics: {
speed: 'moderate',
quality: 'good',
artifacts: 'minimal',
best_for: 'mixed_content'
}
},
'sigmoidal': {
name: 'Sigmoidal Compression',
description: 'Uses S-curve compression for smooth transitions',
preserves: ['color_relationships', 'smooth_gradients'],
characteristics: {
speed: 'moderate',
quality: 'good_to_excellent',
artifacts: 'very_minimal',
best_for: 'high_quality_images'
}
},
'hpminde': {
name: 'HPMINDE Algorithm',
description: 'Hue-preserving minimum Delta E mapping',
preserves: ['hue', 'lightness_relationships'],
characteristics: {
speed: 'slow',
quality: 'excellent',
artifacts: 'none',
best_for: 'color_critical_work'
}
}
};
// Color space gamut definitions
this.colorSpaceGamuts = {
'sRGB': {
name: 'sRGB',
volume: 35, // % of visible spectrum
characteristics: {
red_primary: [0.64, 0.33],
green_primary: [0.30, 0.60],
blue_primary: [0.15, 0.06],
white_point: [0.3127, 0.3290]
},
typical_use: 'web_and_consumer_displays'
},
'Adobe_RGB': {
name: 'Adobe RGB (1998)',
volume: 50, // % of visible spectrum
characteristics: {
red_primary: [0.64, 0.33],
green_primary: [0.21, 0.71],
blue_primary: [0.15, 0.06],
white_point: [0.3127, 0.3290]
},
typical_use: 'professional_photography_and_print'
},
'P3': {
name: 'DCI-P3',
volume: 45, // % of visible spectrum
characteristics: {
red_primary: [0.68, 0.32],
green_primary: [0.265, 0.69],
blue_primary: [0.15, 0.06],
white_point: [0.314, 0.351]
},
typical_use: 'digital_cinema_and_wide_gamut_displays'
},
'Rec2020': {
name: 'Rec. 2020',
volume: 75, // % of visible spectrum
characteristics: {
red_primary: [0.708, 0.292],
green_primary: [0.170, 0.797],
blue_primary: [0.131, 0.046],
white_point: [0.3127, 0.3290]
},
typical_use: 'ultra_high_definition_television'
}
};
// Rendering intents and their gamut mapping preferences
this.renderingIntents = {
'perceptual': {
preferred_algorithm: 'sigmoidal',
priority: 'overall_appearance',
compress_all_colors: true
},
'relative_colorimetric': {
preferred_algorithm: 'clipping',
priority: 'colorimetric_accuracy',
compress_all_colors: false
},
'saturation': {
preferred_algorithm: 'cusp_knee',
priority: 'vivid_colors',
compress_all_colors: true
},
'absolute_colorimetric': {
preferred_algorithm: 'clipping',
priority: 'absolute_accuracy',
compress_all_colors: false
}
};
}
// Perform gamut mapping
performGamutMapping(sourceColors, sourceGamut, targetGamut, algorithm = 'sigmoidal', options = {}) {
const mapping = {
source_gamut: sourceGamut,
target_gamut: targetGamut,
algorithm: algorithm,
options: options,
source_colors: sourceColors,
mapped_colors: [],
mapping_statistics: {},
quality_metrics: {}
};
// Analyze source colors and gamut relationships
const gamutAnalysis = this.analyzeGamutRelationship(sourceGamut, targetGamut);
// Apply gamut mapping to each color
sourceColors.forEach((color, index) => {
const mappedColor = this.mapSingleColor(
color,
sourceGamut,
targetGamut,
algorithm,
options
);
mappedColor.original_index = index;
mappedColor.was_out_of_gamut = this.isOutOfGamut(color, targetGamut);
mapping.mapped_colors.push(mappedColor);
});
// Calculate mapping statistics
mapping.mapping_statistics = this.calculateMappingStatistics(
mapping.mapped_colors,
gamutAnalysis
);
// Assess mapping quality
mapping.quality_metrics = this.assessMappingQuality(
sourceColors,
mapping.mapped_colors,
algorithm
);
return mapping;
}
// Map single color using specified algorithm
mapSingleColor(color, sourceGamut, targetGamut, algorithm, options) {
const mapping = {
original_color: color,
mapped_color: null,
mapping_method: algorithm,
color_difference: 0,
mapping_applied: false
};
// Convert to device-independent color space (LAB)
const labColor = this.convertToLab(color, sourceGamut);
// Check if color is within target gamut
const isInGamut = this.isColorInGamut(labColor, targetGamut);
if (isInGamut) {
// Direct conversion for in-gamut colors
mapping.mapped_color = this.convertFromLab(labColor, targetGamut);
mapping.mapping_method = 'direct';
} else {
// Apply gamut mapping algorithm
const mappedLabColor = this.applyMappingAlgorithm(
labColor,
targetGamut,
algorithm,
options
);
mapping.mapped_color = this.convertFromLab(mappedLabColor, targetGamut);
mapping.mapping_applied = true;
}
// Calculate color difference
mapping.color_difference = this.calculateColorDifference(
labColor,
this.convertToLab(mapping.mapped_color, targetGamut)
);
return mapping;
}
// Apply specific mapping algorithm
applyMappingAlgorithm(labColor, targetGamut, algorithm, options) {
switch (algorithm) {
case 'clipping':
return this.applyClipping(labColor, targetGamut, options);
case 'compression':
return this.applyLinearCompression(labColor, targetGamut, options);
case 'cusp_knee':
return this.applyCuspKneeCompression(labColor, targetGamut, options);
case 'sigmoidal':
return this.applySigmoidalCompression(labColor, targetGamut, options);
case 'hpminde':
return this.applyHPMINDE(labColor, targetGamut, options);
default:
return this.applySigmoidalCompression(labColor, targetGamut, options);
}
}
// Clipping algorithm - map to nearest point on gamut boundary
applyClipping(labColor, targetGamut, options) {
const lchColor = this.labToLch(labColor);
const maxChroma = this.findMaximumChroma(lchColor.h, lchColor.L, targetGamut);
return this.lchToLab({
L: lchColor.L,
C: Math.min(lchColor.C, maxChroma),
h: lchColor.h
});
}
// Linear compression algorithm
applyLinearCompression(labColor, targetGamut, options) {
const compressionRatio = options.compressionRatio || this.calculateCompressionRatio(
targetGamut
);
const lchColor = this.labToLch(labColor);
return this.lchToLab({
L: lchColor.L,
C: lchColor.C * compressionRatio,
h: lchColor.h
});
}
// Cusp knee compression algorithm
applyCuspKneeCompression(labColor, targetGamut, options) {
const lchColor = this.labToLch(labColor);
const maxChroma = this.findMaximumChroma(lchColor.h, lchColor.L, targetGamut);
if (lchColor.C <= maxChroma) {
return labColor; // Already in gamut
}
// Apply knee compression
const kneePoint = maxChroma * (options.kneePosition || 0.8);
const compressionFactor = options.compressionFactor || 0.5;
let compressedChroma;
if (lchColor.C <= kneePoint) {
compressedChroma = lchColor.C;
} else {
const excessChroma = lchColor.C - kneePoint;
const maxExcess = maxChroma - kneePoint;
compressedChroma = kneePoint + (excessChroma / maxExcess) * maxExcess * compressionFactor;
}
return this.lchToLab({
L: lchColor.L,
C: compressedChroma,
h: lchColor.h
});
}
// Sigmoidal compression algorithm
applySigmoidalCompression(labColor, targetGamut, options) {
const lchColor = this.labToLch(labColor);
const maxChroma = this.findMaximumChroma(lchColor.h, lchColor.L, targetGamut);
if (lchColor.C <= maxChroma) {
return labColor; // Already in gamut
}
// Apply sigmoidal compression
const steepness = options.steepness || 2.0;
const normalizedChroma = lchColor.C / maxChroma;
// Sigmoid function: f(x) = 1 / (1 + e^(-k*(x-0.5)))
const compressedNormalized = 1 / (1 + Math.exp(-steepness * (normalizedChroma - 1)));
const compressedChroma = compressedNormalized * maxChroma;
return this.lchToLab({
L: lchColor.L,
C: compressedChroma,
h: lchColor.h
});
}
// HPMINDE (Hue-Preserving Minimum Delta E) algorithm
applyHPMINDE(labColor, targetGamut, options) {
const lchColor = this.labToLch(labColor);
let bestMapping = labColor;
let minDeltaE = Infinity;
// Search for mapping with minimum Delta E while preserving hue
const maxChroma = this.findMaximumChroma(lchColor.h, lchColor.L, targetGamut);
const searchSteps = options.searchSteps || 100;
for (let i = 0; i <= searchSteps; i++) {
const testChroma = (i / searchSteps) * maxChroma;
const testColor = this.lchToLab({
L: lchColor.L,
C: testChroma,
h: lchColor.h
});
const deltaE = this.calculateDeltaE2000(labColor, testColor);
if (deltaE < minDeltaE) {
minDeltaE = deltaE;
bestMapping = testColor;
}
}
return bestMapping;
}
// Analyze relationship between source and target gamuts
analyzeGamutRelationship(sourceGamut, targetGamut) {
const analysis = {
source_gamut: sourceGamut,
target_gamut: targetGamut,
volume_ratio: 0,
overlap_percentage: 0,
problem_areas: [],
mapping_complexity: 'low'
};
// Calculate volume ratio
const sourceVolume = this.colorSpaceGamuts[sourceGamut]?.volume || 50;
const targetVolume = this.colorSpaceGamuts[targetGamut]?.volume || 35;
analysis.volume_ratio = targetVolume / sourceVolume;
// Estimate overlap percentage
analysis.overlap_percentage = Math.min(100, analysis.volume_ratio * 100);
// Identify problem areas
analysis.problem_areas = this.identifyProblemAreas(sourceGamut, targetGamut);
// Assess mapping complexity
if (analysis.volume_ratio > 0.9) {
analysis.mapping_complexity = 'low';
} else if (analysis.volume_ratio > 0.7) {
analysis.mapping_complexity = 'moderate';
} else {
analysis.mapping_complexity = 'high';
}
return analysis;
}
// Compare gamut mapping algorithms
compareGamutMappingAlgorithms(sourceColors, sourceGamut, targetGamut) {
const comparison = {
source_gamut: sourceGamut,
target_gamut: targetGamut,
algorithm_results: {},
recommendations: {}
};
// Test each algorithm
Object.keys(this.algorithms).forEach(algorithm => {
const mapping = this.performGamutMapping(
sourceColors,
sourceGamut,
targetGamut,
algorithm
);
comparison.algorithm_results[algorithm] = {
mapping_results: mapping,
performance_score: this.calculatePerformanceScore(mapping),
visual_quality_score: this.calculateVisualQualityScore(mapping),
suitability_score: this.calculateSuitabilityScore(mapping, sourceColors)
};
});
// Generate recommendations
comparison.recommendations = this.generateAlgorithmRecommendations(
comparison.algorithm_results,
sourceColors
);
return comparison;
}
// Optimize gamut mapping parameters
optimizeGamutMapping(sourceColors, sourceGamut, targetGamut, algorithm, objectives = ['minimize_color_difference', 'preserve_gradients']) {
const optimization = {
algorithm: algorithm,
objectives: objectives,
parameter_space: this.defineParameterSpace(algorithm),
optimization_results: {},
optimal_parameters: {},
quality_improvement: 0
};
// Define parameter ranges for optimization
const parameterRanges = optimization.parameter_space;
// Perform grid search optimization
let bestScore = -Infinity;
let bestParameters = {};
this.gridSearchOptimization(parameterRanges, (parameters) => {
const mapping = this.performGamutMapping(
sourceColors,
sourceGamut,
targetGamut,
algorithm,
parameters
);
const score = this.calculateObjectiveScore(mapping, objectives);
if (score > bestScore) {
bestScore = score;
bestParameters = { ...parameters };
}
});
optimization.optimal_parameters = bestParameters;
optimization.optimization_results = this.performGamutMapping(
sourceColors,
sourceGamut,
targetGamut,
algorithm,
bestParameters
);
// Calculate quality improvement
const baselineMapping = this.performGamutMapping(
sourceColors,
sourceGamut,
targetGamut,
algorithm
);
optimization.quality_improvement = this.calculateQualityImprovement(
baselineMapping,
optimization.optimization_results
);
return optimization;
}
// LAB to LCH conversion
labToLch(lab) {
const C = Math.sqrt(lab.a * lab.a + lab.b * lab.b);
let h = Math.atan2(lab.b, lab.a) * 180 / Math.PI;
if (h < 0) h += 360;
return { L: lab.L, C: C, h: h };
}
// LCH to LAB conversion
lchToLab(lch) {
const a = lch.C * Math.cos(lch.h * Math.PI / 180);
const b = lch.C * Math.sin(lch.h * Math.PI / 180);
return { L: lch.L, a: a, b: b };
}
// Find maximum chroma for given hue and lightness
findMaximumChroma(hue, lightness, gamut) {
// Simplified gamut boundary calculation
const baseChroma = 100;
const lightnessReduction = Math.abs(lightness - 50) / 50;
const hueReduction = this.getHueReduction(hue, gamut);
return baseChroma * (1 - lightnessReduction * 0.3) * (1 - hueReduction * 0.2);
}
// Calculate Delta E CIE 2000
calculateDeltaE2000(lab1, lab2) {
const dL = lab1.L - lab2.L;
const da = lab1.a - lab2.a;
const db = 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 dC = C1 - C2;
const dH = Math.sqrt(da * da + db * db - dC * dC);
const SL = 1 + (0.015 * Math.pow(lab1.L - 50, 2)) / Math.sqrt(20 + Math.pow(lab1.L - 50, 2));
const SC = 1 + 0.045 * C1;
const SH = 1 + 0.015 * C1;
return Math.sqrt(
Math.pow(dL / SL, 2) +
Math.pow(dC / SC, 2) +
Math.pow(dH / SH, 2)
);
}
}The simplest approach maps out-of-gamut colors to the nearest point on the gamut boundary. While fast and preserving hue, clipping can cause loss of detail in saturated areas and create visible artifacts in smooth gradients.
These algorithms compress the entire source gamut to fit within the destination gamut. Linear compression maintains color relationships but may reduce overall saturation, while non-linear methods can preserve important color regions.
Modern gamut mapping often combines multiple techniques, applying different strategies based on the color's position within the gamut, the content type, and the specific requirements of the application.
Effective gamut mapping preserves important color relationships, ensuring that colors that appeared similar in the source remain similar in the destination, and that color gradients remain smooth.
Some colors are more visually important than others. Skin tones, memory colors (sky blue, grass green), and neutral colors often receive special treatment in gamut mapping algorithms.
The optimal gamut mapping strategy can depend on the image content, viewing conditions, and the specific source and destination gamuts involved.
Gamut mapping is typically performed in perceptually uniform color spaces like CIELAB or CIECAM02, where equal numerical differences correspond more closely to equal perceived differences.
Accurate gamut mapping requires precise definition of the source and destination gamut boundaries, often represented as lookup tables or mathematical models.
Advanced gamut mapping algorithms use optimization techniques to minimize perceptual color differences while maintaining important image characteristics.
Converting from RGB working spaces to CMYK print spaces requires sophisticated gamut mapping to handle the significant differences in gamut size and shape between additive and subtractive color reproduction.
Different display technologies (LCD, OLED, quantum dot) have different gamuts, requiring gamut mapping for consistent color appearance across devices.
The film industry uses gamut mapping to convert between different color spaces in the production pipeline, from camera capture through post-production to final display.
Gamut mapping quality can be assessed using metrics like average color difference, maximum color difference, and preservation of color relationships.
Human visual assessment remains important for evaluating gamut mapping performance, as the ultimate goal is to produce visually pleasing results.
Different types of content (photographs, graphics, text) may require different evaluation criteria and optimization strategies.
Some advanced systems analyze the specific colors present in an image and optimize the gamut mapping strategy accordingly, rather than using a fixed algorithm.
Spatially-aware gamut mapping considers the local context of colors within an image, potentially applying different mapping strategies to different regions.
For video content, gamut mapping must maintain temporal consistency to avoid flickering or color shifts between frames.
Explore these comprehensive pillar articles related to Gamut Mapping
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.
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.
Discover more about Gamut Mapping 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 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.
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.
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.
Discover more color terminology and concepts in our comprehensive glossary.
Browse Full Glossary