Gamma Correction + Code(Make images brighter or darker)

vahid_jani
3 min readSep 15, 2021

Recently I came through this problem that some images are so dark and we as humans can not get much information from it. The same applies to your deep learning model (you trained the model with normal images and now you need to do the prediction on dark images).

In this case, the information are there but the color values differences are too low to be detected by our eyes. So we use a technique called Gamma correction that tries to assign new values to pixel in order to make it more clear.

Lets start with some samples and plot the histograms of images (image histograms show the frequency of each value in an image).

example 1
image histogram for example 1

To get the histogram there are many ways but you need to have 1 value for each pixel (1 channel) since our sample images are colorful (3 Chanel), we need to convert them to grayscale or use a method in “numpy” called “ravel()”. It creates a 1D array from values (it keeps all 3 channel) and then we can plot it using pyplot. (code)

The mean and std are 123 and 69 for this image that shows a good distribution for the color values and no need for Gamma correction.

--

--