Perfectly Flat Histogram Equalization - Ryerson Universitygnkhan/publications/... · Perfectly Flat...

5
Int. Conf. Signal Processing, Pattern Recognition and Applications, June 30-July 2, 2003 pp. 38-42, Rhodes Greece Perfectly Flat Histogram Equalization Jacob Levman, Javad Alirezaie, Gul Khan Department of Electrical and Computer Engineering, Ryerson University jlevman | jalireza | [email protected] Abstract In this paper, we present a novel technique for histogram equalization. Histogram equalization (or flattening) is the process of redistributing an input image’s grey level values to produce an output image easily analyzed by the human eye. Histogram equalization is primarily utilized in image enhancement. Most of the existing approaches to histogram flattening employ a simple transformation function that defines the resultant grey level value for any given input. We propose a multi-stage histogram equalization algorithm that guarantees a perfectly flat output histogram. Our algorithm consists of three stages, each of which creates an intermediate image. Results have shown that our approach to histogram equalization can result in excellent image enhancement. The benefits of such an algorithm are particularly important in medical applications such as x-ray images. Keywords: Image processing; histogram equalization. 1. INTRODUCTION Medical image analysis and advanced image interpretation techniques are heavily dependent on effective histogram equalization capabilities. Low contrast images are very common in medical applications and greatly benefit from histogram equalization. Histogram flattening is the process by which an algorithm redistributes grey level values so as to better define contrast differences to the user. Histogram flattening aids doctors in interpreting medical images, thus facilitating the diagnosis of ailments. Many approaches to histogram equalization have been developed. One common approach is to use the image’s histogram cumulative distribution function (CDF) as a grey level transformation function [1]. This is effectively the discrete integral of the function that represents the histogram. Kim et al. present an approach that is based on the piecewise linear approximation of the CDF [5]. Another technique is a subset of histogram matching. Histogram matching is the process by which one forces an image’s histogram to resemble any predefined function. This can be performed by using a transfer function that is comprised of the inverse CDF of the desired histogram and the CDF of the input histogram [3]. If a probability density function is chosen which corresponds to a flattened image, then the histogram matching problem is also an equalization task. Many of the recent developments in histogram flattening involve local histogram equalization. In local histogram flattening, an image is divided into sub-blocks and each sub-block is subjected to a separate histogram equalization process [4, 8, 9]. This method does tend to provide good solutions, but the algorithms can be complicated. Additionally, these algorithms do not ensure that the overall image will be equalized. Stark has proposed a histogram equalization technique that takes user inputs in order to produce various outputs that range from full histogram equalization to no changes at all [7]. Munteanu and Rosa approached this image enhancement problem with genetic algorithms [6]. Our approach involves three distinct phases, each of which produces an intermediate image. After each stage is performed, the intermediate image’s histogram is at least as flat as the previous image’s histogram. After the final stage the histogram is always perfectly flat. The first phase is concerned with eliminating any spikes in the histogram that are extremely large. The second phase is a form of histogram matching. The final phase is concerned with smoothing the histogram. It is this last stage that guarantees that the image’s histogram will appear perfectly flat.

Transcript of Perfectly Flat Histogram Equalization - Ryerson Universitygnkhan/publications/... · Perfectly Flat...

Page 1: Perfectly Flat Histogram Equalization - Ryerson Universitygnkhan/publications/... · Perfectly Flat Histogram Equalization Jacob Levman, Javad Alirezaie, Gul Khan ... move on to the

Int. Conf. Signal Processing, Pattern Recognition and Applications, June 30-July 2, 2003 pp. 38-42, Rhodes Greece

Perfectly Flat Histogram Equalization

Jacob Levman, Javad Alirezaie, Gul Khan Department of Electrical and Computer Engineering, Ryerson University

jlevman | jalireza | [email protected]

Abstract In this paper, we present a novel technique for histogram equalization. Histogram equalization (or flattening) is the process of redistributing an input image’s grey level values to produce an output image easily analyzed by the human eye. Histogram equalization is primarily utilized in image enhancement. Most of the existing approaches to histogram flattening employ a simple transformation function that defines the resultant grey level value for any given input. We propose a multi-stage histogram equalization algorithm that guarantees a perfectly flat output histogram. Our algorithm consists of three stages, each of which creates an intermediate image. Results have shown that our approach to histogram equalization can result in excellent image enhancement. The benefits of such an algorithm are particularly important in medical applications such as x-ray images. Keywords: Image processing; histogram equalization.

1. INTRODUCTION Medical image analysis and advanced image interpretation techniques are heavily dependent on effective histogram equalization capabilities. Low contrast images are very common in medical applications and greatly benefit from histogram equalization. Histogram flattening is the process by which an algorithm redistributes grey level values so as to better define contrast differences to the user. Histogram flattening aids doctors in interpreting medical images, thus facilitating the diagnosis of ailments. Many approaches to histogram equalization have been developed. One common approach is to use the image’s histogram cumulative distribution function (CDF) as a grey level transformation function [1]. This is effectively the discrete integral of the function that represents the histogram. Kim et al. present an approach that is based on the piecewise linear

approximation of the CDF [5]. Another technique is a subset of histogram matching. Histogram matching is the process by which one forces an image’s histogram to resemble any predefined function. This can be performed by using a transfer function that is comprised of the inverse CDF of the desired histogram and the CDF of the input histogram [3]. If a probability density function is chosen which corresponds to a flattened image, then the histogram matching problem is also an equalization task. Many of the recent developments in histogram flattening involve local histogram equalization. In local histogram flattening, an image is divided into sub-blocks and each sub-block is subjected to a separate histogram equalization process [4, 8, 9]. This method does tend to provide good solutions, but the algorithms can be complicated. Additionally, these algorithms do not ensure that the overall image will be equalized. Stark has proposed a histogram equalization technique that takes user inputs in order to produce various outputs that range from full histogram equalization to no changes at all [7]. Munteanu and Rosa approached this image enhancement problem with genetic algorithms [6]. Our approach involves three distinct phases, each of which produces an intermediate image. After each stage is performed, the intermediate image’s histogram is at least as flat as the previous image’s histogram. After the final stage the histogram is always perfectly flat. The first phase is concerned with eliminating any spikes in the histogram that are extremely large. The second phase is a form of histogram matching. The final phase is concerned with smoothing the histogram. It is this last stage that guarantees that the image’s histogram will appear perfectly flat.

Page 2: Perfectly Flat Histogram Equalization - Ryerson Universitygnkhan/publications/... · Perfectly Flat Histogram Equalization Jacob Levman, Javad Alirezaie, Gul Khan ... move on to the

-39 -

2. HISTOGRAM FLATTENING The first phase of the algorithm redistributes any major peaks that are found in the input image’s histogram. Let target be the desired number of pixels at any given grey level in order to make a perfectly flat histogram. A grey level is eligible for first phase redistribution if there are greater than threshold*target pixels at that given grey level. Threshold is set to 16 by default, but can be set to other values by the user. It should be noted that most standard images (photographs of people or landscapes) will not have any grey levels with a histogram reading this high. However, it commonly applies to medical images such as x-rays. It would typically represent the background black area of the image where no real information is stored. These pixel values are redistributed across all grey levels according to the following equation:

=),( nmpixel

���

���

−≤

otherwise /255*)maxP( if /255*

midPn

midPnmidPn

where, • midP = half of the width of the image

• maxP = the width of the image This stage has the effect of creating a gradient from white in the center to black on the left and right sides of the image. For an illustration of this effect on the background please see figure 3. The second phase of the algorithm is a form of histogram matching. The target function is a perfectly flat histogram that only uses 64 out of the total 256 possible grey levels. Thus the target histogram’s value at any grey level is defined as:

���

���

=otherwise 0

}{0,1,2,...in is )4/( if *4)(

ptgtphist

where, • tgt = image height * image width / 256

This algorithm must construct the transfer function to define the mappings of input to output grey levels. In order to do this, it first constructs the histogram cumulative distribution functions (CDFs) for both the input image and the target histogram. This algorithm selects the transfer function that will minimize the following equation:

)())(( rinCDFrTranstgtCDF −

where, • tgtCDF = the CDF of the target histogram • inCDF = the CDF of the input image • Trans( ) = the resultant transfer function • r = the set of all grey levels This equation requires the transfer function to be monotonic. The algorithm also requires that the tgtCDF value not be greater than the inCDF value by more than half of the distance between the histogram values at r. This section of the algorithm is based on previously developed methods [2]. The final stage of equalization is concerned with smoothing the histogram. Essentially, this algorithm traverses the histogram. Let curCount be the current count of pixels at a given location. If curCount is larger than target, then the algorithm selects curCount-target pixels randomly and moves them to the next grey level location. The selection process prioritizes those pixels originally located at this grey level ahead of those that have been previously moved to the given location. If curCount is smaller than target, then the algorithm selects target-curCount pixels from the closest grey level value that has a pixel count and grey level greater than the current value. To better illustrate this algorithm the pseudocode is provided in figure 1.

for endtarget)-number1,mxels(m,moveRandPi

else number)-targetm,1,xels(mmoveRandPi

target)if(number m]histogram[number

)m 256,m 0,for(m

+

+<

=++<=

Figure 1: Phase 3 Algorithm Here the moveRandPixels function moves the number of pixels in the third parameter from the grey level specified by the first parameter to the grey level specified by the second parameter. If there are not enough pixels in the first parameter, the function will move on to the next grey level to complete the operation. Please note that this will never occur in the second call to the function.

Page 3: Perfectly Flat Histogram Equalization - Ryerson Universitygnkhan/publications/... · Perfectly Flat Histogram Equalization Jacob Levman, Javad Alirezaie, Gul Khan ... move on to the

- 40 -

3. RESULTS AND DISCUSSION In histogram equalization it is beneficial to produce output images that are easily analyzed by the human eye. In figure 2 we present the low contrast input medical image of a spine; its histogram is shown in figure 5. Our algorithm produces a visually appealing version of the spine, and is presented in figure 3. The output image’s flat histogram is shown in figure 6. We compare our approach with the well-known method of using an image’s histogram CDF as the image transfer function. As is common with many histogram equalization techniques, this approach gives the image a washed out look. The output of such an algorithm is given in figure 4 and its resultant histogram is provided in figure 7. All of the algorithms were implemented and tested on a P-II 450 computer in C++.

Figure 2: Input Image

Figure 3: Output Image – Our Algorithm

Figure 4: Output Image – Comparison

Page 4: Perfectly Flat Histogram Equalization - Ryerson Universitygnkhan/publications/... · Perfectly Flat Histogram Equalization Jacob Levman, Javad Alirezaie, Gul Khan ... move on to the

- 41 -

Figure 5: Input Histogram

Figure 6: Output Histogram

Figure 7: Output Histogram – Comparison

It is evident from the results that our algorithm performs well with respect to creating a clear contrast enhanced image. This algorithm has been applied to a variety of images and has performed very well. The spine was selected because it shows the effectiveness that such an algorithm has on medical imaging. A medical image of a human skull is provided in figure 8. This example is presented to further illustrate the benefits this algorithm provides to medical imaging. Figure 9 shows the output generated by applying our approach to histogram equalization. Once again, in figure 10, we compare our approach to the common equalization technique outlined above.

Figure 8: Input Image

Figure 9: Output Image – Our Algorithm

Page 5: Perfectly Flat Histogram Equalization - Ryerson Universitygnkhan/publications/... · Perfectly Flat Histogram Equalization Jacob Levman, Javad Alirezaie, Gul Khan ... move on to the

-42 -

Figure 10: Output Image - Comparison

Although it is evident from the results displayed that this approach can provide significant benefits for the interpretation of medical images, it should be noted that the algorithm has a tendency to introduce small amounts of distortion in low information areas of the images. This is particularly prevalent in the base of the neck in figure 9. One of the main deficiencies of this algorithm would seem to be its lack of reversibility. Most histogram equalization techniques simply utilize a transfer function for grey level conversion. It is generally thought that since a transfer function is being used, its inverse can be calculated which could then be applied to the output image to restore the original. This concept only applies properly to continuous functions. In a discrete system, a transfer function will typically map two different pixel values to the same location. No discrete inverse transfer function can reverse this effect as there is no information to discern which grey levels were the origins of each output pixel. Admittedly, this lack of reversibility is a minor issue when compared to that of our algorithm; however, most every histogram equalization technique is at least in part irreversible.

4. CONCLUSIONS We propose a novel approach to histogram equalization where the output images are guaranteed to have perfectly flat histograms. The algorithm consists of three main stages: histogram spike redistribution, histogram matching, and histogram smoothing. The spike redistribution stage is concerned with eliminating any abnormally large peaks from the histogram. The matching phase attempts to transform the histogram

into a 64 grey level flattened image. The smoothing stage is concerned with forcing a perfectly flat shape on the histogram. This approach can greatly improve image contrast, particularly in medical imaging. The example output has shown this algorithm’s efficacy.

Acknowledgements This research is supported by a grant from NSERC Canada.

References [1] K. R. Castleman, Digital Image Processing, pp. 91-93, Prentice Hall, Upper Saddle River, NJ, 1996. [2] Documentation > Image Processing Toolbox, http://www.mathworks.com/access/helpdesk/help /toolbox/images/histeq.shtml, March 1, 2003. [3] R. C. Gonzalez, R. E. Woods, Digital Image Processing, pp. 94-102, Prentice Hall, Upper Saddle River, NJ, 2001. [4] Joung-Youn Kim, Lee-Sup Kim, Seung-Ho Hwang, “An advanced contrast enhancement using partially overlapped sub-block histogram equalization”, IEEE Transactions on Circuits and Systems for Video Technology, pp. 475-484, April 2001. [5] Sang-Yeon Kim, Dongil Han, Seung-Jong Choi, Jong-Seok Park, “Image contrast enhancement based on the piecewise-linear approximation of CDF”, IEEE Transactions on Consumer Electronics, pp. 828-834, Aug 1999. [6] C. Munteanu, A. Rosa, “Towards automatic image enhancement using genetic algorithms”, Proceedings of the 2000 Congress on Evolutionary Computation, pp. 1535-1542 vol. 2, July 2000. [7] J. A. Stark, “Adaptive image contrast enhancement using generalizations of histogram equalization”, IEEE Transactions on Image Processing, pp. 889-896, May 2000. [8] Yu Wang, Qian Chen, Baeomin Zhang, “Image enhancement based on equal area dualistic sub- image histogram equalization method”, IEEE Transactions on Consumer Electronics, pp. 68- 75, Feb 1999. [9] Hung-Shung Wong, Jung-Hua Wang, “Contrast enhancement based on divided histogram manipulation”, IEEE International Conference on Systems, Man, and Cybernetics, pp. 1551-1555 vol.2, Oct 2000.