The Mystery of Gamma Correction
The Hidden Curve
When you read an RGB value of (128, 128, 128) from an image file, you might assume it represents exactly half the brightness of (255, 255, 255). It doesn't. It represents roughly 21.5% of the physical light intensity — less than a quarter. This discrepancy is gamma encoding, and ignoring it is one of the most common mistakes in color computation.
Why Gamma Exists
Gamma encoding has historical roots in CRT monitors, whose phosphors had a non-linear response to voltage — roughly a power curve of γ ≈ 2.2. Image files are encoded with the inverse curve (γ ≈ 1/2.2 ≈ 0.4545) so that the CRT's non-linearity cancels out and the image appears correct.
But there's a deeper reason gamma persists in the LCD era: it matches human vision. We're far more sensitive to differences in dark tones than bright tones. Gamma encoding allocates more of the 0–255 range to darks, where we can see the finest distinctions, and compresses the brights, where we're less discerning. It's a form of perceptual compression.
The Math Problem
When you calculate the average of two colors — say, blending (255, 0, 0) (red) and (0, 0, 0) (black) — doing it directly in gamma-encoded sRGB gives you (128, 0, 0). But physically, the correct midpoint requires linearizing first, averaging in linear space, then re-encoding:
Linear red = 1.0, linear black = 0.0. Average = 0.5. Re-encoded to sRGB ≈ (188, 0, 0). The difference is dramatic — the gamma-naive blend is visibly darker than it should be.
Linearization in Practice
The sRGB standard defines a precise transfer function (slightly more complex than a simple power curve, with a linear segment near black). To linearize:
For each channel, normalize to [0, 1], then apply: if V ≤ 0.04045, then V_linear = V / 12.92; otherwise V_linear = ((V + 0.055) / 1.055) ^ 2.4. The inverse (linear to sRGB) reverses this.
Every color operation — distance, blending, filtering, interpolation — should be performed in linear space. Only the final display value should be gamma-encoded. Getting this wrong produces muddy gradients, incorrect blends, and color distance calculations that are systematically biased toward dark tones.
Gamma and Dithering
Dithering algorithms are particularly sensitive to gamma. Floyd-Steinberg diffuses the error between the original color and the quantized result. If that error is calculated in gamma-encoded space, the algorithm over-corrects in darks and under-corrects in lights. The fix is simple: dither in linear space, then encode the final result.
The Takeaway
Gamma is not an obscure technical detail — it's the single most impactful correction you can make to any color algorithm. The difference between gamma-naive and gamma-correct processing is often more visible than the difference between different algorithms entirely.
Every color tool in the Lab linearizes before computing and re-encodes for display. The Color Theory Lab shows this explicitly: toggle linearization on and off to see how it affects distance calculations, blending, and palette generation.
Gerelateerde concepten
Gerelateerde artikelen
Perceptual Color Spaces: CIELAB and Delta E
Where Euclidean RGB distance fails because it ignores human biology, CIELAB succeeds. How the ΔE formula measures color differences in a way that feels human.
6 feb 2026
Dithering: Creating Illusions with Mathematics
When you have only a handful of colors, clever pixel placement can trick the eye into seeing thousands. A deep dive into error-diffusion dithering and the algorithms behind the illusion.
10 feb 2026
Probeer in het Lab
Verken Gerelateerde Secties
Gebruik deze secties om kunstwerken te ontdekken, technische context te lezen en het volledige ecosysteem van algoritmische kunst te verkennen.
