In this activity, we were to produce the histogram equalized images of raw grayscale pictures using backprojection from raw image cumulative distribution functions (CDF) on an ideal CDF. We are also to create and apply a CDF that can represent the nonlinear response of the human eye to images.
All image processing was done on Scilab with the SIP toolbox. Images were first imported using imread, which imports the matrix of pixel values that make up the images. To get the CDF of the image, we first determine its PDF, which is just the histogram normalized with respect to the number of pixels in the image. The pixel value frequency count was determined using the tabul command. tabul only lists frequency counts for pixel values that do exist in the image matrix, it is possible that pixel values will be skipped. To fill up the skipped pixel values with frequency counts of zero and to set the pixel value range to 0 to 255:
allpxvals = [0:1:255];
allvalfreq = allpxvals*0;
for j = allpxvals,
allvalfreq = allvalfreq + (bool2s(allpxvals==j)*(valfreq(find(pxvals==j))));
end;
We then calculate the CDF per pixel value r as in the equation below (p1 is the PDF):
which is equivalent to the cumsum command in Scilab applied on the CDF of the image.
We then need an "ideal" CDF for the transformation. For the linear enhancement, we simply create an array from 0 to 255 to match the pixel values and normalize it by the total number of pixels (Figure 1).
We then finally do backprojection by matching image CDF and ideal CDF values and replacing the respective image pixel value with the pixel value from the ideal CDF (Figure 2).

Figure 2. Backprojection example.
CDF value matching may be attained using the vectorfind function, which searches a certain value on a given array. But since the values calculated for the ideal CDF array are finite, not all image CDF values may be matched with the ideal CDF values. Hence, it is easier to simply invert the equation for the ideal CDF and input the image CDF values as in the code below. Note that this is for each pixel value r.
//backprojectionmodimg = img*0; //create empty matrix, same size as img
for r = [1:1:length(pxvals)],
modimg = modimg + (bool2s(img==pxvals(r))*round(CDF(r)/m));;
end;
where img is the imported image pixel value matrix, pxvals contains the list of pixel values obtained from the frequency count done by tabul, CDF is the CDF of the image, and m is just the slope of our ideal CDF. Note that img==pxvals(r) outputs a boolean matrix that has True values for those img elements that are equal to pixel value r and then bool2s turns the boolean matrix into a matrix of 1s and 0s for True and False values, respectively, so that only matrix elements with pixel value r will be changed into the new pixel value. New pixel values are calculated from CDF(r)/m. We then view the resulting image using imshow.
Figures 3, 4, and 5 show the raw images and enhanced images and PDF and CDF plots.






Figure 3. Top: raw grayscale eye image (left) and enhanced eye image (right). Middle: PDF for raw (left) and enhanced (right) image. Bottom: CDF for raw (left) and enhanced (right) image. (image source: http://farm2.static.flickr.com/1342/577585546_c53f536278.jpg?v=0)






Figure 4. Top: raw grayscale hand image (left) and enhanced hand image (right). Middle: PDF for raw (left) and enhanced (right) image. Bottom: CDF for raw (left) and enhanced (right) image. (image source: http://farm4.static.flickr.com/3606/3346568944_37df6fd2b5.jpg?v=0)






Figure 5. Top: raw SEM image (left) and enhanced SEM image (right). Middle: PDF for raw (left) and enhanced (right) image. Bottom: CDF for raw (left) and enhanced (right) image. (image source: http://www.mos.org/sln/SEM/diatomb.gif)
All enhanced images show higher contrast than the raw files; dark pixels in the raw image appear darker in the enhanced image and light pixels in the raw image appear whiter in the enhanced version. We also note that the CDF for the new images (bottom right of Figures 3, 4, and 5) have been converted to the ideal CDF (Figure 1) but with some flat regions since pixel values are whole numbers and finite.
For the nonlinear ideal CDFs we try using y = x2 and y = log(x). Note that the human eye responds logarithmically. Figure 6 summarizes the resulting images for the linear, parabolic and logarithmic CDFs.












Figure 6. For each 4-image set clockwise: raw image, linear CDF, logarithmic CDF, and parabolic CDF.
The parabolic CDF saturated the image, as expected, since it just squares the intensity of each pixel while the logarithmic CDF produced contrast even higher than those produced by the linear CDF.
I would like to thank Mr. Mark Jayson Villangca for teaching me to use the tabul command and Mr. Miguel Sison for pointing out errors in the image histograms.
I give myself a grade of 9 because I was able to increase the contrast of the images using backprojection and CDFs of the modified images show that the algorithm used was correct.
For the nonlinear ideal CDFs we try using y = x2 and y = log(x). Note that the human eye responds logarithmically. Figure 6 summarizes the resulting images for the linear, parabolic and logarithmic CDFs.












Figure 6. For each 4-image set clockwise: raw image, linear CDF, logarithmic CDF, and parabolic CDF.
I would like to thank Mr. Mark Jayson Villangca for teaching me to use the tabul command and Mr. Miguel Sison for pointing out errors in the image histograms.
I give myself a grade of 9 because I was able to increase the contrast of the images using backprojection and CDFs of the modified images show that the algorithm used was correct.


0 comments:
Post a Comment