Image Processing in C#: Part 5 - Adjusting the Gamma
Gamma correction has a history based on the properties of CRT’s and was first noted in televisions.
The light intensity of a CRT is not directly proportional to the input voltage, but is rather proportional to the input voltage raised to a particular power. This power was known as gamma, and varied with CRT. The value was usually around 2.5.
This means that different CRT’s (televisions and monitors before the flatscreen days) all showed the same images slightly differently, and gamma correction was implement to correct this.
A gamma filter works by creating an array of 256 values called a gamma ramp for each value of the red, blue and green components. The gamma value must be between 0.2 and 5.
The formula for calculating the gamma ramp is 255 * (i / 255)1/gamma + 0.5.
If this value is greater than 255, then it is clamped to 255. It is possible to have a different gamma value for each of the 3 colour components.
Then for each pixel in the image, we can substitute the value in this array for the original value of that component at that pixel.
The full source used in the series is available from https://github.com/sjmeunier/image-processor.
Originally posted on my old blog, Smoky Cogs, on 19 Nov 2009