Histogram Specification: A Fast and Flexible Method to ... · THOMASet al.:HISTOGRAM...

14
IEEE TRANSACTIONS ON INSTRUMENTATION AND MEASUREMENT, VOL. 60, NO. 5, MAY 2011 1565 Histogram Specification: A Fast and Flexible Method to Process Digital Images Gabriel Thomas, Member, IEEE, Daniel Flores-Tapia, and Stephen Pistorius Abstract—Histogram specification has been successfully used in digital image processing over the years. Mainly used as an image enhancement technique, methods such as histogram equalization (HE) can yield good contrast with almost no effort in terms of inputs to the algorithm or the computational time required. More elaborate histograms can take on problems faced by HE at the expense of having to define the final histograms in innovative ways that may require some extra processing time but are nevertheless fast enough to be considered for real-time applications. This paper proposes a new technique for specifying a histogram to enhance the image contrast. To further evidence our faith on histogram specification techniques, we also discuss methods to modify im- ages, e.g., to help segmentation approaches. Thus, as advocates of these techniques, we would like to emphasize the flexibility of this image processing approach to do more than enhancing images. Index Terms—Contrast enhancement, histogram equaliza- tion (HE), histogram specification (HS), maximum entropy, segmentation. I. I NTRODUCTION W HAT CONSTITUTES good contrast? That is a good question since image quality is very subjective and, as the phrase says, beauty is in the eyes of the beholder. It depends on the user, and we would like to add here that it also depends on the scene itself. Back in the days of darkroom developing—we assume those days are almost over for the photography enthusiast—developing black-and-white pictures required a test strip, which was made by exposing the photographic paper to different exposure times, as shown in Fig. 1. The winning exposure time was the one that offered the best contrast, which usually meant the one that yielded an image with very dark blacks and very light whites, and everything in between. This last statement would suggest that histogram Manuscript received June 20, 2010; revised August 24, 2010; accepted August 25, 2010. Date of current version April 6, 2011. The Associate Editor coordinating the review process for this paper was Dr. Emil Petriu. G. Thomas is with the Department of Electrical and Computer Engi- neering, University of Manitoba, Winnipeg, MB R3T 5V6, Canada (e-mail: [email protected]). D. Flores-Tapia is with the Department of Medical Physics, CancerCare Manitoba, Winnipeg, MB R3E 0V9, Canada (e-mail: Daniel.Flores@ cancercare.mb.ca). S. Pistorius is with the Department of Medical Physics, CancerCare Manitoba, Winnipeg, MB R3E 0V9, Canada, and also with the Faculty of Medi- cine and the Department of Physics and Astronomy, University of Manitoba, Winnipeg, MB R3T 5V6, Canada (e-mail: Stephen.Pistorius@cancercare. mb.ca). Color versions of one or more of the figures in this paper are available online at http://ieeexplore.ieee.org. Digital Object Identifier 10.1109/TIM.2010.2089110 equalization (HE) must be one of the most effective techniques. If only life was so simple, then yes, HE is the best algorithm, but the very fact that there is still a lot of research in this area suggests that there is more to be done. The HE dates back to the 70s, and a patent was issued way back in 1976. Now, good contrast also depends on the scene. If you are taking pictures in a zoo and the zebra is your subject, then yes, you want those black and whites, and all sort of gray- level values that can appear in the background. However, if you happen to photograph a polar bear in winter, you need mostly whites. What is a good contrast then? We will go for a simple answer here—a method that offers you more gray-level values or more saturation values for the different color tones in the image but will not degrade an image in a considerable way. Since we first mentioned the HE, this paper starts in Section II with a brief introduction to this technique. Section III discusses ways to specify a histogram so that some problems faced by the HE can be solved by these new techniques, including the one originally proposed by the authors in [1], which is further discussed in this paper. Section IV deals with the idea that histogram specification (HS) can also be used as a preprocessing technique that can improve image segmentation [2]. Thus, we aimed to demonstrate that the HS is a fast and flexible technique that can serve more than one purpose. II. ENHANCEMENT BY HISTOGRAM MODIFICATION A. HE Modifying an image such that its histogram has a uniform distribution usually yields a better contrast. The technique is known as the HE, and the transformation T (r) needed to obtain this equalization can be formulated as s = T (r)= r 0 p r (w)dw (1) where r is the intensity value of the original pixel, s is the pixel value of the transformed image, and p r (r) is the probability density function (PDF) associated to the original image. It is assumed that the image is the outcome of a continuous random variable and that the histogram resembles its PDF. In this paper, PDF refers to a histogram that has been normalized so that the area is equal to 1. The HE is then calculated by using the cumulative density function (CDF) of the original image as the transformation function as expressed in (1). It can be easily shown that the PDF of the transformed image 0018-9456/$26.00 © 2010 IEEE

Transcript of Histogram Specification: A Fast and Flexible Method to ... · THOMASet al.:HISTOGRAM...

  • IEEE TRANSACTIONS ON INSTRUMENTATION AND MEASUREMENT, VOL. 60, NO. 5, MAY 2011 1565

    Histogram Specification: A Fast and Flexible Methodto Process Digital Images

    Gabriel Thomas, Member, IEEE, Daniel Flores-Tapia, and Stephen Pistorius

    Abstract—Histogram specification has been successfully used indigital image processing over the years. Mainly used as an imageenhancement technique, methods such as histogram equalization(HE) can yield good contrast with almost no effort in terms ofinputs to the algorithm or the computational time required. Moreelaborate histograms can take on problems faced by HE at theexpense of having to define the final histograms in innovative waysthat may require some extra processing time but are neverthelessfast enough to be considered for real-time applications. This paperproposes a new technique for specifying a histogram to enhancethe image contrast. To further evidence our faith on histogramspecification techniques, we also discuss methods to modify im-ages, e.g., to help segmentation approaches. Thus, as advocatesof these techniques, we would like to emphasize the flexibilityof this image processing approach to do more than enhancingimages.

    Index Terms—Contrast enhancement, histogram equaliza-tion (HE), histogram specification (HS), maximum entropy,segmentation.

    I. INTRODUCTION

    WHAT CONSTITUTES good contrast? That is a goodquestion since image quality is very subjective and,as the phrase says, beauty is in the eyes of the beholder.It depends on the user, and we would like to add here thatit also depends on the scene itself. Back in the days ofdarkroom developing—we assume those days are almost overfor the photography enthusiast—developing black-and-whitepictures required a test strip, which was made by exposingthe photographic paper to different exposure times, as shownin Fig. 1.

    The winning exposure time was the one that offered the bestcontrast, which usually meant the one that yielded an imagewith very dark blacks and very light whites, and everythingin between. This last statement would suggest that histogram

    Manuscript received June 20, 2010; revised August 24, 2010; acceptedAugust 25, 2010. Date of current version April 6, 2011. The Associate Editorcoordinating the review process for this paper was Dr. Emil Petriu.

    G. Thomas is with the Department of Electrical and Computer Engi-neering, University of Manitoba, Winnipeg, MB R3T 5V6, Canada (e-mail:[email protected]).

    D. Flores-Tapia is with the Department of Medical Physics, CancerCareManitoba, Winnipeg, MB R3E 0V9, Canada (e-mail: [email protected]).

    S. Pistorius is with the Department of Medical Physics, CancerCareManitoba, Winnipeg, MB R3E 0V9, Canada, and also with the Faculty of Medi-cine and the Department of Physics and Astronomy, University of Manitoba,Winnipeg, MB R3T 5V6, Canada (e-mail: [email protected]).

    Color versions of one or more of the figures in this paper are available onlineat http://ieeexplore.ieee.org.

    Digital Object Identifier 10.1109/TIM.2010.2089110

    equalization (HE) must be one of the most effective techniques.If only life was so simple, then yes, HE is the best algorithm,but the very fact that there is still a lot of research in this areasuggests that there is more to be done. The HE dates back to the70s, and a patent was issued way back in 1976.

    Now, good contrast also depends on the scene. If you aretaking pictures in a zoo and the zebra is your subject, thenyes, you want those black and whites, and all sort of gray-level values that can appear in the background. However, if youhappen to photograph a polar bear in winter, you need mostlywhites.

    What is a good contrast then? We will go for a simple answerhere—a method that offers you more gray-level values or moresaturation values for the different color tones in the image butwill not degrade an image in a considerable way.

    Since we first mentioned the HE, this paper starts inSection II with a brief introduction to this technique. Section IIIdiscusses ways to specify a histogram so that some problemsfaced by the HE can be solved by these new techniques,including the one originally proposed by the authors in [1],which is further discussed in this paper. Section IV deals withthe idea that histogram specification (HS) can also be used as apreprocessing technique that can improve image segmentation[2]. Thus, we aimed to demonstrate that the HS is a fast andflexible technique that can serve more than one purpose.

    II. ENHANCEMENT BY HISTOGRAM MODIFICATION

    A. HE

    Modifying an image such that its histogram has a uniformdistribution usually yields a better contrast. The technique isknown as the HE, and the transformation T (r) needed to obtainthis equalization can be formulated as

    s = T (r) =

    r∫0

    pr(w)dw (1)

    where r is the intensity value of the original pixel, s is the pixelvalue of the transformed image, and pr(r) is the probabilitydensity function (PDF) associated to the original image. Itis assumed that the image is the outcome of a continuousrandom variable and that the histogram resembles its PDF. Inthis paper, PDF refers to a histogram that has been normalizedso that the area is equal to 1. The HE is then calculated byusing the cumulative density function (CDF) of the originalimage as the transformation function as expressed in (1). Itcan be easily shown that the PDF of the transformed image

    0018-9456/$26.00 © 2010 IEEE

  • 1566 IEEE TRANSACTIONS ON INSTRUMENTATION AND MEASUREMENT, VOL. 60, NO. 5, MAY 2011

    Fig. 1. Test strip examples. Different exposure times can be seen as stripes offering different contrasts. Darkroom-developing techniques look for high contrastson final pictures by selecting the right exposure time.

    Fig. 2. (a) Original image. (b) Results obtained using the HE. (c) Results obtained using darkroom-developing techniques.

    is indeed uniformly distributed [3]. In its discrete form,(1) becomes

    sk = T (rk) =k∑

    j=0

    pr(rj) for k = 0, 1, . . . , L − 1 (2)

    for an image with L gray-level values.The HE can yield bad results for images that contain noise

    and/or include a constant background. Because we are con-centrating on enhancing images for general photography, thenoise case is not of our concern here; albeit the use of telephotolenses of, for example, f500 mm can introduce haze noise,we are assuming that inexpensive cameras would have zoomcapabilities of up to f75 mm, which does not introduce this typeof noise.

    Nevertheless, the HE can yield good results. Fig. 2(a) showsan original image that has been modified by the HE, as canbe seen in Fig. 2(b). Note how brightening the dark shadowson the woman’s face let us see more details in the HE result.Fig. 2(c) shows the same image but was developed using adarkroom technique called dodging, which consists of blockingthe light coming from the enlarger, as illustrated in Fig. 3. Fig. 4shows the histograms of the three images shown in Fig. 2.Because the HE was formulated assuming a continuous PDF,the final histogram is not necessarily uniform, and its histogramshows peaks and gaps [4]. Notice also in Fig. 4 how the pictureenhanced using the dodging technique in the darkroom has ahistogram that is not uniform but still yields fairly good results.

    Fig. 3. Contrast enhancement based on blocking the light during the develop-ing process.

    As a matter of fact, the original and specified histograms arequite similar.

    Let us look at the histograms shown in Fig. 5, where the gray-level spreading and the general shape between the histogramsare even more similar to the ones seen in Fig. 4. Fig. 6shows the images of the aforementioned histograms. Fig. 6(a)is the original image that was taken on film at a full f-stop

  • THOMAS et al.: HISTOGRAM SPECIFICATION: A FAST AND FLEXIBLE METHOD TO PROCESS DIGITAL IMAGES 1567

    Fig. 4. Histograms of pictures shown in Fig. 2.

    Fig. 5. Original histogram of Fig. 6(a) and specified histogram used to obtainFig. 6(b).

    faster than required, that is, the shutter speed was set faster.During developing, it was underdeveloped one full step to try tocompensate for the wrong setting. Furthermore, the image wasscanned and saved as a Joint Photographers Expert Group file.All these steps caused the artifacts that can be seen at a closerlook and that will be amplified if the image is to be printedin a larger size. A zoom on the image shows these effects,too. Fig. 5 shows the histogram of the original image and ahistogram obtained by simply smoothing the original histogramusing low-pass filtering. This histogram was then used as thespecified histogram followed by median filtering with a maskof size 3 × 3 to remove any spurious pixels. The final image isshown in Fig. 6(b).

    These two examples suggest that having a uniform finalhistogram is not necessarily the best choice. This then bringsus to our next subsection, which discusses a way to modifycontrast according to a specified histogram.

    B. Histogram Specification (HS)

    The HS yields an image with a PDF that follows a specifiedshape fZ(z) for z ∈ [0, 1]. If HE is applied to this final im-age, the outcome would be an image that also has a uniformPDF, i.e.,

    G(z) =

    z∫0

    fZ(w)dw = s. (3)

    Equating (1) and (3) can be used to form the transformationfunction that yields the specified histogram, i.e., z = G−1(s) =G−1[T (r)]. For digital normalized images with L gray-levelvalues, the straightforward implementation of the HS is basedon the formulation of

    sk =T (rk)=k∑

    j=0

    fR(rj) for k=0,1

    L−1 ,2

    L−1 , . . . , 1 (4)

    sk =G(zk)=k∑

    i=0

    fZ(zi) for k=0,1

    L−1 ,2

    L−1 , . . . , 1. (5)

    Fig. 7 shows the steps mentioned above for two CDFscorresponding to an original image and a specified histogram.

    Going back to the histograms shown in Figs. 4 and 5, one cansee that HS can potentially enhance images if only we knowa priori the specified histogram that results in a better image.That is a big if, particularly if the algorithm to be proposedhere is to be fully automatic. It is something to have a coupleof parameters to adjust for an image enhancement techniqueto be considered in, for example, general photography, but tospecify L − 1 values for a final histogram is quite discouraging.Is there a way to specify these histograms automatically then?The succeeding sections discussed this possibility.

    III. HS TECHNIQUES FOR CONTRAST ENHANCEMENT

    A. Brightness-Preserving HE

    It is well known that, if the histogram of an image shows astrong peak because the image is dominated by a large area of asingle gray-level value, this can cause problems when using HE[3]. Fig. 8 shows an example when HE can cause bad results.

    Regardless of the shape of the histogram in the original im-age, the HE will yield an image with a final level of brightnessthat is close to 0.5. For the example in Fig. 8, the mean of thehistogram-equalized image is μHE = 0.4991. There is nothingwrong with that, you may say, “since the over enhancementseems to be caused by the spreading, not the average bright-ness.” Yes but not entirely true is the answer. Recall the scenarioof a picture of a polar bear in a winter tundra scenery. The imageshould be very white, and if the HE is applied, the polar bearmay look more like a brown bear in the end. Something similarhas happened to Fig. 8. The original mean is μo = 0.2854, andit can be seen that the HE produced a brighter result in that case,way too bright in some areas, particularly the face of the womansitting in the front.

    Wang and Ye [5] proposed a technique that yields an im-age with a similar brightness level as the original one. Theidea is to find a specified histogram fZ(z), with mean oraverage level of brightness that is equal to the original onesubject to the constraint that the entropy is maximum. Theycalled this technique brightness-preserving HE with maxi-mum entropy (BPHEME), and since the uniform distributionhas maximum entropy, this condition offers excellent contrastas well.

  • 1568 IEEE TRANSACTIONS ON INSTRUMENTATION AND MEASUREMENT, VOL. 60, NO. 5, MAY 2011

    Fig. 6. Original image. (b) Result obtained using the HS by simply smoothing the original histogram.

    Fig. 7. CDF of the original and specified histograms. The necessary steps toaccomplish the HS are shown with the arrows.

    Mathematically, the method is expressed as

    maxf {−fZ(z) ln fZ(z)dz} , s.t.⎧⎨⎩

    fZ(z) ≥ 0∫ 10 fZ(z)dz = 1∫ 10 zfZ(z)dz = μo

    (6)

    for z ∈ [0, 1] and μo =∫ 10 rfR(r)dr.

    A functional can be formed as

    J (fZ(z)) = −1∫

    0

    fZ(z) ln fZ(z)dz + λ1

    ⎡⎣ 1∫

    0

    fZ(z)dz − 1⎤⎦

    + λ2

    ⎡⎣ 1∫

    0

    zfZ(z)dz − μo⎤⎦ (7)

    where λ1 and λ2 are Lagrange multipliers associated with theconstraints in (6). This is solved using the calculus of varia-tions, i.e., ∂J/∂fZ(z) = − ln fZ(z) − 1 + λ1 + λ2z, solutionof which is given by fZ(z) = eμ1−1eλ2z for z ∈ [0, 1].

    Using constraints

    fZ(z) ={

    1, if μo = 0.5λ2e

    λ2z/eλ2 − 1, if μ0 ∈ (0, 0.5) ∪ (0.5, 1)

    once again, for z ∈ [0, 1], the second Lagrange multiplier canbe found as μo =

    ∫ 10 zfZ(z)dz, yielding μo = (λ2e

    λ2 − eλ2 +1)/λ2(eλ2 − 1), which can be found using a lookup table assuggested in [5] or by an iterative algorithm that yields a better

    solution to the Lagrange multipliers as the one presented in [6]and used in this paper.

    Fig. 9 shows the result obtained with this method. Note howkeeping similar brightness results in an image that is also asdark as the original but with an enhanced contrast. However,the results in the dark region on the right are not as good as thatwith HE.

    B. Contrast Enhancement by PiecewiseLinear Transformation

    Recently, Tsai and Yeh [7] developed a contrast enhancementtechnique based on a piecewise linear transformation (PLT)function T (ri) described as

    Tk−1(ri) =(sk − sk−1)(vk − vk−1) (ri − vk−1) + sk−1

    for k = 1, 2, . . . , V (8)

    where V is the total number of segments that is equal to the totalnumber of valleys minus 1, which is found in a smooth versionof the original histogram, the vk values are the valley locationsof the different modes found in histogram ri ∈ [vk−1, vk], andthe sk values are computed as

    sk =vk∑

    k=0

    fR(rk) for k = 0, 1/(L − 1), 2/(L − 1), . . . , vk.(9)

    In order to find the valleys, the method first filters the originalhistogram with a low-pass Gaussian filter with standard devia-tion σG, which is equal to the most frequent distance betweenvalleys in the original histogram. To compute σG, the maximumdistance between valleys Wmax is used to generate a histogramof distances hd divided into ten equal segments between 0 andWmax, and σG is chosen as the most frequent one, i.e., the onecorresponding to the maximum value in histogram hd.

    Fig. 10 shows the image obtained using this method. Notehow the dark areas have more contrast and how the bright areaswere not as emphasized as with BPHEME. Note how the modeswill be equalized, yielding a mean value for each mode that itis approximately at the center of each distance between valleys.The brightest mode (the last one) in the specified histogram islocated between 0.92 and 1, and its mean is in between thesevalues. However, in the original histogram, that mode is shiftedtoward 0.9961. This explains why there are not as many bright

  • THOMAS et al.: HISTOGRAM SPECIFICATION: A FAST AND FLEXIBLE METHOD TO PROCESS DIGITAL IMAGES 1569

    Fig. 8. (a) Original image. (b) Histogram equalization.

    Fig. 9. Image modified by the BPHEME, where µ = 0.28509. Original andspecified histograms.

    Fig. 10. Image and histograms obtained using the PLT method.

    areas in Fig. 10 as in Fig. 9, particularly on the face of thewoman in the middle.

    C. Piecewise Maximum Entropy Histogram

    As discussed in Section III-B, the separation of the differentmodes and the final transformation suggested in [7] yieldsgood results in a very simple and fast way. The same canbe said about BPHEME. Thus, both methods were presentedas excellent options for the image enhancement in consumer

    Fig. 11. Image obtained using the proposed method and original and specifiedhistograms.

    electronics such as digital photography. With this in mind,our method relies on the application of the concepts used inboth approaches but in a way that the proposed method canovercome some of the difficulties faced from certain type ofimages. It is also implemented in a simple way and executesfast.

    The new method that we named piecewise maximum entropy(PME) relies on the idea that the separation of the modes asin the PLT approach offers very good results but can encounterproblems by shifting the modes’ means too far from the originalmeans. Therefore, instead of using a linear transformation, weproposed to form a piecewise transformation function in whichsegments yield the original means of the modes, maximizingtheir entropy as suggested in the BPHEME.

    For the discrete case, the normalized distribution of a discreterandom variable with outcomes defined in [0, v], where v ≤L − 1, that offers maximum entropy given a mean value μ isgiven by

    fZ(zi = i) = Cti for i = 0, 1/(L − 1), . . . , v/(L − 1)(10)

    where C and t can be found by using the two constraints, i.e.,

    v/(L−1)∑i=0

    fZ(zi) = 1 andv/(L−1)∑

    i=0

    ifZ(zi) = μ. (11)

  • 1570 IEEE TRANSACTIONS ON INSTRUMENTATION AND MEASUREMENT, VOL. 60, NO. 5, MAY 2011

    Fig. 12. (a) Original PME image. (b) Modified PME image. (c) Original and specified histogram used in (b).

    Let the original histogram fR(rk) for k = 0, 1/(L − 1),2/(L − 1), . . . , 1 be a mixture distribution that, for simplicity,will be assumed to have two modes A and B distributed asfRA(rk) for k = 0, Δv, 2Δv, . . . , v1, and fRB (rk) for k =v1 + Δv, v1 + 2Δv, . . . , 1, where Δv = 1/(L − 1) and v1 isthe valley found between the two modes. Moreover

    fR(rk) = pfRA(rk) + (p − 1)fRB (rk) (12)

    where p is the proportion of pixels in mode A with respect tothe total number of pixels in the image and (1 − p) is likewisefor B. If fRA(rk) and fRB (rk) are forced to be distributedas (10) with means of equal value to the original means,guaranteeing maximum entropy for the two modes, fR(rk)also has maximum entropy and can be used as the specifiedhistogram.

    Fig. 11 shows the results obtained with the proposed method.Note how the dark region on the right preserved the meanbrightness while achieving a good contrast and how the whiteswere forced to be present in the final specification but withoutcreating the same effect on the front woman’s face. The his-togram shows the final specification, and the circles correspondto the means of the original and specified segments indicatingthat the average brightness of the modes remained very similar.The dotted vertical lines indicate the location of the valleysthat correspond to the same locations used in PLT. Note howthe support of the first mode starts at 0 and the support ofthe last mode ends at 1 so that the blacks and the whites are

    considered in the final histogram. This will help on eliminatingthe slight darkening results found on final images reported in[7]. Note also how the PME does not seem to have excessivelybrightened the face of the woman in the middle, at the expenseof reducing the contrast from the face of the person at the back.The additional benefits of this method will then depend on theshape of the mode and the location of its mean. For example,note how, in Fig. 11, the mean of the mode located between 0and 0.4 is almost at the middle of the two valleys. For this mode,the PME yields a result for that region that is actually similar tothe PLT. Furthermore, if only one mode exists in the image, thePME will yield very similar results to the BPHEME.

    Further contrast improvements can be achieved if the valleysbetween the modes that have areas much smaller than therest can be eliminated, choosing a single valley in between.Additionally, the number of valleys between two consecutivepeaks that are close together should be reduced by eliminatingthe valley in the middle. There is no point of stretching thesesmall size modes, and these changes lead to the definition ofa histogram that stretch the contrast even more. In Fig. 12, thepeaks that are closer to 5 gray-level values or less are consideredas one, and the valleys of the modes in which the total area isless than 0.5% were also eliminated as indicated before. Note,for example, how this new histogram improves the contrast ofthe objects located in the shadows of the top shelf.

    The color implementation is based on converting the colorimages that are originally in the red–green–blue color modelto the hue–saturation–intensity (HSI) model and applying the

  • THOMAS et al.: HISTOGRAM SPECIFICATION: A FAST AND FLEXIBLE METHOD TO PROCESS DIGITAL IMAGES 1571

    Fig. 13. Note how the BPHEME darkens the image at the left slightly more than expected and introduces small bright artifacts on the man’s shirt. At the right,every single method, including the HE, performs reasonably well, but the PME seems to favorably smooth the brightness levels on the sun and does not accentuatethe lens glare shown at the right bottom. The PME also shows nicer smoothing for the shadows on the image on the left when compared with the PLT.

    techniques mentioned in this paper to the intensity level I toform a new HSI model. Examples of a contrast enhancementwith color images can be found in Fig. 13.

    Furthermore, three different illumination scenarios of thesame scene are presented in Fig. 14: 1) a bad contrast due to

    a dark case; 2) a good contrast from the original; and 3) a badcontrast because of a bright image. Cases 1 and 2 are particu-larly challenging. As expected, all the methods performed wellwhen not much contrast enhancement is needed; this can beseen in the images located at the center column. Similar results

  • 1572 IEEE TRANSACTIONS ON INSTRUMENTATION AND MEASUREMENT, VOL. 60, NO. 5, MAY 2011

    Fig. 14. Color image examples for pictures taken with dark, normal, and bright illuminations presented in the first, center, and last columns, respectively. Theimages at the first row are the original ones.

    as obtained in the previous examples can be seen in the rest ofthe images.

    IV. IMAGE ENHANCEMENT FOR SEGMENTATION

    To the best of our knowledge, there is no single automaticsegmentation algorithm that can deliver results accurately ondifferent types of images such as magnetic resonance imaging,thermal, synthetic aperture radar, etc. Even in cases involvingone type of imagery where, for example, illumination can

    vary drastically, frustration during the development of such analgorithm can build up rapidly.

    Thinking in general terms for the sake of robustness, letus consider what type of histograms can be easily segmentedregardless of the segmentation approach used. First, the his-togram has to consist of modes (values that occurs with thehighest frequency in a distribution) with very well definedvalleys. Second, the mixture probability distribution that can beapproximated from the histogram should ideally be smooth; thiswould facilitate on the detection of peaks and valleys. Thinking

  • THOMAS et al.: HISTOGRAM SPECIFICATION: A FAST AND FLEXIBLE METHOD TO PROCESS DIGITAL IMAGES 1573

    Fig. 15. Example of the HS using a manually designed specified PDF.

    Fig. 16. Example used to evaluate the effect of reducing the entropy.(a) Original image with only two gray levels. (b) Gold standard obtained bythresholding (a). (c) Original image with added Gaussian noise. (d) Histogramof (c) [(a) No noise; (b) Po = 0.21673 Pb = 0.78327; (c) noisy; (d) noisy].

    in this broad sense, one can infer that modifying an image insuch a way so that the final histogram has the characteristicsmentioned above would help on the segmentation part.

    Fig. 15 shows an image before and after the HS. Note how itcan be said that the transformed image is a better candidate forsegmentation. The regions within the background and withinthe object are smoother in the modified image. Quantitatively,the variance of the pixels within the object and the backgroundin the original image are 1910.9 and 1478.2, respectively, and1750.1 and 1227.9 for the modified image.

    The last example illustrates the potential for using the HS forsegmentation purposes; what remains is to find ways to specifythese histograms in at least a semiautomatic way as it was donein Section III.

    A. Semiautomatic Specification

    Let define the original PDF and the specified PDF as pO(z)and pS(z), respectively. We would like to have pS(z) resemble

    Fig. 17. Original and two specified histograms. Entropy values are 1.7636,1.6723, and 0.7846, respectively.

    Fig. 18. Percentage of misclassified pixels versus entropy ratio. (Horizontalline) Error of the original Otsu segmentation.

    a smooth version of pO(z). This can be accomplished by low-pass filtering the histogram in the frequency domain or bysimply averaging the samples in pO(z). Now, the amount ofaveraging will determine the number of modes (discernablepeaks) in the specified PDF; too much smoothing will eliminatemodes that are very close together. This, in fact, may be adesirable feature since, as suggested in [8], close histogrampeaks may be formed by the same object and should be con-sidered as one. Thus, the first step can be defined as pOf (z) =pO(z) ∗ w(z), where ∗ denotes convolution and w(z) is alow-pass filter. For example, w(z) can be defined as rect(z) = 1for 0 < z < dist, where dist is twice the distance betweenpeaks in the original histogram in case concatenation of thesepeaks is desired. Once again, the smoothing can be done indifferent ways such as in the frequency domain, but keep inmind that the support of the filter defines the elimination ofclosely spaced modes in the histogram. Smoothing a histogramis not a new idea. For example, it has been done before for

  • 1574 IEEE TRANSACTIONS ON INSTRUMENTATION AND MEASUREMENT, VOL. 60, NO. 5, MAY 2011

    Fig. 19. (a) Original segmentation. (b) Segmentation obtained using the HS.

    the estimation of noise variance when affected by variances ofspeckle noise or image edges [9] and noise reduction [10].

    The location of peaks zp and valleys zv can be obtainedby finding the zeroes of pD(z) = dpOf (z)/dz. With theselocations, one can design a specified histogram in differentways as discussed next.

    B. Specification by Double Smoothing

    This method is based on incrementing the value of theoriginal histogram at the position of the peaks by constant kpand the reduction of the values in the position of the valleys byanother constant kv followed by a second smoothing, i.e.,

    p(z) =

    [pO(z) + kp

    P∑i=i

    pO(z)δ(z − zpi)

    − kvV∑

    i=i

    pO(z)δ(z − zvi)]∗ w(z)) (13)

    where P and V indicate the number of peaks and valleys,respectively. Finally, to have a valid PDF

    pS(z) =p(z)

    ∞∫−∞

    p(z) dz. (14)

    C. Specification Using Gaussian Modes

    If all the modes in the original histogram resemble Gaussianones and have similar variances, then the specified histogramcan be defined by

    p(z) =

    [pG(z) ∗

    P∑i=i

    pOf (z)δ(z − zpi)]

    (15)

    where pG(z) has a Gaussian shape with a smaller standard devi-ation σG than the ones seen in the original PDF. Subsequently,(14) guarantees a valid PDF.

    D. Analysis of the Specified Histograms

    The histograms specified in (13) and (15) should have lowerentropy as defined by H = − ∫ p(z) ln p(z) in the continuouscase or H = −∑ p(zi) ln p(zi) in the discrete one, wherezi indicates the gray-level value, than the original ones. Theimplementation of the HS by (4) and (5) provides an approx-imation of the desired histogram with a reduced number of

    Fig. 20. Modified and original PDFs of the first example.

    gray levels, and this is the main reason of the entropy decrease.Furthermore, this condition should yield specified modes thatare sharper and should therefore be more separated from eachother, defining better valleys for segmentation purposes, as itwill be shown in the example here. This concept of sharperpeaks and minimum entropy leads to interesting compensationalgorithms for radar imaging, as explained in [11].

    The filtering part of the histogram leads to dithering, asexplained in [12] and [13], which is equivalent to adding noiseto the image. The PDF of the sum of two independent randomvariables is given by the convolution of their PDFs. If Yand W are these independent random variables distributed aspY (z) and pW (z), then X = Y + W is distributed as pX(z) =pY (z) ∗ pW (z). Since the shape of pW (z) is a valid PDF, thenall its values are positive, and we are in fact filtering pY (z)with a low-pass filter. As the previous suggestion was to averagesamples, W in that case is uniformly distributed noise.

    As mentioned before, the entropy of the specified histogramshould be less than the original one. As stated in [14], for anytwo independent random vectors Y and W such that both H[X]and H[Y ] exist, H[Y + W ] ≥ H[Ỹ + W̃ ], where Ỹ and W̃are two independent multivariate Gaussians with proportionalcovariances to Y and W , respectively. Therefore, if the originalPDF modes are in fact non-Gaussian but the filtering steps ap-proximate the specified PDF to Gaussian ones, then the entropyis less than the original histogram. If the specified histogramis a sum of Gaussians as specified in (15), the condition ofminimum entropy is clearly satisfied, too.

  • THOMAS et al.: HISTOGRAM SPECIFICATION: A FAST AND FLEXIBLE METHOD TO PROCESS DIGITAL IMAGES 1575

    Fig. 21. (Left) Original segmentation. (Right) Results obtained using the HS.

    In order to verify the above entropy discussion, an exam-ple using a simple segmentation technique based on Otsu’sthresholding [15] was tested. Fig. 16 shows the image used forthis example.

    Fig. 17 shows the first and last specified histograms used forthis simulation based on (15) followed by (14), changing thestandard deviations of pG(z) in (15)—a total of 16 differentstandard-deviation values have been used from 1 to 8. The orig-inal PDF in Fig. 17 refers to the histogram shown in Fig. 16(d).Fig. 18 shows the percentage of misclassified pixels versus theratio

    ∑pO(zi) ln pO(zi)/

    ∑pS(zi) ln pS(zi) of the entropy of

    the original histogram and the entropy of the specified his-togram. As it can be seen, reducing the standard deviations ofthe Gaussians yields lower entropy as the entropy ratio becomeslarger. It is interesting to note that reducing the entropy forthis example, i.e., defining narrower Gaussian modes, does notnecessarily yield fewer errors, as indicated in Fig. 18. Whatit shows in this example is that even a small reduction inthe entropy yields better results. This translates to almost aneffortless selection of parameters in (13) and (15) to obtaina better segmentation as the ones shown in the succeedingsubsections. By no means can the discussion presented here begeneralized for all images or all segmentation approaches. Whatis consistent, however, is that the modification does reduce theerrors for all the segmentation cases presented in this paper,as well as all the entropy ratios in Fig. 18. Testing all the majorsegmentation methods available is out of the reach of this paper.

    The approach presented here was tested using different seg-mentation techniques offered in MATLAB. The details of thesegmentation part can be found in the MATLAB documentationor the MathWorks homepage. None of these segmentationalgorithms were modified; the only difference was the inputimages that were modified with the proposed approach.

    E. Example Using Morphological Segmentation

    The first segmentation algorithm presented here is based ona series of basic morphological operations such as dilation,closing, and opening. The edges of the image are calculatedfirst using a Sobel mask, and these edges are then modifiedby the morphological operations to obtain a final segmentation.Once again, more details can be found in the MATLAB docu-mentation. Fig. 19 shows the results using (15). Note how themodified image presents smoother regions and how it can detect

    an object that the original segmentation algorithm missed. Notealso how the segmentation appears to follow the objects better.Fig. 20 shows the modified and original PDFs of this image.

    F. Example Using an Entropy Filter

    Fig. 21 shows the results of using (13) with a segmentationapproach that uses an entropy filter to calculate texture values.The entropy is calculated using a 9 × 9 mask, which givesan estimation of the “roughness” of the area. Morphologicaloperations then eliminate artifacts and fill gaps after the entropyfilter is used. Note how the specified image obtained betterresults for the segmentation of the two textures. Note also howthe images are almost identical. This corroborates the resultsfound in Fig. 18 in the sense that a small modification based ona specified histogram that almost has the same entropy as theoriginal histogram yields good results.

    G. Example Using Thresholding

    Here, classical segmentation by thresholding the histogramis investigated. Here, the minimum-error-thresholding (MET)[16] method is used to assess another thresholding approachaside from Otsu’s because of the excellent results of thistechnique reported in [15], in which 40 different thresholdingsegmentation methods were investigated.

    In order to have a quantitative analysis of the improvementachieved by using the HS, 100 images of a wide variety ofnatural scenes were tested, and the segmentation was comparedwith the database ground-truth segmentations performed byhuman observers [17]. Fig. 22 shows an example using the HSand MET segmentations.

    A quality metric R was defined as

    R =∑

    i |(SHi , SM )|∑i |SHi |

    −∑

    i

    ∣∣(SHi , SM)∣∣∑i |SHi |

    (16)

    where |x| denotes the cardinality of x, SHi is the segmentationdone by the ith observer (where the number of observers variesfrom more than three to less than five), SM is the segmentationdone by the method to be evaluated, the S̄Hi values are thebackground pixels from the ith observer segmentation, and(SHi , SM ) denotes the set of pixels corresponding to the regionin segmentation SHi that contains the pixels in segmenta-tion SM .

  • 1576 IEEE TRANSACTIONS ON INSTRUMENTATION AND MEASUREMENT, VOL. 60, NO. 5, MAY 2011

    Fig. 22. Examples using the MET technique with the HS. First column is the original image; second column corresponds to the MET segmentation (in green);third column is the human segmentation; and fourth column is the MET using the HS (in green). (Red caption) Value of the quality metric computed as in (16).

    TABLE IRESULTS OBTAINED USING THE HS ON 100 IMAGES. THE VALUESINDICATE THE AVERAGE VALUE OF THE QUALITY METRIC R AND

    SHOULD BE COMPARED WITH THE AVERAGE OBTAINED WHENUSING NO HS, WHICH IS EQUAL TO 0.090776

    For the metric defined in (16), 0 < R < 1, where 1 wouldindicate a perfect segmentation match between all the observersand the method. The caption in red in Fig. 22 shows thecomputed values of R for each example. Table I shows theaverage value of metric R obtained when using the 100 images

    following the two methods specified in (13) and (15). Parameterwh corresponds to the normalized cutoff frequency of the ideallow-pass filter used in pOf (z) = pO(z) ∗ w(z).

    H. Segmentation Using the HS as a Solo Approach

    At this point, one may wonder if the HS can be used as asegmentation approach on its own. It would just be a matter todefine the new histogram as two Dirac impulses, one for thebackground and the other one for the objects (assuming theyhave similar gray-level values).

    Let us consider the case of a mixture probability distributionp(z) = P1p1(z) + P2p2(z) consisting of two modes distrib-uted each as Gaussian; the PDF is defined then by

    pG(z) =P1√2πσ1

    e− (z−μ1)2

    2σ21 +

    P2√2πσ2

    e− (z−μ2)2

    2σ22 (17)

    where P1 and P2 are the probabilities of occurrence and P1 +P2 = 1. By specifying a histogram as two Dirac impulses, asindicated before, located right where the means of the Gaussianmodes are, the PDF of this mixture is

    pS(z) =P1√2πσ1

    δ(z − μ1) + P2√2πσ2 δ(z − μ2)P1√2πσ1

    + P2√2πσ2

    (18)

    which can be simplified to

    pS(z) =P1σ2

    P1σ2 + P2σ1δ(z − μ1) + P2σ1

    P1σ2 + P2σ1δ(z − μ2).

    (19)

    The optimal threshold that minimizes the average error forsegmentation is defined by [3]

    P1p1(T ) = P2p2(T ) (20)

  • THOMAS et al.: HISTOGRAM SPECIFICATION: A FAST AND FLEXIBLE METHOD TO PROCESS DIGITAL IMAGES 1577

    Fig. 23. HS used as a segmentation approach.

    which, for the case of the Dirac impulses, yields

    P1σ2δ(T − μ1) = P2σ1δ(T − μ2) (21)and for the Gaussian mixture

    P1e− (z−μ1)2

    2σ21 = P2e

    − (z−μ2)22σ2

    2 . (22)

    The case of the Gaussian mixture is well known that, for σ =σ2 = σ1, the optimum threshold is defined by [3]

    TG =μ1 + μ2

    2+

    σ2

    μ1 + μ2ln

    (P2P1

    )(23)

    Solving (21) by using a nascent delta function δ(x) =lima→0(1/a

    √π)e−x

    2/a2 , the optimum specified threshold TSis similar to (23), but σ = 0, which defines that the optimumthreshold, is just in the middle of the two Dirac impulses inthe specified PDF, i.e., TS = (μ1 + μ2)/2. This result is nota surprise since the specified distribution can be seen as theGaussian mixture with equal variances approximating zero. Theeffect of P2/P1 in (23) is not taken into consideration whenusing the HS, and this may cause trouble when one of the modesis too prominent compared with the other one. Fig. 23 shows anexample using only Dirac impulses as the specified PDF, that is

    p(z) =

    [P∑

    i=i

    pOf (z)δ(z − zpi)]

    . (24)

    The first column corresponds to the original images, the secondcolumn corresponds to the specified PDFs, the third columnshows the modified images, and the last column is the pixelpositions in the modified images with gray-level values lessthan 115. The segmentation is not extremely accurate, but itis not bad at all, considering how easy it was obtained.

    V. CONCLUSION

    The image enhancement method presented in this paper hasrun in less than 2 s using a 2-GHz personal computer and hasproduced satisfactorily enhanced images that yielded bad re-sults using the HE. By combining and improving two differentways to enhance the contrast, our method has compared wellwith respect to each approach and has solved some of the issuesof the original techniques. The method has also shown goodresults when used in color images. Additionally, the HS hasbeen proposed as a way to improve image segmentation. Thespecification of the final histogram has been done relativelyeasy, and all it takes has been the definition of a low-passfilter and the amplification and the attenuation of the peaksand the valleys, respectively, or the standard deviation of theassumed Gaussian modes in the final specification. Examplesshowing better segmentation have been presented, and thepossibility of using this approach as a standalone segmentationmethod has been also discussed. The attractive side of usingthe HS is the easy implementation that is needed to obtain

  • 1578 IEEE TRANSACTIONS ON INSTRUMENTATION AND MEASUREMENT, VOL. 60, NO. 5, MAY 2011

    considerably better results for enhancement and segmentationpurposes.

    REFERENCES

    [1] G. Thomas, D. Flores-Tapia, and S. Pistorius, “Fast image contrast en-hancement for general use digital cameras,” in Proc. IEEE Instrum. Meas.Technol. Conf., Austin, TX, May 2010, pp. 706–709.

    [2] G. Thomas, “Image segmentation using histogram specification,” in Proc.IEEE Int. Conf. Image Process., San Diego, CA, Oct. 2008, pp. 589–592.

    [3] R. C. Gonzalez and R. E. Woods, Digital Image Processing,2nd ed. Englewood Cliffs, NJ: Prentice-Hall, 2001.

    [4] M. Stamm and K. J. R. Liu, “Blind forensics of contrast enhancement indigital images,” in Proc. IEEE Int. Conf. Image Process., San Diego, CA,Oct. 2008, pp. 3112–3115.

    [5] C. Wang and Z. Ye, “Brightness preserving histogram equalization withmaximum entropy: A variational perspective,” IEEE Trans. Consum.Electron., vol. 51, no. 4, pp. 1326–1334, Nov. 2005.

    [6] G. J. Erickson and C. R. Smith, Maximum Entropy and Bayesian Methods.Seattle, WA: Kluwer, 1991.

    [7] C. M. Tsai and Z. M. Yeh, “Contrast enhancement by automatic andparameter-free piecewise linear transformation for color images,” IEEETrans. Consum. Electron., vol. 54, no. 2, pp. 213–219, May 2008.

    [8] A. O. Silva, J. F. Camapum Wanderley, A. N. Freitas, H. de F. Bassani,R. A. de Vasconcelos, and F. M. O. Freitas, “Watershed transformfor automatic image segmentation of the human pelvic area,” in Proc.IEEE Int. Conf. Acoust., Speech, Signal Process., Montreal, QC, Canada,May 2004, vol. 5, pp. 597–600.

    [9] W. Hagg and M. Sties, “Efficient speckle filtering of SAR images,” inProc. Geosci. Remote Sens. Symp., Pasadena, CA, Aug. 1994, vol. 4,pp. 2140–2142.

    [10] A. Wrangsjo and H. Knutsson, “Histogram filters for noise reduction,” inProc. SSAB Symp. Image Anal., Stockholm, Sweden, Mar. 2003.

    [11] J. S. Sok, G. Thomas, and B. C. Flores, Range Doppler Radar Imagingand Motion Compensation. Norwood, MA: Artech House, 2001.

    [12] P.-E. Forssen, “Image analysis using soft histograms,” in Proc. SSABSymp. Image Anal., Stockholm, Sweden, Mar. 2002.

    [13] R. M. Gray and T. G. Stockham, “Dithered quantizers,” IEEE Trans. Inf.Theory, vol. 39, no. 3, pp. 805–812, May 1993.

    [14] A. Dembo, T. M. Cover, and J. A. Thomas, “Information theoretic in-equalities,” IEEE Trans. Inf. Theory, vol. 37, no. 6, pp. 1501–1518,Nov. 1991.

    [15] M. Sezgin and B. Sankur, “Survey over image thresholding techniques andquantitative performance evaluation,” SPIE J. Electron. Imaging, vol. 13,no. 1, pp. 146–168, Jan. 2004.

    [16] J. Kittler and J. Illingworth, “Minimum error thresholding,” PatternRecognit., vol. 19, no. 1, pp. 41–47, 1986.

    [17] D. Martin, C. Fowlkes, D. Tal, and J. Malik, “A database of humansegmented natural images and its application to evaluating segmentationalgorithms and measuring ecological statistics,” in Proc. 8th Int. Conf.Comput. Vis., Jul. 2001, vol. 2, pp. 416–423.

    Gabriel Thomas (S’89–M’95) received the B.Sc.degree in electrical engineering from the MonterreyInstitute of Technology, Monterrey, Mexico, in 1991and the M.Sc. and Ph.D. degrees in computer en-gineering from the University of Texas, El Paso, in1994 and 1999, respectively.

    Since 1999, he has been a Faculty Member withthe Department of Electrical and Computer Engi-neering, University of Manitoba, Winnipeg, MB,Canada, where he is currently an Associate Pro-fessor. He has coauthored the book Range Doppler

    Radar Imaging and Motion Compensation. His current research interests in-clude digital image and signal processing, computer vision, and nondestructivetesting.

    Daniel Flores-Tapia received the B.Sc. degree inelectrical engineering from the Monterrey Instituteof Technology, Chihuahua, Mexico, in 2002 andthe Ph.D. degree in computer engineering from theUniversity of Manitoba, Winnipeg, MB, Canada,in 2009.

    He is currently a Postdoctoral Fellow atCancerCare Manitoba, Winnipeg. His currentresearch interests include biomedical Fourierimaging, biomedical signal processing, and electricalimpedance tomography.

    Stephen Pistorius received the B.Sc. degree inphysics and geography from the University of Natal,Durban, South Africa, in 1982, and the B.Sc. (Hons.)degree in radiation physics, the M.Sc. degree inmedical science, and the Ph.D. degree in physicsfrom the University of Stellenbosch, Bellville, SouthAfrica, in 1983, 1984, and 1991, respectively.

    In 1986, he was certified as a Medical Physicistby the Health Professions Council of South Africa,and in 2002, he obtained the Professional Physicistdesignation from the Canadian Association of Physi-

    cists. He is the Provincial Director of Medical Physics, CancerCare Manitoba,Winnipeg, MB, Canada, and is an Associate Professor with the Faculty ofMedicine and an Adjunct Professor with the Department of Physics andAstronomy, University of Manitoba, Winnipeg. His research interests includeadvanced imaging techniques and reconstruction, Monte Carlo simulation, andradiation transport/beam modeling for ionizing and nonionizing radiation. Hehas authored over 100 publications and presentations.

    Dr. Pistorius was the Chair of the Canadian Organization of Medical Physi-cists from 2006 to 2008. He has won a number of national and internationalawards.

    /ColorImageDict > /JPEG2000ColorACSImageDict > /JPEG2000ColorImageDict > /AntiAliasGrayImages false /CropGrayImages true /GrayImageMinResolution 300 /GrayImageMinResolutionPolicy /OK /DownsampleGrayImages true /GrayImageDownsampleType /Bicubic /GrayImageResolution 300 /GrayImageDepth -1 /GrayImageMinDownsampleDepth 2 /GrayImageDownsampleThreshold 1.50000 /EncodeGrayImages true /GrayImageFilter /DCTEncode /AutoFilterGrayImages false /GrayImageAutoFilterStrategy /JPEG /GrayACSImageDict > /GrayImageDict > /JPEG2000GrayACSImageDict > /JPEG2000GrayImageDict > /AntiAliasMonoImages false /CropMonoImages true /MonoImageMinResolution 1200 /MonoImageMinResolutionPolicy /OK /DownsampleMonoImages true /MonoImageDownsampleType /Bicubic /MonoImageResolution 600 /MonoImageDepth -1 /MonoImageDownsampleThreshold 1.50000 /EncodeMonoImages true /MonoImageFilter /CCITTFaxEncode /MonoImageDict > /AllowPSXObjects false /CheckCompliance [ /None ] /PDFX1aCheck false /PDFX3Check false /PDFXCompliantPDFOnly false /PDFXNoTrimBoxError true /PDFXTrimBoxToMediaBoxOffset [ 0.00000 0.00000 0.00000 0.00000 ] /PDFXSetBleedBoxToMediaBox true /PDFXBleedBoxToTrimBoxOffset [ 0.00000 0.00000 0.00000 0.00000 ] /PDFXOutputIntentProfile (None) /PDFXOutputConditionIdentifier () /PDFXOutputCondition () /PDFXRegistryName () /PDFXTrapped /False

    /Description > /Namespace [ (Adobe) (Common) (1.0) ] /OtherNamespaces [ > /FormElements false /GenerateStructure false /IncludeBookmarks false /IncludeHyperlinks false /IncludeInteractive false /IncludeLayers false /IncludeProfiles false /MultimediaHandling /UseObjectSettings /Namespace [ (Adobe) (CreativeSuite) (2.0) ] /PDFXOutputIntentProfileSelector /DocumentCMYK /PreserveEditing true /UntaggedCMYKHandling /LeaveUntagged /UntaggedRGBHandling /UseDocumentProfile /UseDocumentBleed false >> ]>> setdistillerparams> setpagedevice