Skip to main content

Activity 5: Enhancement by Histogram Manipulation

IN this activity, we will try to enhance an image by manipulating its histogram. By enhance, I mean the improvement of a dark image such that features disguised by the dark areas may be revealed. The histogram of a graylevel image, when normalized to the number of pixels, gives us the probability distribution function (PDF). 

For example, if we have the following color image:
Figure 1a. Dark color image which will be enhanced
 (taken from  http://twoleggedtripod.net/index.php?postid=3  )  
Then, convert it to a graylevel image using Scilab: 
Figure 1b. Grayscaled version of the image in Figure 1a
We get its PDF by dividing each pixel by the total number of pixels.

Figure 1c. Code for obtaining PDF of image
Figure 1d. PDF of the graylevel image
From the PDF, we see that the distribution is biased towards the low values.

If the image has graylevels, r, with a PDF of p1(r) and a cumulative distribution function (CDF) given by,

then we can map it to a new set of graylevels, z, described by a different CDF described by:
where p2(z) is the new PDF of the image. This technique is called backprojection and is best illustrated by the diagram found in Figure 2.
Figure 2. Illustration of the backprojection method. Look for the graylevel value, r,  of the pixel, and find its corresponding CDF value T(r). Project the value of T(r) for the graylevel on the desired CDF , G(z). Look for the graylevel value which corresponds to the mapped value for G(z). This graylevel value will replace the original value.



For the image in Figure 1b, we determine the CDF using the cumsum() command in SciLab as shown in the code snippet in Figure 3. The CDF is shown in Figure 4.
Figure 3. Code for obtaining CDF of image
Figure 4. CDF of the graylevel image in Figure 1b.
We then map the y values from the original CDF to a desired CDF. In this case we used a linear CDF and the CDF of a Gaussian PDF as shown in Figure 5.
Figure 5a. Linear CDF
Figure 5b. CDF of Gaussian PDF
We then use the interp() function in SciLab to find the corresponding graylevel value, z, for the y value that we mapped on the desired CDF. We then replace the graylevel value for each pixel of the original image by the new grayvalue obtained from the backprojection method. The code used to do this is shown below.



Shown below are the enhanced images using the linear CDF and the CDF of a Gaussian PDF. The corresponding CDFs of the enhanced images are also shown.
Figure 6a. Image enhanced using a linear CDF
Figure 6b. CDF of the image in Figure 6a.

Figure 6c. Enhanced image using CDF for a Gaussian PDF
Figure 6d. CDF of image in Figure 6c
The enhanced images show some feature that we cannot see just by looking at the original grayscale image such as some of the features of the branches and leaves of the surrounding trees. The image which resulted from the projection on a linear CDF is sharper compared to that obtained for the CDF of a Gaussian PDF. However, the image is too bright making some parts of the image to be indistinguishable due to the brightness. For the enhanced image using the CDF of a Gaussian PDF, the contrast is not as sharp and most parts of the original image are still distinguishable.

For this activity, I would like to thank Ms. Eloisa Ventura, Ms. Maria Isabel Saludares and Mr. Benjur Borja for useful discussions. 

Finally, I give myself a grade of 10/10 for being able to fulfill the requirements in the activity. 

References:
1.  M. Soriano, A5: Enhancement by Histogram Manipulation Manual, 2012

Comments

Popular posts from this blog

Activity 10 Applications of Morphological Operation 3 of 3: Looping through images

When doing image-based measurements, we often want to separate the region of interest (ROI) from the background. One way to do this is by representing the ROIs as blobs. Binarizing the image using the optimum threshold obtained from the image histogram simplifies the task of segmenting the ROI. Usually, we want to examine or process several ROIs in one image. We solve this by looping through the subimages and processing each. The binarized images may be cleaned using morphological operations.  In this activity, we want to be able to distinguish simulated "normal cells" from simulated "cancer cells" by comparing their areas. We do this by taking the best estimate of the area of a "normal cell" and making it our reference.  Figure 1 shows a scanned image of scattered punched papers which we imagine to be cells examined under the microscope. These will be the "normal cells." Figure 1. Scattered punched paper digitized using flatbe...

Activity 2: SciLab basics

For the second activity we had a bit of practice in using the SciLab programming language. We had to produce the following synthetic images: a.        Centered square aperture b.       Sine wave along x direction (corrugated roof) c.        Grating along x direction d.       Annulus e.       Circular aperture with graded transparency (Gaussian function) But first we had to follow a sample code given by Dr. Soriano. The code produced a 100 x 100 pixel – image of a centered circular aperture with radius of 35 pixels (Figure 1). Figure 1. Code and synthetic image for centered circular aperture After doing the centered circular aperture I am ready to do the other synthetic images. The easiest was the annulus since you just have to tweak the code for the centered circular aperture. I just replaced line 7 of the code with: A(find(r...

Activity 8 Applications of Morphological Operations 1 of 3: Pre-processing Text

In this activity, we aim to be able to extract text (handwritten or typed) using image processing techniques that we have learned. The image in Figure 1 is the source of the text we need to extract.   Figure 1. Image of a document from which text will be extracted The image is tilted so it was rotated using Gimp 2.8. Using the same software, I selected a portion of the image and cropped it (Figure 2a). The image was then loaded in Scilab 4.1.2 and converted to grayscale for image processing. The grayscale image is shown in Figure 2b.   Figure 2. (a) Cropped portion from the rotated image of the document  (b) grayscale version of the patch in (a) The first task was to remove the lines, to do this, I took the fftshifted FT of the grayscale image and multiplied it by a mask to filter out the higher order frequencies that contribute to the lines. I then took the inverse FT to get the image with the lines removed. I then binarized the image and inverted it...