Saturday, March 12, 2016

Gamma coding

Humans are more sensitive to relative differences between darker tones compared to relative differences between lighter ones.  This is some kind of power law. 

If we simply linearly encode the image for all hues, we need to allocate too many bits to store it and also cause too much bandwidth to transmit it.  Assuming humans can respond to luminescence values 100 to 1 and can detect the contrast ratio of two values that exceed 1% or 1.01 delta, we need to encode values 1, 1.01, 1.02, .... 99.09, 100 and the total number of codes needed is 99/0.01 or 9900 codes or 14 bits for each tone. We also end up using few bits to shadow values that humans are sensitive to and that will be lost opportunity to improve the quality. We use more bits to portions that humans are not sensitive to and that will be additional cost with no improvement to visual quality. So linear encoding is not good from both the compression and quality point of view.

If we use the observation that most highlights cannot be differentiated by humans, we can employ nonlinear encoding.  If we encode only ratios starting from 1,  1 + 0.01, (1+0.01)^2, ... , then we need just  log(100)/log(1.01) or around 462 codes or nine bits. If a television or display has only contrast ratio of 50:1, then it is just eight bits.

Power law :  Vout = Vinγ

Gamma(γ) is slope of log plot of input and output. Most of our images are encoded with 0.45 gamma value and decoded with 1/0.45 or 2.2  gamma value.  There is another power law in place in CRT based display monitors. The light produced on the display is approximately proportional to the applied voltage raised to the 2.5 power. This is also called gamma. This is amazing coincidence that vision gamma or image gamma is kind of inverse to display or monitor gamma. The net effect of applying both gammas is called system gamma and ideally should be 1.0. 


Gamma correction
Gamma FAQ
System gamma

No comments: