OpenCV – Gamma Correction

February 23, 2011

Gamma correction (also known as power transformation) is used in image processing in several situations. The classic example where gamma correction is needed is in CRT monitors. In CRTs the amount or intensity of light from the phosphor in the screen is related to voltage as

Output = Voltage crt_gamma

Hence if we give a linear or normal image to the CRT, the image would be look much too dark. In order to mitigate this effect, we “gamma correct” the image such a way that the image output looks well. All we do is something opposite to what the CRT does.

gamma_correc_image = image(1/crt_gamma)

For most CRTs, the crt_gamma is somewhere between 1.0 and 3.0.

Now lets delve into the code. The code given below is just to explicit to understand (I believe).

Share this:

Like this:

Related

Hi, I am trying to implement the gamma transformation. My code is very similar to your code but for some reason is not working. I tried yours also but it is not working as well. Using your code, I tried with gamma=2 and with an image where the intensity increases horizontally from 0 to 255, that is, it is a gray scale image. I expected to obtained a similar image, but I obtain a black and white image. Maybe, you can help to understand which is the problem.

I believe the code I have given here works well. If you give a greyscale image with intensity varying uniformly from 0 to 255, and give gamma = 2, you will get a non uniformly varying intensity for the output image. I have not got the point that you have put up here. How can you get a black and while image? Maybe if you upload the input and output images somewhere on internet, I may be able to help you.

Hi, I am trying to apply gamma correction to a constant stream of images coming in from my feed. I understand how to apply the correction but I am not sure what value to use. You are using ‘2’ but these images can sometimes have good or bad contrast to start from. Is there a way of ‘reading’ a ‘poor’ image and then applying when the adjustable gamma ‘figure’ ?