Automatic thresholding of gray-level pictures using two-dimensional entropy

Automatic thresholding of gray-level pictures using two-dimensional entropy

COMPUTER VISION, GRAPHICS, AND IMAGE PROCESSING 47, 22-32 (1989) Automatic Thresholding of Gray-Level Pictures Using Two-Dimensional Entropy AH...

627KB Sizes 0 Downloads 48 Views

COMPUTER

VISION,

GRAPHICS,

AND

IMAGE

PROCESSING

47, 22-32 (1989)

Automatic Thresholding of Gray-Level Pictures Using Two-Dimensional Entropy AHMED Electrical

Engineering Department, 12th and Norris Streets,

S. ABLJTALEB* College of Engineering, Temple University, Philadelphia, Pennsylvania 19122

Received January 13,1988; accepted November 28,1988 Automatic thresholding of the gray-level values of an image is very useful in automated analysis of morphological images, and it represents the first step in many applications in image understanding. Recently it was shown that by choosing the threshold as the value that maximizes the entropy of the l-dimensional histogram of an image, one might be able to separate, effectively, the desired objects from the background. This approach, however, does not take into consideration the spatial correlation between the pixels in an image. Thus, the performance might degrade rapidly as the spatial interaction between pixels becomes more dominant than the gray-level values. In this case, it becomes difficult to isolate the object from the background and human interference might be required. This was observed during studies that involved images of the stomach. The objective of this report is to extend the entropy-based thresholding algorithm to the 2-dimensional histogram. In this approach, the gray-level value of each pixel as well as the average value of its immediate neighborhood is studied. Thus, the threshold is a vector and has two entries: the gray level of the pixel and the average gray level of its neighborhood. The vector that maximizes the 2-dimensional entropy is used as the 2-dimensional threshold. This method was then compared to the conventional l-dimensional entropy-based method. Several images were synthesized and others were obtained from the hospital files that represent images of the stomach of patients. It was found that the proposed approach performs better specially when the signal to noise ratio (SNR) is decreased. Both, as expected, yielded good results when the SNR was high (more than 12 dB). i- 1989 Acadcmlc Press, lnc

I. INTRODUCTION

Thresholding is a widely used tool in image segmentation where one is interested in identifying the different homogeneous components of the image [4]. it is useful in discriminating objects from background in many scenes, such as organs in scintigraphic studies, targets in forward looking infrared (FLIR) studies [14]. Edges can be detected as the boundaries of the different segments. Thresholding, however, is of limited value for textured images, i.e., inhomogeneous components. There are two kinds of thresholding: bilevel and multilevel. In the former, one assumes that the image is composed of two components, foreground and background that have distinctively different gray-level distribution. One then attempts to find the threshold value between the two groups. Each pixel of gray level that is above the threshold is assigned to the foreground (background) and that below is assigned to the background (foreground). In the multilevel, it is assumed that there are several components (segments) in the image, each of a homogeneous value of gray level. One then attempts to locate the values of the thresholds that can separate the components. Obviously, the multilevel situation is an extension of the bilevel one. In bilevel thresholding, the gray-level distribution (histogram) is usually assumed to have one valley between two peaks; each represents the gray level concentration *Present address: MIT, Lincoln Lab, Lexington, MA 02173 22 0734-189X/89 Copyright All rights

$3.00

0 1989 by Academic Press, Inc. of reproduction in any form reserved.

USING 2-DIMENSIONAL

ENTROPY

23

of one segment. The objective is to locate, effectively, the bottom of the valley which, hopefully, best separates the two groups or segments. There are two main approaches to locate the bottom of the valley: parametric and nonparametric. In the parametric approach, a model is assumed to have the probability density function of the gray-level distribution of each group; usually it is assumed to be normal. One then attempts to find an estimate of the parameters of the distributions using the given histogram. This results in a nonlinear estimation problem that is computationally expensive. The bottom of the valley is then obtained from these estimates [5]. There are several modifications to this approach such as prefiltering [2] or using numerically efficient algorithms to find the bottom of the valley [15]. This approach does not usually yield good results because of the fact that the distributions may not be normal and/or the bottom of the valley is not the best place to find a threshold. In the nonparametric approach, one is interested in separating the two gray-level distributions in an optimum manner according to some criterion such as within-class variance, between-class variance, total variance [8, 91, or entropy [7, 61. Other methods are also available [13, lo]. The nonparametric approach proved to be robust and more accurate than the parametric. This comes as no surprise as long as the gray-level distribution does not fit a known probability density function. The thresholding techniques that are based on the gray level alone, however, do not utilize all the information available in the image. The effect of the information not included becomes apparent as the signal to noise ratio (SNR) decreases. Thus, one would expect an improvement in performance if the spatial information about the interaction between the pixels is exploited. This was demonstrated in [l], where they used what was called the “M matrix.” It represents the probability of co-occurrence of two values of gray levels when the corresponding pixels are separated by a specific distance. The approach enhances the peaks and valley of the histogram but does not select the threshold. In the proposed approach, presented in this report, an attempt is made to utilize the spatial information and select the threshold. The separation between the two groups (background and foreground) was achieved by locating the maximum of a 2-dimensional entropy criterion. Both the gray level at each pixel and the average gray level at its neighbors were used to generate an entropy surface. The peak determines the gray level and the average surrounding gray level of the threshold. Thus, a pixel belongs to one segment if its gray-level value satisfies two conditions, not just one, as in the conventional methods. The proposed approach was applied to some real images that were obtained from the hospital files as well as some simulated data. It was compared to the l-dimensional entropy-based approach [6] under different SNR conditions. The results were in favor of the proposed method. In Section II, the conventional entropy-based approach is described and the newly developed approach is also introduced. In Section III, results, conclusions, and summary are given. II. AUTOMATIC

A. One-Dimensional

THRESHOLDING

Entropy-Based Approach

The basic idea behind this approach is to choose the threshold such that the information available in the two gray-level distributions of the foreground and the

24

AHMED

S. ABUTALEB

background appropriate

is maximized. The information is measured by the entropy. The steps are explained below: Let fly fi,. . . , f, represent the observed gray-level frequencies (histogram). The expression for the probabilities (percentage of occurrence of a specific gray level), pi, becomes: i = 1,2 ,...,

pi = f/N27

m,

(1)

where N2 is the total number of pixels in the image and m is the number of gray levels in the histogram. It is reasonable to assume that only foreground values make up clusters and the background values consist of noise. Setting the gray levels above a threshold value (s) equal to 1 and the rest equal to 0, results in a binary image. By maximizing the entropy criterion, with respect to s, the threshold is obtained. The entropy criterion, #(s), is defined by

G(s) = lnP,(l - f’,) + f&/P, + (H, - &)/(I

- P,),

(2)

where

H, = - i hlnpi)

(34

i-l

‘s = i Pi i=l H,=

- it (Pilnpi) i=l m ptn = C Pi

(3’4 (44 W)

i-l

(“in”

is the natural logarithm).

B. Two-Dimensional Entropy-Based Approach The spatial gray-level distribution and the gray-level distribution are both used in defining this criterion. The gray level of each pixel and the average gray-level value of its neighborhood are studied. The frequency of occurrence of each pair of gray levels is computed. This will draw a surface that, presumably, has two peaks and one valley. The peaks correspond to the foreground and the background. They can be separated by choosing the threshold the maximizes the entropy in the two groups. The method is described as follows: Let the gray level be divided into m values and the average gray level is also divided into the same m values. At each pixel, the average gray-level value of the neighborhood is calculated. This forms a pair: the pixel gray level and the average of the neighborhood. Each pair belongs to a 2dimensional bin. The total number of bins is obviously m X m and the total number of pixels to be tested is N X N. The

USING 2-DIMENSIONAL

Probability

Mass

Function

ENTROPY

25

(PMF)

FIG. 1. Schematic of 2-dimensional histogram (probability mass function).

total number of occurrence (frequency), fij, of a pair (i, j) divided by the total number of pixels, N*, defines the joint probability mass function, pij: viz., i and j = l,...,

Pij = f,j/N*,

m.

(5)

It will be assumed throughout this report that the distant diagonal components are very close to zero. Assume that there are two groups, A and B, that represent the foreground and background, with two different probability mass functions (PMF). If the threshold is located at the pair (s, t), then the total area under pij (i = 1,. . . , s and j = l,..., t) must equal one, since now pij in this region represent the conditional PMF (Fig. 1). Thus, a normalization process is needed and this results in a modified entropy for group A, H(A), defined as H(A)

= - fI

i

i-l

j=l

(Pij/P,,)ln(Pij/P,I),

(6)

where

(7)

Pst= - r: iPij. i=l j=l

Equation (6) can be rewritten as H(A)

= -(l/p~t)

k

i

i-l

j=l

[(Pij)ln(Pij)

= ln( P,,) + H,,/Ps,3

- (PijMps,)]

(8)

26

AHMED

S. ABUTALEB

where

In a similar manner, an entropy for group B is defined, H(B):

H(B)= - i==s+lf =

-[l/(1

I? [Pij/(l- P,t)]b[Pi/(1- J’s,>]

(10)

j=r+1

-

p,t)l

fl

i-s+1 = h-d1 - C,)

+ (Km

If

(P;j)[MPij)

-

141

-

P,t)]

(11)

j=r+l - H,,)/(l

- p,,).

02)

The expression for H(B) is valid as long as p, j = 0 in the two regions defined by i=s+l >***, m and j = 1,. . . , t and by i = 1,. . . , s and j = t + 1,. . . , m. This assumption is reasonable since in many situations the off-diagonal probabilities are of negligible value. The assumption made will reduce the computation time.

(d) FIG. 2. Image of a stomach, SNR = 6.4 dB: (a) true image; (b) image + gaussian random noise; (c) image after thresholding using 1D entropy; (d) image after thresholding using 2D entropy.

USING

The entropy-based viz,

function,

= ln(f’s,) + h/P,,

2-DIMENSIONAL.

27

ENTROPY

#(s, t), is defined as the sum of the two entropies,

+ h(l

- J’s,> + @Gm, - Hs,)/(l

- p,,)

= ws,o - f31 + HSJPS, + wmm - HstM1- w

(13)

The algorithm then searches for the values of s and t that maximizes $(s, t). This is where the threshold is located. C. Properties of #(s, t) and the Computational Algorithm If we assume that there is one distribution then s = t = 1 or s = t = m. In this case we have #(l,l) = \Il(m, m), and these are the end points of Jl(s, t). Since $(s, t) is a continuous real-valued function in the interval defined by 1 -C s < m and 1 c t < m, and since #(l,l) = #( m, m), then there exists a pair, 1 < s’ < m and 1 < t’ < m, such that I,!( s’, t’) is a maximum or a minimum; this a consequence of the mean value theorem [ll]. From the properties of 2D entropy [12], the

(a)

(b)

(d) SNR = 12.3 dB: (a) true image; (b) image + gaussian random FIG. 3. Image of a stomach, (c) image after thresholdmg using 1D entropy; (d) image after thresholding using 2D entropy.

noise;

28

AHMED

S. ABUTALEB

end points, a/(1,1) and +( m, m), are minimum values of J/(s, t). Thus #(s, t) attains a maximum at s’ and t’. Other properties of Jl(s, t) are described in [12]. The algorithm to obtain the s’ and t’ is very simple and iterative. The values of s and t are changed till we obtain the maximum of $(s, t), viz, max := 0; for (S = 1 to m) do begin for (t = 1 to m) do begin evaluate Il/(s, t) of eqn. (13); if Jl(s, t) > max then begin max := \cl(s, t); s’ := s; t’ := t; end; end; end: It is clear that this exhaustive search for the threshold values of s’ and t’ that

(d) FIG. 4. Image of one ellipse, (c) image after tbresholding using

SNR = 2.3 dB: (a) true image; (b) image + gaussian random 1D entropy; (d) image after thresholding using 2D entropy.

noise;

USING 2-DIMENSIONAL

ENTROPY

29

maximize #(s, t) is time consuming, and one might consider some algorithms such as the Newton-Raphson method to find the maximum. Obtaining the global maxima using the Newton-Raphson method, however, is difficult to obtain since there is no guarantee that #(s, t) does not have local maxima. Thus the exhaustive search given above seems to be the only possible solution. When compared to the 1D entropy, the 2D entropy takes more computational time (an order of magnitude increase). Thus, for more accurate thresholding one has to pay the price of more time.

III. RESULTS

The proposed 2D entropy based method was compared to the 1D entropy based approach for several images and different SNR scenarios. The noise was generated as a Gaussian noise with different values of the variance. The SNR is defined as the 10 log of the ratio of the noise-free image power to the noise power. At each pixel, the noise-free signal power is calculated as the squared value of the gray level. The noise-free image power is then the summation of these values over the whole image. The noise power is calculated in a similar manner. In some images, of high SNR, the results of the 2D entropy is a thinned version of the original image. Consequently, a dilation process [3] might follow the thresh-

(a)

(d) FIG. 5. Image of one ellipse, SNR = 11.8 dB: (a) true image; (b) image + gaussian random noise; (c) image after thresholding using 1D entropy; (d) image after thresholding using 2D entropy.

30

AHMED

S. ABUTALEB

FIG. 6. Image of two ellipses, SNR = 5.4 dB: (a) true image; (b) image + gaussian random noise: (c) image after thresholding using 1D entropy; (d) image after thresholding using 2D entropy.

olding. The dilation might be performed using, for example, a square of 4 pixels. This, in general, yields improved results. When the SNR was of large values both approaches (1D and 2D entropy) yielded comparable results. The power of the 2D entropy-based method becomes apparent when the SNR is reduced. In Fig. 2, a picture of a stomach is shown along with its noisy version (SNR = 6 dB) and the results of applying the two methods. As shown, the 2D entropy approach reproduces the shape of the stomach in a reasonable way while the 1D entropy approach shows a sponge-type of an image. In Fig. 3, the SNR was raised to about 12 dB, and, as expected, both methods yielded good thresholding capabilities. In Fig. 4, a synthesized image of an ellipse is presented (SNR = 2 dB). Again, the 2D entropy approach yielded a better estimate of the original ellipse. In Fig. 5, the SNR = 12 dB, and the results of both methods are close. In Fig. 6, two ellipses were synthesized and white gaussian noise was added. The proposed approach, again performed better than the 1D entropy method. In Fig. 7. the SNR = 12 dB, and as expected both methods yielded good results. It should be noticed that the small clusters of the noise can be eliminated by a simple labelling algorithm that retains only the big cluster. These clusters appear because of the noise. The results showed that indeed the 2D entropy based criterion for thresholding has better performance than the powerful 1D entropy based criterion. This comes at no surprise since the more information used the better the

USING 2-DIMENSIONAL

ENTROPY

31

(a)

(cl

(d)

FIG. 7. Image of two ellipses, SNR = 11.4 dB: (a) true image; (b) image + gaussian random noise; (c) image after thresholding using 1D entropy; (d) image after thresholding using 2D entropy.

thresholding capabilities become. The price paid for this increase in accuracy is the increased computational time. Currently extensions are being developed to assess the inclusion of the gradient and other features, and in this case nD entropy criterion will be used. The 2D entropy based approach is also being extended to multilevel thresholding. REFERENCES 1. N. Ahuja and A. Rosenfeld, A note on the use of second-order gray-level statistics for threshold selection, IEEE Trans. Systems Man Cybernet. SMC-8, No. 12, 1978, 897-898. 2. L. Davis, A. Rosenfeld, and J. Weszka, Region extraction by averaging and thresholding, IEEE Trans. Systems. Man Cybernef. SMCd,1975, 383-388. 3. E. Dougherty and C. Giardina, Imuge Processing-Continuou to Discrete, Vol. I, Prentice-Hall, Englewood Cliffs, NJ, 1987. 4. K. S. Fu and J. K. Mui, A survey on image segmentation, Pattern Recognit. 13, 1981, 3-16. 5. R. Gonzalez and P. Win& Digital Image Processing, 2nd Ed, Addison-Wesley, Reading, MA, 1987. 6. J. Kapur, P. Sahoo, and A. Wong, A new method for gray-level picture thresholding using the entropy of the histogram, Compur. Vision Graphics Image Process. 29, 1985, 273-285. 7. T. Pun, A new method for grey-level picture thresholding using the entropy of the histogram, Signal Process. 2, 1980, 223-237. 8. N. Otsu, A threshold selection method for gray-level histograms, IEEE Trans. Systems Man Cytwmet. SMC-9, No. 1, 1979, 62-66. 9. S. Reddi, S. Rudin, and H. Keshavan, An optimal threshold scheme for image segmentation, IEEE Trans. Systems Man Cybernet. SMC-14, No. 4, 1984, 661-665.

32

AHMED

S. ABUTALEB

10. T. Ridler and S. Calvard, Picture thresholding using an iterative selection method, IEEE Trans. Systems Man Cybernet. SMC-8, No. 8, 1978,630-632. 11. M. Rose&&, Introducr~on to An&&, Scott, Foresman, Glenview, IL, 1968. 12. J. Thomas, Statistical Communication Theory, Wiley, New York, 1969. 13. W. Tsai, Moment-preserving thresholding: A new approach, Comput. Vision Graphics Image Process. 29, 1985, 377-293. 14. J. Weszka and A, Rosenfeld, Threshold evaluation techniques, IEEE Trans. System, Man Cyberner. SMC-8, No. 8, 1978,622-629. 15. J. Weszka and A. Rosenfeid, Histogram modifications for threshold selection, IEEE Trans. Systems Man Cybernet. SMC-9, No. 1, 1979, 38-52.