You are on page 1of 7

A High Performance Exact Histogram Specication Algorithm

Alessandro Bevilacqua Pietro Azzari

ARCES - DEIS (Department of Electronics, Computer Science and Systems) University of Bologna, Viale Risorgimento 2 - Bologna, ITALY, 40136, {abevilacqua,pazzari}@arces.unibo.it Abstract
Real-time histogram specication methods aims to nd a continuous function that transforms a source image to match a target distribution with the highest possible degree of accuracy. Many approaches privilege exact specication exploiting multi-valued ordering functions but incur in highly computational expensive implementations. Histogram specication algorithms can be classied according to computational complexity, image distortion and accuracy of reproduction of the target histogram. The method we propose permits an exact match of a given target histogram independently of the source image meanwhile introducing negligible image distortion. The simplicity of the method enables fast computation making the algorithm suitable for real time applications. Exhaustive experiments and accurate comparisons are carried out against the most representative approaches reported in literature.

1. INTRODUCTION
Histogram modeling techniques provide sophisticated methods for modifying the dynamic range and contrast of an image by altering each individual pixel such that its intensity histogram assumes a desired shape ([1, 2]). Histogram specication, or histogram matching, is a basic histogram modeling technique that transform one histogram into another one by remapping the pixel values to control the relative frequency of their occurrence. Although histogram modeling operators may encompass the use of non-linear and non-monotonic Intensity Mapping Function (IMF), histogram specication employs a simple monotonic, nonlinear mapping which re-assigns the intensity values of pixels in the input image such that the output image exhibits as a similar histogram as possible to a given target distribution. Ideally, target and output image histograms should resemble each other as much as possible. In the continuous

case, histogram specication spreads graylevels all over the allowable range to match the output distribution. Although in the continuous case a mapping yielding a desired Probability Distribution Function (PDF) exists, working in a discrete domain means coping with a generally ill posed problem that does not admit an exact solution. Two strategies can be adopted: pursuing exact histogram specication by injecting noise to perfectly match the histogram or minimizing image handling using the best sub-optimal point-wise transformation of the grayscale levels. While low image distortion methods, such as classical ones ([1, 2]), are appealing for a wide range of tasks where visual evaluation is crucial, due to them preserving as much the source signal as possible, histogram gaps can have very detrimental effects for subsequent image processing operations. This is yet more true when considering general shapes for target histogram while the detrimental shades when considering an equal distributed target histogram, i.e the well known case of histogram equalization. In fact, in the latter case the main goal of histogram equalization is contrast enhancement that is performed visually correctly even in case that the target histogram is not completely at. On the contrary, histogram specication, where the target histogram has a prexed shape, makes sense if that shape is perfectly matched since the primary goal the visual effect from a qualitative point of view but the histogram shape itself. In general, faulty histogram matches yielding histogram distorsion may cause heavy consequences to applications such as image fusion, image retrieval, invisible watermarking, image normalization, image mosaicing. Research in the eld of exact histogram specication has led to diverse approaches that are characterized by achieving a lower histogram distortion at the expense of noisy images. In this paper we present the simple yet effective approach for exact histogram specication that arises from the thorough investigation we have carried out to nd out the best tradeoff between image and histogram distortion. The method we have conceived shows very a low image dis-

tortion while achieving the exact specication, in a faster way than other methods usually do. The paper is organized as follows. Section 2 provides a meaningful insight concerning related works in the eld of histogram specication. Section 3 gives an in-depth description of our method, also emphasizing its novelty and the main advances with the most signicant methods reported in literature. Section 4 analyses experimental results using synthetic and real world images and reports a thorough comparison with the performance achieved by the most representative methods. Concluding remarks are given in Section 5, together with some directions for future works.

ity, almost trivial, and the lower image distortion achievable, since pixels showing same graylevel in the original image are mapped into the same target graylevel. However, although the graylevels maintain their own coherence and the order relationship in the output image is strictly preserved, resulting histograms look quite different from the target one.

RELATED WORK

Histogram specication ([1, 2]) originates from a generalization of histogram equalization ([1, 3]). Classical implementation of histogram equalization is based on the fact that transforming a Random Variable (RV) by its Cumulative Distribution Function (CDF) results in a uniform distribution ([2]). Histogram specication is performed by using the source cumulative distribution function to map the source histogram to an equalized histogram and then using the inverse of the target cumulative distribution function to reshape the equalized histogram to reproduce the target histogram. In practice, if we regard image intensity as a discrete RV r characterized by a PDF that describes the spatial frequency of its gray levels, then the RV R = Cr (r) is uniformly distributed in [0, 1], where r Cr (r) = pr (v)dv is its monotonically non-decreasing CDF. Besides, let Z = Cz (z), z and Z being RVs and Cz the CDF of z, then one can force R = Z, hence 1 1 z = Cz (Z) = Cz (Cr (r)), as long as R and Z are uni1 form. According to the above, it turns out that Cr and Cz are the equalizing and the reshaping function, respectively. Apart from normalization details, histogram specication is performed by replacing in the source image the graylevel r 1 with r : r r = Cz (Cr (r)). While in the continuous case the problem of nding a function remapping the source samples into target ones exhibiting a desired PDF yields an exact result, its discrete counterpart is generally an ill posed problem that does not admit an exact solution. This is due to the CDF being not exactly invertible. In the discrete case the CDFs are staircase functions therefore invertible when pixels take distinct values only. Since the number of pixels in an image is usually considerably larger than the number of graylevels, the distinct value case is unlikely to happen. Practically speaking, the classical specication algorithm [1, 2], implemented according to the theoretical framework exposed above, cannot separate among equal graylevel pixels thus failing to yield a perfect match of the target histogram. The distinctive mark of the classical algorithm is its simplic-

Figure 1. An image histogram (left), a target histogram (middle) and the outcome after classical specication (right) Fig. 1 shows a signicant example of the distortion of resulting histogram with respect to the target one when performing classical histogram specication. As one can see, gaps and overfull bins are emphasized in case the source image histogram is composed by few large bins. Authors in [1, 3] propose to reduce this effect by preprocessing the source image adding a small amount of uniform noise to each pixels intensity value. While these approaches are likely to produce an output image whose histogram is more similar to the target one, the noise is added without any regard of the source image structure, potentially even reducing the overall image quality. Although being rough, these methods represent an improvement of the classical method, since the unstructured noise they add can be easily ltered by further processing procedures. Several other attempts have been accomplished to improve histogram matching with respect to the classical approach by exploiting methodological techniques. For instance, authors in [4, 5] rene the classical algorithm in order to get exact histogram specication by randomly separating pixels. In particular, authors in [4] cope with the histogram specication dealing with it as being an optimization problem. However, exact matching are attained at the expense of more noisy images, as stated in [1]. Moreover, typical noise pattern introduced by this class of methods is represented by structured horizontal lines inside uniform areas, this due to the row-wise order of evaluation of equivalent pixels. As a matter of fact, such structured, although often visually negligible, patterns may mislead further image processing methods (e.g. edge detectors), where noisy structured lines can be mistaken as being signals. For the sake of clarity, this problem has been already noticed in

[6], where the histogram approximation has been improved by separating pixels according to their local mean on the four horizontal and vertical neighbors. However, the computational overhead introduced by statistical processing has often been considered as a reckoning not to be paid. Besides, this work has been successively rened by several authors. For instance, in order to further discriminate among equal pixels authors in [7] take two more neighborhood based metrics into consideration (the 8-connected average and the greater-than-neighbors count). While this approach permits to effectively split larger bins into smaller ones, the target histograms still are not perfectly matched. Authors in [8] improve the latter approaches by trying combining different metrics (using K-dimensional size increasing lter bank) with the purpose of discriminating each pixel of the image. This way, invertible CDFs are obtained, thus making the exact solution to exist, as it happens in the continuous case. Leaving the inherent complexity of the method out of consideration, the lter size plays a key role in order to achieve bins made of one pixel, since considering far and far pixels may increase the probability of introducing useful information. Often, choosing the right size for the neighbor window is strictly depending on image peculiarities and this task needs to be performed image by image in order to achieve optimality. However, we can state that the work reported in [8] represents the state-of-the-art for exact histogram specication methods.

this setting, the discrete PDF H (i.e. the normalized histogram) and the CDF C of the image f () can be computed as follows: H(x) = 1 E
E

S(f (p)), S(f (p)) =


p=0 x

1 , if f (p) = x 0 , otherwise (1) (2)

C(x) =
y=0

H(y)

The desired histogram specied output would be an image represented by an intensity scalar function g : [0, N 1] [0, M 1] [0, D 1] characterized by a normalized histogram that exactly matches the target PDF HT . Given these denitions, each bin of the output histogram must count N M HT (i) pixels, where i [0..D 1] represents the bin index. Fig. 2 outline graphically, using just 4 gray levels, the different approaches utilized to remap the gray levels in or-

(a) Classical

(b) Eramian et al. (c) Coltuc et al.

(d) Our method

THE METHOD

Figure 2. Histogram specication mappings methods and approximation errors. Classical (a), Eramian et al. (b), Coltuc et al. (c), our method (d) der to perform histogram specication. The rst rows refer to the source image and show the distribution of the 4 gray levels (left) with the corresponding histogram (right). The second rows show the expected target distribution (and related histogram), while the arrows from rst to second rows describe the re-mapping method (e.g. in Fig. 2(a) 0 maps to 0, 1 to 2, 2 to 3 and 3 to 3). Finally, the third rows show in red (dark) color the approximation errors. For example, the third row of Fig. 2(a) shows that gray level 1 is mapped erroneously in gray level 2 instead that partly in 0,1 and 2. Fig. 2(a) depicts the classical histogram specication algorithm. It requires to compute a simple IMF in the form of a Look-Up-Table (LUT) whose entries are the D distinct graylevels x. Hence, D represents the dynamic range of an implicit ordering function based on gray levels. In order to obtain the histogram specied image each graylevel x must be substituted with the graylevel x according to Eq. 3:
1 x = D CT (C(

Histogram specication methods can be classied according to computational complexity, image distortion and accuracy in reproducting the target histogram. The method we propose yields exact solutions and produces histograms perfectly matching a target PDF. Practically speaking, our method offers the following features: capability to achieve exact matching; simplicity to yield a fast algorithm; independence of the properties of both the source image and the target histogram.

3.1

Approaches

According to the classical treatment exposed in Section 2, histogram specication is generally accomplished through a mapping between the order statistics, where each element of the source distribution is mapped to the correspondingly ranked element of the target distribution. Thus let f : [0, N 1] [0, M 1] [0, D 1] be a scalar function representing an image with dimension E = N M and depth D, where f (p) denotes the graylevel of a pixel p. In

x )) D

(3)

where CT and C are the CDF of the target PDF and the source image, respectively. This method is simply

a graylevel remapping, only global histogram information and the pixels graylevel are considered. The more the original and the target histogram are different the more unwanted gaps and overfull bins are likely to appear. In fact, large difference in pixels count of corresponding bins (through the computed mapping) cannot be meaningfully handled. The problem is originated from the staircase nature of the discrete CDF and its rough quantization step = 1/D. As highlighted in Fig. 2(a), this lack of distinctiveness among pixels leads to gross approximation errors and, most importantly, hinder any further improvements. An attractive improvement arises from discriminating pixels with the same gray level, taking into account the properties of their own neighborhoods. For example, authors in [7] introduce the neighborhood voting metric m1 , according to a voting function dened as the number of pixels in the m m square neighborhood mask centered on a pixel whose gray value is strictly less than the pixels. The dynamic range of this metric is given by Dm = m m 1, thus being DM = D Dm the dynamic range of the resulting ordering function. This grants a consequent renement of the quantization step = 1/DM . Practically speaking, equal gray level pixels have the chance to be split into additional Dm bins, thus reducing the staircase effect of the CDF and yielding a better approximation to the desired histogram (Fig. 2(b)). As a consequence, splitting equivalent gray level classes using neighborhood metrics permits to achieve a ner quantization step, thus considerably reducing the overall error. These procedures can be virtually iterated until each bin is made of one pixel. An interesting example can be found in [8], where authors combine K average neighborhood metric mk , k [0..K 1] computed on size increasing neighbor K1 masks, thus yielding a dynamic range DM = k=0 Dmk . As one can see in Fig. 2(c), the quantization step decreases and the histogram converges signicantly to the target one.

according to a given ordering metric that can yield several subclasses ci , i [0..DM 1]. Namely, the class of pixels equal to, say, 100 can be further split into subclasses of pixels having the same value (100) for one feature (the gray level) but being different according to one additional feature (e.g. neighbor average). More features yield more subclasses, thus producing a ner quantization step. After that, each subclass ci is sequentially assigned to the available target gray level bins bj , j [0..D 1] so that each of them have E HT (i) items. A sparse matrix M DM D has been utilized to store this one-to-many mapping, in which each row represents the source image subclass and the column entry denotes the target histogram gray level. Each matrix cell M (ci , bj ) contains the amount of source pixels dened by class ci that must be remapped to the gray level bj : m0,0 0 0 0 ... 0 m1,0 m1,1 0 0 ... 0 0 0 ... 0 m2,1 m2,2 0 0 ... 0 0 m3,2 (4) 0 0 0 m4,2 m4,3 . . . ... ... ... ... ... ... .. . mDM ,D 0 0 0 0 Histogram matching is attained by imposing that each target gray level (column entry) have had E HT (i) source pixels mapped. Practically speaking, this can be achieved by forcing each column sums up to E HT (i) pixels:
DM 1

S(bj ) =
ci =0

M (ci , bj ) = E HT (j), j [0..D 1]

3.2

Description of the algorithm

Our algorithm has been primarily designed to meet the denition of histogram specication, namely the generation of an image whose histogram perfectly matches a given target histogram, independently of the source image. Since each bin i in the output image must be populated with E HT (i) pixels in order to achieve the exact match, it is likely that equal pixels shall be mapped to different gray levels. Yet more, the equality concept usually referred to the gray level property of pixels can be easily extended to all the properties derived using metrics or any other discriminating feature. Therefore, according to the need expressed above we can relax the concept of function and refer to the concept of relationship. Consequently, the conventional scalar, or pointwise, IMF approach has been abandoned, in favor of an explicit one-to-many mapping. Pixels are rst ordered

(5) This approach can have a signicant drawback consisting in the introduction of structured pattern noise in case gray level assignments are left to the order of the evaluation of the input pixels (e.g. typically row-wise). This phenomenon is well known to affect all the algorithms aiming at performing (quasi-) exact methods. However, although the visual effect can be noticed only for quite untextured and largely uniform images, this always alters the signals in a systematic way, often misleading further image processing algorithms. To compensate for this effect, we have introduced random strings to select gray level bj randomly among the non-zero column entries of the matrix M . While preserving computing speed, our choice permits not to add to the transformed image unwanted signal patterns.

EXPERIMENTAL RESULTS

Extensive experiments have been carried out using well known images usually employed for benchmark evaluations, using a AMD Athlon 2000+ equipped with 512 MB

RAM. In addition, challenging images have been considered in order to stress the methods considered, thus emphasizing the outcome of the different strategies adopted. Three different performance indicators have been considered, thus allowing even the lightest differences to be highlighted. In particular, comparisons have been performed according to computing speed and contrast enhancement as far as macro effects are concerned. However, as stated at the beginning, a bad specied histogram can affect further image processing steps. To this purpose, we have implemented two distortion indicators measuring how much the histogram or the image structure have been altered by the specication process. The experiments have been accomplished over the most four representative methods in literature and results have been compared with the outcome of our approach. The names of authors in the Tables refer to the methods described in the respective papers cited. In particular, Coltuc [8] is the only method achieving an exact matching histogram, and it is our direct competitor for all the indicators. Finally, for one image we include the shapes of the original and specied histograms, using all the methods implemented.

For the same reason as the contrast enhancement, it has been adopted in these experiments as well. = 1 E G1 (i, j) ij G2 (i, j)
2

(i,j)[0,M 1][0,N 1]

(7) 1 Here, ij = E i,j G1 (i,j) is the mean ratio. The G2 (i,j) indicator gives sort of a measure of the standard deviation of local changes in terms of contrast.

4.2

Results

As the images for benchmarks we use some of the synthetic images Brodatz textures collection [9], besides the well known Lena and Peppers (Fig. 3). In these gures we

4.1

Performance Indicators

What follow are the performance indicators we have implemented to assess and compare the histogram equalization methods. computational speed Often the time needed to obtain the specied histogram is not directly measurable since the elapsed time is too short with respect to the resolution of the clock procedure. Therefore we have computed the number of specications performed in a given amount of time, that in the experiments has been xed to 10 seconds. In this way we can derive the number of iterations S per second (ips) that is our measure unit. histogram distortion This indicator gives a measure of the effectiveness of the methods to achieve a specied histogram by comparing the CDFs of the target and the specied histogram, H and K respectively, by using the Kolmogorov-Smirnov distance dened in Eq. 6: DKS (H, K) = max(| hi ki |), i [0..D]
i

(a) Original

(b) Linear

(c) Gaussian

(d) Log

Figure 3. Samples from the data set. Brodatz d72 (top), Baboon (middle) and Boat (bottom) histogram specied using our method with synthetic target histograms.

(6)

where hi and ki represents the ith bin of the CDF. image distortion The image distortion between images G1 and G2 , whose size is N M has been measured using the indicator dened by authors in [7] and reported in Eq. 7.

show the original images (top) and those equalized using our method (bottom). We do not show images achieved with the other approaches, since the differences are not visually perceptible. Rather, they can be assessed through analyzing Tables 1- 1, column by column. As for speed, for all algorithms it is strictly proportional to image dimension. Our algorithm always performs far better than all the other ones (more that one order of magnitude, two as for Coltuc) but the classic, whose speed is twice than ours. At the opposite, Coltuc has the worst performance. As a consequence, we can also state that our algorithm is the only one capable to work almost at frame rate (25 frame per second), or faster (Peppers and Lena), in a video processing application. The contrast indicator shows that our algorithm always performs better than Classic and Coltuc as well (even more than twice in image d102), while Eramian shows always the highest value. As for the remaining indicators, results in the tables

show us how they are inversely proportional dimensions, as expected: the lower the histogram distortion, the higher the image distortion. Coltuc and ours have the same image distortion and they are the only two to have not any histogram distortion. As for histogram distortion, the best among the non exact methods is Eramian , that always shares with Coltucs and ours comparable image distortion for all images but d102. However, it never cannot reach zero distortion. In image d25 Eramian has same image distortion as us, but histogram is not at, as one can see in Fig. 4(f). As far as image distortion is concerned, it is roughly comparable when considering all methods, but in image d102 our image distortion is almost one order of magnitude larger than non exact methods. Again, this cannot be assessed visually, but it is quite a heavy effect from a numerical point of view, that affects both the exact methods. Image d102 is a very contrasted image, with quite a bimodal original histogram (Fig. 4(c)). Looking at histogram of Fig. 4(h), one can see how Eramian lacks in lling bins having the lowest gray levels and conversely this yields an improvement in terms of image distortion.

Table 3. Histogram specication results for Baboon, 512 512, single channel
Distortion Lin Classic Eram Eram Coltuc Ours 88.82 2.99 1.56 0.35 67.45 .010 .010 .010 .011 .011 Gau 1.08 1.09 1.11 1.12 1.12 Log .324 .339 .345 .346 .346 Match DKS [102 ] Lin .766 .134 .013 .000 .000 Gau .788 .204 .013 .000 .000 Log .786 .198 .014 .000 .000

Method

Speed

CONCLUSION

Table 1. Histogram specication results for image d72, 640 640, single channel
Distortion Lin Classic Eram Eram Coltuc Ours 56.58 1.88 1.05 0.20 42.91 .023 .024 .024 .024 .024 Gau .244 .559 .701 .741 .741 Log .147 .198 .203 .210 .210 Match DKS [102 ] Lin 4.07 .743 .067 .000 .000 Gau 4.15 .975 .059 .000 .000 Log 4.39 1.04 .107 .000 .000

Method

Speed

In this paper we describe a novel method to perform accurate histogram equalization by achieving a at histogram. Usually, mapping between original histogram and target attened is carried out by means of functions, that can involve 1-d feature (gray levels) or n-d features, where different metrics (e.g. neighborhood average) allow to discriminate among pixels having same values for the remaining (n1)-d features. Our approach leaves the concept of mapping function and replaces it with the principle of one-to-many mapping relationship. This enable us to map pixels having same value for one feature in the source histogram to diverse gray level values. Known indicators have been used to assess the time and quality performance of our method. Here we tried using just 1-d feature for source histogram. This makes by far our algorithms the fastest and the best when compared with an algorithm that so far has been the reference in literature. Nevertheless, our method always achieves a at histogram where other methods fail.

References
Table 2. Histogram specication results for Boat, 512 512, single channel
Distortion Lin Classic Eram Eram Coltuc Ours 87.32 2.99 1.56 0.36 71.14 .009 .009 .009 .009 .009 Gau .203 .226 .250 .249 .249 Log .090 .098 .099 .103 .103 Match DKS [102 ] Lin 2.15 .490 .027 .000 .000 Gau 2.04 .421 .026 .000 .000 Log 2.05 .638 .028 .000 .000

[1] A. Rosenfeld and A. Kak. Digital picture processing. Upper Saddle River, NJ, Prentice Hall, 1982. [2] R.C. Gonzales and R.E. Woods. Digital image processing. Upper Saddle River, NJ, Prentice Hall, 2002. [3] L.G. Shapiro and G.C. Stockman. Computer Vision. Prentice Hall Inc., New Jersey, 2001. [4] Y.J. Zhang. Improving the accuracy of direct histogram specication. Journal of Electronic Imaging, 28(3):213214, 1992. [5] J.P. Rolland, V. Vo, B. Bloss, and C.K. Abbey. Fast algorithm for histogram matching: applications to texture

Method

Speed

(a) Original

(b) Linear

(c) Gaussian

(d) Log

Figure 4. Comparison between source (left column) and specied histograms using ve different specication methods: from top to bottom, Classical, Eram , Eram , ours (Coltucs is identical and it has not been reported), and different target histograms: from left to right, Linear, Gaussian and Logarithmic.

synthesis. Journal of Electronic Imaging, 9(1):3945, 2000. [6] E.L. Hall. Almost uniform distributions for computer image enhancement. IEEE Transactions on Computers, 23(2):207208, February 1974. [7] M. Eramian and D. Mould. Histogram equalization using neighborhood metrics. In Proceedings of the Second Canadian Conference on Computer and Robot Vision (CRV05), pages 397404, 2005. [8] D. Coltuc, P. Bolon, and J.M. Chassery. Exact histogram specication. Transactions on Image Processing, 15(5):11431152, May 2006. [9] P. Brodatz. Textures: A photographic album for artists and designers. In Dover Publications, 1999.

You might also like