In image processing, Contrast enhancement is done due to the limit of human’s visual system. Details in a raw image can’t be easily determined unless it has a fine contrast. It is done by changing the brightness levels of each pixels in the image. In this process, the histogram of the gray levels of an image is manipulated such that the values are spread out entire the range of brightness values. In this activity, a raw truecolor image is enhanced by histogram manipulation. A dark image was chosen so as to observe a significant difference in the raw and enhanced images. The image used is a shot taken in Enchanted Kingdom. 🙂
Figure 1. Raw truecolor image (original image)
Using Scilab 4.0, the grayscale of the image was obtained via gray_imread(). The histogram of the image was then generated. It was done by using the histplot() function which takes the x values and the input image . Instead of displaying gray level values from 0 to 255, I used 0 to 1 so that the values are already normalized. It can be observed that the values are saturated to the left of the image which is due to the fact that there is a lot of dark areas in the image.
Figure 2. Histogram of original image
Normalizing the histogram, the tabul() function was used to obtain the frequencies of the values in a vector or matrix. The total frequency of all the values in the y axis is obtained then divided to the maximum value. The x and new y values are then plotted.
Figure 3. Normalized histogram of original image
The normalized histogram is now the Probability Distribution function (PDF) of the grayscale image. From this the Cumulative Distribution function (CDF) of the image was obtained. It was done by using the cumsum() function in Scilab which basically obtains the cumulative sum of a vector/matrix. This CDF can be altered to take the form of a desired CDF by backprojection.
Figure 4. Cumulative Distribution function (CDF) of original image
The CDF of an image with a uniform distribution is a straight line with a positive slope. So the desired PDF has a linear CDF.
Figure 5. CDF of a uniform distribution
Backprojection was done in Scilab (refer to code below) using the function interp1(). It takes three inputs: the x (Ax) and y (Y) values of the image’s CDF and the grayscale values (ix) of the image itself. Given the grayscale values, the function interpolates its corresponding yp values linearly. The interpolation is defined by the x and y values. The yp values is then used to create a new matrix image with the same size as the original image. This results to the enhanced image shown below.
//backprojection [r c] = size(I); ix = I(:); yp = interp1(Ax,Y,ix); Im = matrix(yp, [r c]);
Figure 6. Image with a Linearly modified CDF/uniform distribution
This is now the image with a uniformly distributed CDF. The manipulated grayscale image is more detailed compared to the original image.
Figure 7. Histogram of the image having a CDF of a uniform distribution
The histogram of the modified image is now like this. Compared to the original histogram, the grayscale levels are now distributed over all values.
Figure 8. The modified CDF of the image
As expected, we see that the CDF is now linear! Thus, backprojection worked and the result is really an equalized image. 🙂 But what if the desired CDF is Non-linear? What would the result be?
It is essential that we know the result of a Non-linear modification in images since the human eye has a non-linear response. So using a nonlinear function, say an exponential function exp(-x^2) which is a Gaussian, a nonlinear CDF was generated.
Figure 9. CDF of a Non-linear function (Exponential Gaussian)
Using the same process, backprojection was done but this time the reference ‘x’ values for the interpolation is the interpolated values from the linearly modified image. In contrast to the linearly modified image, the non-linear is darker but the details can still be seen. This is due to the Gaussian distribution function used.
Figure 10. Resulting image with a non-linear CDF
Comparing the original (grayscale) image with the modified images, it can be observed that the details at the background emerged from the darkness. Initially the trees and the other structures can’t be seen.
Figure 11. Comparison of the original grayscale image (left), linearly modified image (center), and the non-linearly modified image (right).
Histogram manipulation can be also done in advanced image processing software, such as GIMP (the same software used in the past activity). Basically, the image was set to Grayscale mode (Image->Mode->Grayscale) and the Color curves was modified (Colors->Curves). The initial color curve of the image is linear. The series of images shows the effect of altering the color curves of the grayscale images
Figure 12. The different effects of altering the color curves in the grayscale image using GIMP software.
The ‘Value’ option for the Channel adjusts the image’s brightness. So raising or lowering a point in the curve increases or decreases the intensity of the image’s brightness (as shown in the images above). Another imaging processing software that I have been using is Photoscape (also a freeware *yay!*). And it also has a histogram manipulation feature. It works the same way as in GIMP but instead of a ‘Value’ option, the Red, Green, and Blue checkbox is selected.
Figure 13. The different effects of altering the color curves in the grayscale image using Photoscape software.
Pulling the curve upwards, increases the image’s brightness while pulling it downward, decreases the brightness. Photoscape has an additional feature that is able to save the modified Color curve having the file format ‘.curves’. When opening an image, the color curve can be loaded and applied to the current image being edited.
Figure 14. Snapshot of how to store the modified curve in Photoscape.
Histogram manipulation is one way of improving the quality of the image, especially in extracting the details. It can also be used to copy the response of the human eye to luminance.
For this activity, I give myself a 10. 😀