Wednesday, July 1, 2009

Enhancement by histogram manipulation

Not all images we capture have perfect contrast!... This is basically the motivation of this activity. Several techniques have been implemented in order to enhance images qualities. One of these is through histogram manipulation.
Histogram shows the pixel number in the image, each having one of the 256 possible values (1). The brightness of the images is shown in the histogram through the peaks in each pixel number. Histograms are manipulated by equalizing the distribution of the pixel numbers of the image. New brightness values are reassigned in the image's pixel numbers but the relationship among the pixel numbers are retained, that is, the pixels darker than other pixels still appear darker.

For this activity...

First thing I did: Find a grayscale image in the web. The chosen image is shown in Figure 1.
Reference:
http://images.google.com.ph/imgres?imgurl=http://www.atpm.com/13.02/images/ps-grayscale-4.jpg&imgrefurl=http://www.atpm.com/13.02/photoshop.shtml&usg=__ToqI_jVS80Y4k_ezF1QCq2TI03k=&h=280&w=420&sz=44&hl=tl&start=116&sig2=JetPq2CRGpzxKvLgJe0AMg&um=1&tbnid=lpf4uDD45kW5kM:&tbnh=83&tbnw=125&prev=/images%3Fq%3Dgrayscale%252Bblur%2Bimage%26ndsp%3D20%26hl%3Dtl%26client%3Dfirefox-a%26rls%3Dorg.mozilla:en-US:official%26sa%3DN%26start%3D100%26um%3D1&ei=pWFJSqCEF4_6kAXB67TwCQ

Justify FullFigure 1. Original image

My main goal in this activity is to enhance the image above. To achieve this, I used Scilab and find the histogram of the image, the normalized probability distribution function (PDF) of the graylevel. Then, the PDF of the image is taken by simply dividing the frequencies by the total number of pixels of the image. The cumulative sum of the PDF is the Cumulative Distribution Function (CDF). Figures 2 and 3 show the histogram and CDF of the image, respectively.
Figure 2. Histogram of the image
Figure 3. CDF of the image
Each graylevel has a corresponding PDF value. In order to enhance the image, I created a desired CDF. In my case, I used the equation of a straight line. The figure below is my desired CDF.
Figure 4. Desired CDF
Each value in the image's CDF is then matched with the value of the desired CDF. I did this by looking for the y-values of the CDF of the image that are equal to the y-axis of the desired CDF and then getting the grayscale value of the desired CDF and put these in a new matrix having the same size as the image.
After reconstructing the image, I look for its corresponding histogram and CDF. The CDF of the new image must be in close relation with the desired CDF.

Figure 5. Collated results of the simulation


Code:
image=imread('act4 picture.jpg');
subplot(241)
imshow(image,[]);
//histogram
H=[];
counter=1;
for i = 0:255;
num=find(image==i);
H(counter)=length(num);
counter=counter+1;
end;
I=[1:256];//graylevel
subplot(242);
hist=plot(0:255,H);

//CDF of the image
tot=cumsum(H/length(image));
subplot(243);
cdf=plot(0:255,tot);

//desired CDF
j=[0:1:255];
slope=1/255;
line=slope*j;
subplot(244);
plot(j,line);

//mapping
s=size(image);
mat=spzeros(s(1),s(2));
for j=[1:length(I)];
mat=mat+round(bool2s(image==I(j))*tot(j)/slope);
end;

subplot(245);
imshow(mat,[]);

//histogram of the reconstructed image
new=[];
c=1;
for i = 0:255;
num2=find(mat==i);
new(c)=length(num2);
c=c+1;
end;
subplot(246);
hist2=plot(0:255,new);
//CDF of the new image
tot2=cumsum(new/length(mat));
subplot(247);
cdf2=plot(0:255,tot2);

The code was implemented to other images and these are the results.


Figure 6. The first three columns in the first row show the details of the original images, that is, the histogram and CDF. The fourth column is the desired CDF and the second row shows the reconstructed image with its corresponding histogram and CDF.
The human eyes respond to light in a nonlinear behavior. Thus, choosing a CDF that fits the behavior of the human eyes, logarithmic function [y=log(x)] is applicable. Replacing the desired CDF from a straight line into a logarithmic function, I arrived at the following results below.

Figure 7. left- original image; right- reconstructed image
It can be noticed from the reconstructed images still show good contrast but are brighter at some regions. This shows that the histograms of these reconstructed images are evenly distributed to the different gray levels, only that some gray level occurs more frequently than others at larger diffferences.

I would like to acknowledge Gary Carcia, Jica Monsanto and Jaya Combinido for helping me improve my code and giving constructive criticisms to my work.
I think I have performed all the tasks needed for this activity. So I am giving myself a grade of 10.

Additional Information:
I have found an article which performed image contrast enhancement based on the generalized histograms by relaxing the restriction of using the integer count. The abstract of the paper reads,

"We present an adaptive contrast enhancement method based on the generalized histogram, which is obtained by relaxing the restriction of using the integer count. For each pixel, the integer count 1 allocated to a pixel is split into the fractional count and the remainder count. The generalized histogram is generated by accumulating the fractional count for each intensity level and distributing the remainder count uniformly throughout the intensity levels. The intensity mapping function, which determines the contrast gain for each intensity level, is derived from the generalized histogram. Since only the fractional part of the count allocated to each pixel is
used for increasing the contrast gain of its intensity level, the amount of contrast enhancement is adjusted by varying the fractional count according to regional characteristics. The proposed
scheme produces visually more pleasing results than the conventional histogram equalization."
Title: Image contrast enhancement based on the generalized histogram
Authors: Byoung-Woo Yoon and Woo-Jin Song

References and Image url:
1. J. Russ, The Image Processing Handbook, Fifth Edition, CRC Press.
http://incisors.files.wordpress.com/2008/06/truecolor.jpg
http://www.dolphinsc.com/images/Dolphin.jpg

No comments:

Post a Comment