A comprehensive guide to exposure - the amount of light that reaches the camera sensor or image, controlling brightness and determining the overall tonal range and visual impact of digital images.
Exposure refers to the amount of light that reaches a camera sensor or the overall brightness level of a digital image. It's one of the fundamental concepts in photography and digital imaging, directly affecting image brightness, contrast, and the ability to capture detail in shadows and highlights.
Professional photo editing and enhancement tools powered by AI for photographers and content creators.
Remove backgrounds instantly • Resize without quality loss • Extract color palettes • Professional results
Exposure is controlled by three main factors:
// Exposure calculation and adjustment system
class ExposureProcessor {
constructor() {
this.canvas = document.createElement('canvas');
this.ctx = this.canvas.getContext('2d');
}
// Adjust exposure in stops
adjustExposure(imageData, stops) {
const { data, width, height } = imageData;
const result = new Uint8ClampedArray(data.length);
// Calculate exposure factor (2^stops)
const exposureFactor = Math.pow(2, stops);
for (let i = 0; i < data.length; i += 4) {
// Convert to linear space for accurate exposure math
const r = this.srgbToLinear(data[i] / 255);
const g = this.srgbToLinear(data[i + 1] / 255);
const b = this.srgbToLinear(data[i + 2] / 255);
// Apply exposure adjustment
const exposedR = r * exposureFactor;
const exposedG = g * exposureFactor;
const exposedB = b * exposureFactor;
// Convert back to sRGB space
result[i] = Math.max(0, Math.min(255, this.linearToSrgb(exposedR) * 255));
result[i + 1] = Math.max(0, Math.min(255, this.linearToSrgb(exposedG) * 255));
result[i + 2] = Math.max(0, Math.min(255, this.linearToSrgb(exposedB) * 255));
result[i + 3] = data[i + 3];
}
return new ImageData(result, width, height);
}
// Convert sRGB to linear space
srgbToLinear(value) {
return value <= 0.04045 ?
value / 12.92 :
Math.pow((value + 0.055) / 1.055, 2.4);
}
// Convert linear to sRGB space
linearToSrgb(value) {
return value <= 0.0031308 ?
value * 12.92 :
1.055 * Math.pow(value, 1 / 2.4) - 0.055;
}
// Advanced exposure with highlight rolloff
adjustExposureWithRolloff(imageData, stops, highlightRolloff = 0.5) {
const { data, width, height } = imageData;
const result = new Uint8ClampedArray(data.length);
const exposureFactor = Math.pow(2, stops);
for (let i = 0; i < data.length; i += 4) {
const r = this.srgbToLinear(data[i] / 255);
const g = this.srgbToLinear(data[i + 1] / 255);
const b = this.srgbToLinear(data[i + 2] / 255);
// Calculate luminance
const luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b;
// Apply exposure with highlight protection
let factor = exposureFactor;
if (luminance > highlightRolloff) {
// Reduce exposure factor for highlights
const rolloffAmount = (luminance - highlightRolloff) / (1 - highlightRolloff);
factor = exposureFactor * (1 - rolloffAmount * 0.5);
}
const exposedR = r * factor;
const exposedG = g * factor;
const exposedB = b * factor;
result[i] = Math.max(0, Math.min(255, this.linearToSrgb(exposedR) * 255));
result[i + 1] = Math.max(0, Math.min(255, this.linearToSrgb(exposedG) * 255));
result[i + 2] = Math.max(0, Math.min(255, this.linearToSrgb(exposedB) * 255));
result[i + 3] = data[i + 3];
}
return new ImageData(result, width, height);
}
// Calculate optimal exposure
calculateOptimalExposure(imageData, targetMidtone = 0.18) {
const { data, width, height } = imageData;
let luminanceSum = 0;
const pixelCount = width * height;
// Calculate average luminance
for (let i = 0; i < data.length; i += 4) {
const r = this.srgbToLinear(data[i] / 255);
const g = this.srgbToLinear(data[i + 1] / 255);
const b = this.srgbToLinear(data[i + 2] / 255);
const luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b;
luminanceSum += luminance;
}
const averageLuminance = luminanceSum / pixelCount;
// Calculate exposure adjustment needed
const exposureAdjustment = Math.log2(targetMidtone / averageLuminance);
return {
currentAverage: averageLuminance,
targetAverage: targetMidtone,
suggestedAdjustment: exposureAdjustment,
suggestedAdjustmentEV: Math.round(exposureAdjustment * 3) / 3 // Round to 1/3 stops
};
}
}// Advanced exposure with selective adjustments
class AdvancedExposureProcessor {
constructor() {
this.processor = new ExposureProcessor();
}
// Selective exposure adjustment by tone range
adjustExposureSelective(imageData, shadowsEV = 0, midtonesEV = 0, highlightsEV = 0) {
const { data, width, height } = imageData;
const result = new Uint8ClampedArray(data.length);
for (let i = 0; i < data.length; i += 4) {
const r = this.processor.srgbToLinear(data[i] / 255);
const g = this.processor.srgbToLinear(data[i + 1] / 255);
const b = this.processor.srgbToLinear(data[i + 2] / 255);
// Calculate luminance
const luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b;
// Calculate tone weights
const shadowWeight = this.calculateToneWeight(luminance, 'shadow');
const midtoneWeight = this.calculateToneWeight(luminance, 'midtone');
const highlightWeight = this.calculateToneWeight(luminance, 'highlight');
// Calculate blended exposure adjustment
const totalEV =
shadowsEV * shadowWeight +
midtonesEV * midtoneWeight +
highlightsEV * highlightWeight;
const exposureFactor = Math.pow(2, totalEV);
// Apply exposure
const exposedR = r * exposureFactor;
const exposedG = g * exposureFactor;
const exposedB = b * exposureFactor;
result[i] = Math.max(0, Math.min(255, this.processor.linearToSrgb(exposedR) * 255));
result[i + 1] = Math.max(0, Math.min(255, this.processor.linearToSrgb(exposedG) * 255));
result[i + 2] = Math.max(0, Math.min(255, this.processor.linearToSrgb(exposedB) * 255));
result[i + 3] = data[i + 3];
}
return new ImageData(result, width, height);
}
calculateToneWeight(luminance, toneRange) {
switch (toneRange) {
case 'shadow':
return luminance < 0.25 ?
Math.pow(1 - (luminance / 0.25), 2) : 0;
case 'midtone':
if (luminance >= 0.25 && luminance <= 0.75) {
const center = 0.5;
const distance = Math.abs(luminance - center);
return 1 - (distance / 0.25);
}
return 0;
case 'highlight':
return luminance > 0.75 ?
Math.pow((luminance - 0.75) / 0.25, 2) : 0;
default:
return 0;
}
}
// HDR tone mapping simulation
hdrToneMapping(imageData, method = 'reinhard') {
const { data, width, height } = imageData;
const result = new Uint8ClampedArray(data.length);
// Calculate scene luminance statistics
const luminanceStats = this.calculateLuminanceStats(data);
for (let i = 0; i < data.length; i += 4) {
const r = this.processor.srgbToLinear(data[i] / 255);
const g = this.processor.srgbToLinear(data[i + 1] / 255);
const b = this.processor.srgbToLinear(data[i + 2] / 255);
let mappedR, mappedG, mappedB;
switch (method) {
case 'reinhard':
mappedR = this.reinhardToneMap(r, luminanceStats);
mappedG = this.reinhardToneMap(g, luminanceStats);
mappedB = this.reinhardToneMap(b, luminanceStats);
break;
case 'filmic':
mappedR = this.filmicToneMap(r);
mappedG = this.filmicToneMap(g);
mappedB = this.filmicToneMap(b);
break;
default:
mappedR = r;
mappedG = g;
mappedB = b;
}
result[i] = Math.max(0, Math.min(255, this.processor.linearToSrgb(mappedR) * 255));
result[i + 1] = Math.max(0, Math.min(255, this.processor.linearToSrgb(mappedG) * 255));
result[i + 2] = Math.max(0, Math.min(255, this.processor.linearToSrgb(mappedB) * 255));
result[i + 3] = data[i + 3];
}
return new ImageData(result, width, height);
}
calculateLuminanceStats(data) {
const luminances = [];
for (let i = 0; i < data.length; i += 4) {
const r = this.processor.srgbToLinear(data[i] / 255);
const g = this.processor.srgbToLinear(data[i + 1] / 255);
const b = this.processor.srgbToLinear(data[i + 2] / 255);
const luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b;
luminances.push(luminance);
}
luminances.sort((a, b) => a - b);
return {
min: luminances[0],
max: luminances[luminances.length - 1],
average: luminances.reduce((sum, l) => sum + l, 0) / luminances.length,
median: luminances[Math.floor(luminances.length / 2)]
};
}
reinhardToneMap(value, stats) {
const scaledValue = value / stats.average;
return scaledValue / (1 + scaledValue);
}
filmicToneMap(value) {
// Simplified filmic tone mapping curve
const a = 2.51;
const b = 0.03;
const c = 2.43;
const d = 0.59;
const e = 0.14;
return Math.max(0, (value * (a * value + b)) / (value * (c * value + d) + e));
}
}// Exposure analysis and measurement tools
class ExposureAnalyzer {
constructor() {
this.processor = new ExposureProcessor();
}
// Generate luminance histogram
generateHistogram(imageData, bins = 256) {
const { data, width, height } = imageData;
const histogram = new Array(bins).fill(0);
const pixelCount = width * height;
for (let i = 0; i < data.length; i += 4) {
const r = this.processor.srgbToLinear(data[i] / 255);
const g = this.processor.srgbToLinear(data[i + 1] / 255);
const b = this.processor.srgbToLinear(data[i + 2] / 255);
// Calculate luminance
const luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b;
// Map to histogram bin
const bin = Math.min(bins - 1, Math.floor(luminance * bins));
histogram[bin]++;
}
// Normalize histogram
return histogram.map(count => count / pixelCount);
}
// Analyze exposure characteristics
analyzeExposure(imageData) {
const { data, width, height } = imageData;
const pixelCount = width * height;
let luminanceSum = 0;
let shadowPixels = 0;
let highlightPixels = 0;
let clippedShadows = 0;
let clippedHighlights = 0;
const luminances = [];
for (let i = 0; i < data.length; i += 4) {
const r = this.processor.srgbToLinear(data[i] / 255);
const g = this.processor.srgbToLinear(data[i + 1] / 255);
const b = this.processor.srgbToLinear(data[i + 2] / 255);
const luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b;
luminances.push(luminance);
luminanceSum += luminance;
// Count shadow and highlight pixels
if (luminance < 0.1) shadowPixels++;
if (luminance > 0.9) highlightPixels++;
// Count clipped pixels
if (luminance < 0.01) clippedShadows++;
if (luminance > 0.99) clippedHighlights++;
}
// Sort luminances for percentile calculations
luminances.sort((a, b) => a - b);
const analysis = {
averageLuminance: luminanceSum / pixelCount,
medianLuminance: luminances[Math.floor(luminances.length / 2)],
// Percentiles
p1: luminances[Math.floor(luminances.length * 0.01)],
p5: luminances[Math.floor(luminances.length * 0.05)],
p95: luminances[Math.floor(luminances.length * 0.95)],
p99: luminances[Math.floor(luminances.length * 0.99)],
// Pixel distribution
shadowPercentage: (shadowPixels / pixelCount) * 100,
highlightPercentage: (highlightPixels / pixelCount) * 100,
clippedShadowsPercentage: (clippedShadows / pixelCount) * 100,
clippedHighlightsPercentage: (clippedHighlights / pixelCount) * 100,
// Dynamic range
dynamicRange: Math.log2(luminances[luminances.length - 1] / Math.max(luminances[0], 0.001))
};
// Generate recommendations
analysis.recommendations = this.generateExposureRecommendations(analysis);
return analysis;
}
generateExposureRecommendations(analysis) {
const recommendations = [];
// Check for underexposure
if (analysis.averageLuminance < 0.1) {
const adjustment = Math.log2(0.18 / analysis.averageLuminance);
recommendations.push({
type: 'underexposed',
message: 'Image appears underexposed',
suggestedAdjustment: `+${adjustment.toFixed(1)} EV`,
severity: 'high'
});
}
// Check for overexposure
if (analysis.averageLuminance > 0.7) {
const adjustment = Math.log2(0.18 / analysis.averageLuminance);
recommendations.push({
type: 'overexposed',
message: 'Image appears overexposed',
suggestedAdjustment: `${adjustment.toFixed(1)} EV`,
severity: 'high'
});
}
// Check for clipped highlights
if (analysis.clippedHighlightsPercentage > 1) {
recommendations.push({
type: 'clipped_highlights',
message: `${analysis.clippedHighlightsPercentage.toFixed(1)}% of highlights are clipped`,
suggestedAdjustment: 'Reduce exposure or use highlight recovery',
severity: 'medium'
});
}
// Check for clipped shadows
if (analysis.clippedShadowsPercentage > 1) {
recommendations.push({
type: 'clipped_shadows',
message: `${analysis.clippedShadowsPercentage.toFixed(1)}% of shadows are clipped`,
suggestedAdjustment: 'Increase exposure or use shadow recovery',
severity: 'medium'
});
}
// Check dynamic range
if (analysis.dynamicRange < 6) {
recommendations.push({
type: 'low_dynamic_range',
message: 'Image has limited dynamic range',
suggestedAdjustment: 'Consider increasing contrast or using tone mapping',
severity: 'low'
});
}
return recommendations;
}
// Auto exposure correction
autoCorrectExposure(imageData, targetLuminance = 0.18) {
const analysis = this.analyzeExposure(imageData);
if (analysis.recommendations.length === 0) {
return imageData; // No correction needed
}
// Calculate correction based on average luminance
const correction = Math.log2(targetLuminance / analysis.averageLuminance);
// Apply gentle correction to avoid overcorrection
const gentleCorrection = correction * 0.7;
return this.processor.adjustExposure(imageData, gentleCorrection);
}
}// Complete exposure workflow for digital photography
class PhotographyExposureWorkflow {
constructor() {
this.processor = new ExposureProcessor();
this.advanced = new AdvancedExposureProcessor();
this.analyzer = new ExposureAnalyzer();
}
// Process image with complete exposure workflow
processImage(imageData, settings = {}) {
const {
autoExposure = false,
exposureAdjustment = 0,
shadowRecovery = 0,
highlightRecovery = 0,
useHDRToneMapping = false,
toneMappingMethod = 'reinhard'
} = settings;
let result = imageData;
// Step 1: Analyze current exposure
const analysis = this.analyzer.analyzeExposure(result);
console.log('Exposure Analysis:', analysis);
// Step 2: Auto exposure correction if requested
if (autoExposure) {
result = this.analyzer.autoCorrectExposure(result);
}
// Step 3: Manual exposure adjustment
if (exposureAdjustment !== 0) {
result = this.processor.adjustExposure(result, exposureAdjustment);
}
// Step 4: Shadow and highlight recovery
if (shadowRecovery !== 0 || highlightRecovery !== 0) {
result = this.advanced.adjustExposureSelective(
result,
shadowRecovery,
0,
-highlightRecovery
);
}
// Step 5: HDR tone mapping if requested
if (useHDRToneMapping) {
result = this.advanced.hdrToneMapping(result, toneMappingMethod);
}
return result;
}
// Batch process multiple images
batchProcess(imageDataArray, settings) {
return imageDataArray.map(imageData =>
this.processImage(imageData, settings)
);
}
// Generate exposure report
generateReport(imageData) {
const analysis = this.analyzer.analyzeExposure(imageData);
const histogram = this.analyzer.generateHistogram(imageData);
return {
timestamp: new Date().toISOString(),
analysis,
histogram,
summary: {
exposureQuality: this.assessExposureQuality(analysis),
primaryIssues: analysis.recommendations.filter(r => r.severity === 'high'),
suggestions: analysis.recommendations.map(r => r.message)
}
};
}
assessExposureQuality(analysis) {
const issues = analysis.recommendations.filter(r => r.severity === 'high').length;
const warnings = analysis.recommendations.filter(r => r.severity === 'medium').length;
if (issues > 0) return 'poor';
if (warnings > 1) return 'fair';
if (warnings === 1) return 'good';
return 'excellent';
}
}Explore these comprehensive pillar articles related to Exposure
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 Exposure 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