Gamma Correction

Gamma Correction


It is not a widely enough known fact that the intensity response of a standard computer monitor is not linear.

Pardon? What I mean to say is that if you plot a pixel of intensity 128, it does not appear twice as bright as a pixel of intensity 64. This fact means that many images are not displayed well on a computer. This can especially spoil carefully computer generated images. It is possible to adjust the intensity of the pixels on the screen so that they are displayed at the correct intensities relative to each other.


Let these eight little pictures demonstrate. Each picture consists of two halves. The left half contains an even mix of pixels, half of which are intensity 0, half are intensity 255. This will correctly appear as intensity 128 if you squint a bit. The other half of the picture contains a solid colour. The first picture (top left) contains intensity 128. The last image has intensity 183. You will notice that, in the first image, the solid colour seems to be darker than the left half, even though it is intensity 128.
Throughout the 8 images, the intensity of the solid colour increases. By finding the intensity which most closely matches, you can determine the level of Gamma Correction required by your monitor.
This might not work well if you are viewing this on an 8-bit screen mode. I suggest using a High or True colour mode.

Different monitors have different responses, so in the case of a single image, you will have to make an adjustment which will best suit a wide range of monitors. In software, however, you can have an interactive adjustment so that the user can match the displayed images to their own hardware.


Intensity Response

This is an approximated curve to show how the intensity response of a monitor is non linear. Dark colours tend to be displayed too dark. This can be corrected.

Also note that the curve does not go through the origin. A black pixel on a monitor is not totally black. There is not very much you can do about that.



The process of adjusting the intensities to look correct is known as Gamma Correction. The process is a simple one, and need not be done in realtime, as creating a lookup table requires only a little space.

The amount of Gamma Correction we shall call g is usually greater than 1. The range of displayable intensities, i, is between 0 and 1. The formula is thus:
		pixel = i ^ (1/g)
A g value of 1 gives no Gamma Correction. Higher values give more correction.

Because values of i must be between 0 and 1, you will have to divide the intensity by the maximum displayable intensity, perform the Gamma Correction, then multiply up again.
		pixel = ((i / MaxIntensity) ^ (1/g)) * MaxIntensity