Archive for July 21, 2010

Enhancement by Histogram Manipulation

The histogram of a digital grayscale image describes the frequencies that correspond to each of its gray levels. It shows the gray level distribution of the image, making it useful in image processing operations. Histograms can be manipulated to effectively modify or enhance an image. To demonstrate, we use following low contrast image.

Figure 1. A photo of my adorable cousin, taken with a camera phone.

Using gray_imread and histplot, we can open the image in grayscale mode and plot its histogram respectively. We can see in Figure 2 that the image histogram is not uniformly distributed throughout the whole range of grayscale values. Thus the image is of poor contrast, knowing that high contrast means a broader and flatter histogram. In order to improve the quality of an image, we need to equalize its histogram. The normalized histogram or its gray level probability distribution function (PDF) can be obtained by dividing each histogram value by the total number of pixels in the image. By performing cumsum on the normalized histogram values, we will obtain its cumulative distribution function (CDF).

Figure 2. Original image converted to grayscale and its corresponding histogram and CDF.

We now proceed to backprojection of the grayscale values of the image. Given the image’s CDF, we remap the grayscale values of the image such that the resulting CDF of the transformed image will look like the desired CDF. The steps are shown as follows.

Figure 3. Steps in altering the grayscale distribution. ( 1) From pixel grayscale, find CDF value (2). Trace this value in the desired CDF (3). Replace pixel value by grayscale value having this CDF value in desired CDF (4).

Linear CDF

Since we want an image of higher contrast, we will backproject using a linear CDF. Ideally, its corresponding histogram has a uniform distribution. As seen in Figure 4, the histogram has a broad distribution of values. Also, the CDF of the modified image is actually the same as the desired CDF.

Figure 4. Image enhancement using linear CDF. Notice that the histogram is broad and flat. This implies good correspondence between the actual CDF and the desired CDF.

Nonlinear CDF

We can also perform the same methods using a nonlinear function. Here I used the quadratic function.

Figure 5. Image enhancement using nonlinear CDF.

—————————————————————————————————————————————————

We can also use advanced image processing softwares to easily perform histogram manipulation. Some are available for free, such as GIMP. The following images are snapshots of the actual manipulations in GIMP.

Figure 6. Histogram manipulation in GIMP.
Figure 7. Histogram manipulation in GIMP.
—————————————————————————————————————————————————

I thank Joseph for sharing with me his knowledge on backprojecting.

—————————————————————————————————————————————————

Self evaluation: 10/10


Design a site like this with WordPress.com
Get started