Thursday, July 2, 2009

Activity 4 Enhancement by Histogram Manipulation

During my senior year in high school I chose this visual communication class as my elective, and one of our activities were photography. At that time we were required to use a classic SLR camera which was shared by 3 people per group. It was a really fun activity but there were also some very frustrating moments. I clearly remember times when our shots were either to bright or too dark. Since we were newbies, we had a very hard time getting the exposure time, flash, and aperture size correctly. To add to our difficulties, we could only see the pictures ones we had them developed. This resulted to us spending money on buying rolls and rolls of film which really burned our pockets. At that time I would really have appreciated anything that would give me the ability to improve my shots which did not include taking more pictures and buying more film. Here I am now, five years later, doing the exact activity that could have saved me money five years ago.

In this activity we are tasked to improve or enhance the contrast of grayscale images by histogram manipulation. We do this by obtaining the images histogram or probability distribution function(PDF) and, from here, calculating its cumulative distribution function (CDF). Then to improve the image we map its current CDF to the CDF of our desired PDF which we believe would improve the image. This mapping of the CDF is done in 3 steps:
  1. We take the grayscale value of a pixel i and locate its value in the CDF, cdf(i).
  2. We then match this CDF value, cdf(i), to the desired CDF and locate its corresponding grayscale value.
  3. Finally we replace the existing grayscale value of the pixel with the new one obtained in step 2.
The final result of this mapping would be a new image which would have a CDF similar in shape to the mapping CDF.

There are also other simpler methods of enhancing an image, such us simple contrast stretching. I used this method before, during my old research topic, to fully utilize all 8bits. In this method we simply take the minimum and maximum values of the image and implement the algorithm:
Image = (Image - min(Image))/(max(Image) - min(Image)).
This method is considerably much simpler both theoretically and computationally but its use is very limited. It works by taking your range of values, from minimum to maximum, and stretching it so that you will use all 8bits or 256 grayscale values. This being the case you can only use this if the image doesn't already have a value of 256 and 0, otherwise you would have to do some thresholding and truncate the higher and lower values. This would then cause some loss of possibly useful information.

The images below are the results of the enhancements using CDF mapping. The first column shows the original image and its normalized PDF and CDF. Whereas the second and third column shows the result after CDF mappings on a linear CDF and logarithmic CDF respectively.

The first CDF mapping enhancement made use of a linear CDF which corresponds to a flat PDF. A flat PDF means that all gray values have equal probability, in other words a detector having such a PDF would have no bias on any grayscale value. According to our Proffesor, Dr. Soriano, research grade cameras would ideally have a linear CDF. But she also said that such a camera would usually show a dark image which would not appeal to most people. Still this makes sense since in research accuracy and calibration is important, so having a favored range of grayscale values would make it difficult for the researcher. The other CDF mapping made use of a logarithmic CDF because according to John C. Russ the human eye has a logarithmic response [1].


Figure 1


Figure 2


Figure 3


Figure 4


Figure 5

Before commenting on the results of the enhancements I would first like to note that by looking at the plots of the CDF we are assured that the implemented algorithm works correctly since the resulting CDFs match the theoretically expected.

By examining figures 1-5 we can see that in general the linear CDF works very well as an image enhancing tool. As expected all of the 5 images had a better contrast compared to the original.; this observation is supported by the resulting PDF of grayscale values. A broader PDF means that the image makes use of a wider range of grayscale values which is could for higher contrast and detail. Such a result was achieved in all of the pictures and specially for figures 4 and 5. Looking at the images we can easily see that most of them did not only had a better contrast but also had more distinguishable detail. Only figure 2 did not fair as well as the others. Though the image had a much better contrast, some of the detail previously seen was lost after enhancement.

As for the logarithmic CDF mapping, it is clearly seen that it did not fair as well as the linear one. It is true though that the CDF indeed looked match a logarithmic curve, still the image contrast actually suffered after the enhancement. All of these 5 images became much darker than the original and most of their detial became indistinguishable. Also when we look at their resulting PDF we see that it is concentrated on the dark values just like the image. This result should have been expected since this logarithmic curve has a most of its values in the lower x axis, or the dark region. Probably if we stretch the logarithmic curve a little it might result to a much better enhancement.

I tried various types of nonlinear CDFs, such as parabolic, exponential, cubed, and cube root, hoping to find one that would enhance all of the grayscale images that I tried. Soon enough I realized that such a CDF does not exist, or at least it is beyond me. What I did learn though was that a CDF would enhance your image if it stretched your histogram in the range of your region of interest. That is if you have little experience, such as myself, it would be better to look at the histogram and determine which range corresponds to your ROI. Then look for a CDF that would stretch this region and this would amount to a very good ehnacement.

I would like to thank Dr. Soriano for giving me very useful insights. I also thank Dr. Perez for helping me understand what to do. Finally I thank Jaya, Master, and Jica for the discussions and the laughs while doing this activity.

I also thank and award myself with a grade of 10. Thank you very much... HAHAHA!

Reference:
[1] Russ, John C. "The image processing handbook" 5th Edition, Taylor and Francis Group, CRC Press 2006-12

No comments:

Post a Comment