III – Gamma Correction

Gamma correction is a non-linear adjustment to individual pixel values. While in image normalization we carried out linear operations on individual pixels, such as scalar multiplication and addition/subtraction, gamma correction carries out a non-linear operation on the source image pixels, and can cause saturation of the image being altered. Furthermore, it can also lead to poor contrast if the gamma value is too large or too small. Nonetheless, it is still an important operation to cover.

Many people have likely encountered this term before while adjusting their new television set or playing around with advanced video settings in PC games. At first glance, gamma correction appears to either darken or brighten an image, but this is a gross oversimplification. We can already adjust the average brightness of an image by some modified normalization algorithm, the simplest of which would be simply adding a constant value to each pixel intensity value, effectively “shifting” the mean pixel intensity values across the entire image. Gamma correction is an operation that effectively carries out an exponential function on individual pixel values.

Before continuing, let’s consider the case of a “black and white” television set. Assuming it acts as a simple output device, we’d expect it to display, say, a black pixel wherever we specify a pixel intensity value of zero (0), and a white pixel wherever we specify an intensity value of one (1). All values inbetween 0 and 1 are shades of gray. With many (if not all) graphical display devices, this is not the case. Although we have specified that we want a specific color at a certain pixel location, due to imperfections in the display device, the actual color we see on-screen is not the exact color we desire. The diagram below shows a grayscale spectrum, along with the “transfer function” of an ideal display device to its right. For the transfer function plot to the right, consider the x-axis to be the color we want to appear on-screen, while the y-axis represents the color intensity value that is actually displayed. For the grayscale spectrum on the left, this shows an approximation of how “rapidly” output intensity values shift from black to white. In the case of the ideal display device below, the desired output intensity value is exactly the one we specified.

Normal Image Intensity Values – Gamma=1.0

Now consider an old television set that is on its last legs. Due to worn out components, everything appears darker than it should, as demonstrated below.

Darker Image – Gamma=2.0

Finally, consider the case of a new TV that is far too bright. The Output spectrum and transfer function are shown below.

Brighter Image – Gamma=0.5

The MATLAB code shown below was used to generate the images shown above.


For a more mathematical analysis, consider any arbitrary pixel on a display device. The grayscale intensity value we actually see is defined as y, and the intensity value we want to appear on the screen (in our code) is defined as x. Finally, the gamma value is defined as \gamma. The relationship between the input and output intensity values can be described by the equation below. A table of figures representing the transfer function of gamma correction for varying values of gamma is shown below for emphasis.

  • y = x^{\gamma}

Varying gamma values

In the ideal case, with \gamma=1, our input and output intensity values match perfectly, as in the case of the ideal display described at the top of the page. As the gamma value deviates from unity, we begin to notice a significant difference in the input and output intensity values. As gamma approaches zero, the output pixels become brighter, while as gamma approaches infinity, the pixels become darker. Gamma correction essentially carries out the inverse function of the exponential operation caused by imperfections in the display device.

For an example, consider we are using a display which, by observation, we assume is introducing gamma distortion corresponding to a gamma value of \gamma. This means that when we specify a pixel value to appear on-screen, it shows up with a (distorted) pixel value of  y = x^{\gamma}. If we carry out the inverse of this opertion in advance, prior to displaying the pixel on-screen, we can compensate for the gamma adjustment due to the display. This is equivalent to y = (x^{\gamma})^{1/\gamma}=x.

This is a very simple and straightforward algorithm to implement, and is demonstrated below, complete with sample images. The real trick with gamma correction is determining the gamma value to use in practise. You can either design algorithms to compute the ideal gamma value mathematically, or you can simply “guess and test” values and evaluate the results yourself. This subject extends beyond the scope of this subsection, and will be covered in future tutorials.



Sample image with varying gamma values

2 thoughts on “III – Gamma Correction

  1. Dear GIASSA,
    it was a great tutorial. i have some question about it. may i ask them please?
    actually i am going to find gamma value by some data as input and some data as target. i used lsqnonlin to fit value of gamma, shift and scale value. i have some question about that. can i ask u?

Leave a Reply

Your email address will not be published. Required fields are marked *