NOTE
Moment-Preserving
Thresholding:
A New Approach
WEN-HSIANG TSAI
Depurtment of Information Science, Nutional Chiao Tung tJniversi[y, Hsinchu, Taiwan 300 Republic of China
Received August 1,1984
A new approach to automatic threshold selection using the moment-preserving principle is proposed. The threshold values are computed deterministically in such a way that the moments of an input picture is preserved in the output picture. Experimental results show that the approach can be employed to threshold a given picture into meaningful gray-level classes. The approach is described for global thresholding, but it is applicable to local thresholding as well.
’ 19X5 Academic Press, Inc
I. INTRODUCTION
Image thresholding is a necessary step in many image analysis applications. For a survey of thresholding techniques, see [l or 21. In its simplest form, thresholding means to classify the pixels of a given image into two groups (e.g., objects and background), one including those pixels with their gray values above a certain threshold, and the other including those with gray values equal to and below the threshold. This is called bileuel thresholding. More generally, we can select more than one threshold, and use them to divide the whole range of gray values into several subranges. This is called multilevel thresholding. Most thresholding techniques [3-S] utilize shape information of the image histogram in threshold selection. In the ideal case, the histogram of an image with high-contrast objects and background will have a bimodal shape, with two peaks separated by a deep valley. The gray value at the valley can be chosen as the threshold. In real applications, such histogram bimodal- ity is often unclear, and several methods have been proposed to overcome this problem [4-81 so that the valley seeking technique can still be applied.
Another direction of threshold selection is to evaluate the goodness of selected thresholds by a certain measure [9-131. One way is to use entropy information to measure the homogeneity of the thresholded classes (9-111 or the independency of the classes from one another [12]. Another way is to make use of the class separability measures used in discriminant analysis [13].
In this paper, we propose another threshold selection method based on the moment-preserving principle which has also been applied to subpixel edge detection [14]. Specifically, before thresholding, we compute the gray-level moments of the input image. The thresholds are then selected in such a way that the moments of the
thresholded image are kept unchanged. This approach may be regarded as a
moment-preserving image transformation which recovers an ideal image from a
blurred version. The approach can automatically and deterministically select multi- ple thresholds without iteration or search. In addition, a representative gray value can also be obtained for each thresholded class.
311
0734189X/85 $3.00
Copyright 0 1985 by Academic Press, Inc Al1 rights of reproductmn in any form resewed
In the remainder of this paper, we first describe the moment-preserving approach to bilevel thresholding. The result is next generalized to multilevel thresholding. A deterministic procedure to compute the threshold values is then described. Experi- mental results are also presented to support the validity of the proposed approach.
II. MOMENT-PRESERVING BILEVEL THRESHOLDING
Given an image f with n pixels whose gray value at pixel (x, y) is denoted by f(x, y), we want to threshold f into two pixel classes, the below-threshold pixels and
the above-threshold ones. The i th moment m i of f is defined as
mi = (l/n)C CfiCx9 Y)Y i = 1,2,3 ,... . (1)
x Y
Moments can also be computed from the histogram of
f
in the following way: mi = (l/n)Cnj(~j)i(2)
where nj is the total number of the pixels inf
with gray value zj and pj = nj/n. We also define mO to be 1. Imagef
can be considered as a blurred version of an ideal bilevel image which consists of pixels with only two gray values z,, and zr, where z,, -C zi. The proposed moment-preserving thresholding is to select a threshold value such that if all below-threshold gray values inf
are replaced by z,, and all above-threshold gray values replaced by zi, then the first three moments of imagef
are preserved in the resulting bilevel image g. Image g so obtained may be regarded as an ideal unblurred version of
f.
Let p. and p1 denote the fractions of the below-threshold pixels and the
above-threshold pixels in
f,
respectively, then the first three moments of g are justml = i pj( zj)‘, i = 1,2,3. (3)
j=O
And preserving the first three moments in g means the following equalities:
ml = mi, i = 1,2,3.
Note that
Po+Pl= 1.
The four equalities described by (4) and (5) above are equivalent to
pozoO + plzlo = mo,
pozb + plzi = ml,
pozi + pg,Z = m2,
(4)
(5)where mi with i = 1,2,3 are computed by (1) or (2) and m, = 1. To find the desired threshold value t, we can first solve the four equations described by (6) above to obtain p0 and pi, and then choose t as the p,tile of the histogram of f, i.e., choose t such that
In practice, there may exist no discrete gray value which is exactly the PO-tile of the histogram. Then, the threshold t should be chosen the gray value closest to the PO-tile. The equations described by (6) will be solved later when we discuss multilevel thresholding. Note that z. and zi will also be obtained simultaneously as part of the solutions to (6). They can be regraded as the representative gray values for the below-threshold and the above-threshold pixels, respectively.
III. MOMENT-PRESERVING MULTILEVEL THRESHOLDING
In the general case, we want to threshold a given image f into more than two pixel classes. To threshold f into N pixel classes, we need N - 1 threshold values t,, t,, . . . 3 t,,,-,. Let zi denote the representative gray value of the ith pixel class, and let pi denote the fraction of the pixels in the ith class. By preserving the first 2N - 1 moments of
f
and using the fact that the sum of all p, values is equal to 1, we get the following set of 2N equations:pot; + plz,o + . . . +pNz; = m,, pozA + plzi + . . * +pwzL = m,.
. . .
po~~N-* + plzfNH1 + . . . +pNziN-l = mZNel, (7)
which can be solved to get all pi and zi, i = 0, 1, . . . , N - 1. The method we use to solve (7) above will be described next. Once all pi values are obtained, the desired thresholds t, can be found from the histogram of
f
by choosing t, as the PO-tile, t, as the (p. + p&tile, and more generally, tj as the (p. + pi + . . . +pi-i)-tile, of the histogram off.
For convenience, the equations described by (7) will be called the moment-preserving equations.Based on Szego [15], Tabatabai [16] showed that the moment-preserving equations can be solved indirectly by executing the following three computation steps:
(i) solve the following linear equations to obtain a set of auxiliary values co, c1,...,cy+I:
corn0 + clml + a*. +cN-lm,-, = -mN.
corn, + clmz + ..a +c,-,m, = -mN+l,
. . 1
cOmNwl + clmN + 0.. +cN-lm,,_, = -mzNP,; (8)
(ii) solve the following polynomial equation to obtain the representative gray values zo, zl,. . . , z+i:
(iii) substitute all zi values obtained above into the first N moment-preserving equations described by (7) and solve the resulting equations to get po,pl,. . . , pNP1.
To guarantee that the N solutions of the polynomial equation (9) are all distinct and real-valued, at least N distinct gray values must exist in the input image f [15]. For N less than 5, analytic solutions to (9) can be obtained. For N no less than 5, as is well known, no close-form solution to (7) exists. Numerical analysis procedures like the Newton’s method need to be applied. The complete analytic solutions of the three computation steps above for N = 2, 3, and 4 are summarized for reference in the Appendix.
IV. AN ILLUSTRATIVE EXAMPLE
The effectiveness of moment-preserving thresholding is demonstrated with an
example in this section. Figure la shows the pixel gray values of a given image, which includes two areas with roughly constant gray values (the leftmost 4 columns and the rightmost 4 columns) and a blurred boundary (the central 4 columns). From the distribution of the gray values, it is reasonable to expect the following results:
(1) bilevel thresholding-the leftmost 6 columns as a thresholded class and the rightmost 6 columns as the other;
(2) trilevel thresholding-the leftmost 4 columns as a class, the boundary portion (central 4 columns) as a second class, and the rightmost columns as the third;
(3) quaterlevel thresholding-the leftmost 4 and the rightmost 4 columns as two classes, and the central left 2 (columns 5 and 6 from the left) and the central right 2 columns as the other two classes.
~~1
~iil:i:ii:
~iii:ii:iji:,lii.i.l’i.
I(ylll:-:lI.:II;l.IIII
Using the analytic solutions provided in the Appendix, we get the computational results as follows:
(1) bilevel thresholding-
(i) representative gray values:
z. = 12; z1 = 38; (ii) class fractions:
p. = 0.498; p1 = 0.502; (iii) selected threshold:
t, = 27; (2) trilevel thresholding-
(i) representative gray values:
z. = 10; zr = 25; z2 = 40; (ii) class fractions:
po = 0.361; pl = 0.277; p2 = 0.362; (iii) selected thresholds:
t, = 18; t, = 30; (3) quaterlevel thresholding-
(i) representative gray values:
z. = 10; zt = 19; z2 = 31; z3 = 40; (ii) class fractions:
po = 0.311; p1 = 0.191; p2 = 0.190; z3 = 0.308;
(in) selected thresholds:
t, = 11; t, = 27; t, = 37.
The thresholded images are shown in Figs. lb, c, and d which are exactly the expected results mentioned previously except only three pixels (marked with * in Figs. lc and d. This means that the moment-preserving principle is indeed feasible for meaningful image thresholding. This fact is further verified by experimental results described next.
V. EXPERIMENTAL RESULTS
The proposed approach has been tried on a lot of images. Some results are shown in Figs. 2-7. Each image tested is of the size 80 by 60. Each figure shown includes a tested image in (a), the histogram of the image in (b) with computed threshold values
! I i:iiii;s
-. ; ,,~~“.““I,..“~.,“..,~““~ .,,.,,,. a.,* .,I. * I,‘,....
:::i::::::::::::::::::::.::::::::::::::::::::::::::~:::::.:::::!~:::::::~~:!~~,~.: . . . . . . . . . . . . . ! . . . . . . . !?? v.. . . . * c ; : : : ; : : : : . . . . . . . . . . . . . . ::::::.::::::- ‘, . . . I_- : :
s--11-- !====-- . ..-..- -- -e=c- --- . s==cz. --.- . s---
.-.-
b.
---
_ __
--
.?rc U...“..a#.wu”I~nu” ... ,,, ... . ... . ... #. ... ..~ ..,, ... m ... ..m... ... I.” -- ... . . . ... “““““““-“-‘:‘~‘-‘~-‘~‘~~“~~“~-“-’”’”’ l ...- .... ~.~..~..~~...~.~~.~~~~.- ... ... . ... . . .. . * ... . ... . ... . ... ~., ...,.l...., ... ... . ... . . .. . ... . ... ..- .. * ...,,...ll.~ ... l ... _ ... . ... . . . ... v ... . . . * ,,(.,( = ,,.,,,),(,,, 11,,~ ... ‘“‘“““‘“‘“‘--“‘“““‘““‘-“~:~~::::::-~~~~~~~: - ~...~.~..~...~~ . ..- . ‘ .... . . ... ..(... ... - v.. ... . . . ... . . ‘,,,,, ,,.,,..., , *,.-I - ,,,,,,,,,.,, * .... . ... l ... . ... . *. ,(,,.,,,,,, * 11.111, ... ... ~:::::::;;;:;!:;:‘:;;:::p .,.,,,,,,,,,,,, 1.1 ... ::::::::::,x-.,, ... ... -. ... ...1...* * ~.~~~....,,1~,, ... ... ..--. .,, ... * ... ::::::::::::;;:;;;;;:;:’ UI....,I..1..., ... ::::::::::--- ... ... ., . .... ..,... . :::::::::::!:;:;;:;;:;, --‘:;;:;;;;:::“~;;;::::::: ... ::::::::::;:::::::;::, -“““““’ -. ... ~..,...ii...lllU ;:::::::!::--=: ... .._ _ _- :;:.::* -..,~~~.~~~~.~..,,-...l,.l...~~. ... .._U .” m.... . ..- :::::::::::::;!;;;;::I -I, ... ,,,,, -...1..., ... ... . -“‘““‘“““““‘-‘~~~;~;;;~~;;~~~~~~~~~~ ... ... . -.- . .. w ... .... ... . . . ,,,.,.-., .. *. ... . ---::::::: :::::::::;;;::;:!:;;;-,,...,.-.;;;::~;;;;!:::::: : ::::::::::,, =. ... ._ _ ... - -, ... ,, - ... :::::::::;;;~;~;;~~~‘-‘““““““” - ... ..~~..., . . “- ,,,,I... ,,,I#. . * ... -‘-““---“* ... - ._ ... .... ., ... ... _, ... ..-. ... .,,,,,, w 1,111, *--.-. ... .“W.M ... l,,,, ... ... ... . . . ... ,,,,,,,,, - ,111, ~.,...~,11111.- ... .I... . - m... - ... ... ,,,,,,,,, .~,,,.~~..~,,~~~1(..~.“..,*.1... ... . -..m...- - ... w..., ... l,,, *‘“-,,1,1,11,,*,,,,‘,,,*,,“‘~~,~~”~~‘,,*~~“”~”~ .. ..11.-... ... :::-::y . ... . ... C-m. l ... .., . ‘.I‘,,,,, -,I,~,*,, ,,,,,, ““.3 .~~~~~...~.~...1,,.~.,...~~.~~~.~.~..~~..”....” ... ... ... . r 111,111 UI ,,,,,, I,,,,, II...., ... I.I.UI-- ...::::::::-.--P e ... ... . ... ‘ ,((, -I ,,.,,*,,,,,,, ‘ ...,.~..I.Y., ... ::::::::~~~--“-‘-‘----“““’ e...-...- .- . ,111 -....~~..~~~~~W ... . . . . m....-...-..-. - ... ... . . . . ~.n .(,..., ... “:.::,I;;;:~;;;;;:!::::::::: ... ... ..I. ,,,,,,.,, u. ,,,,.... ... . ... u,,~ ... . ... ~....~~.--“--~~~~..~-~.~~...- ... ... ... ..I . ,,,,,,,,11’1,,11’~‘~‘1‘,11”~~iI’~ ... ..IU...‘... ..__ ._ 1 .I_...^._.._...._-_” _ ...
..,,‘,‘,,11...., ... . ..~~~.~U...~ ... .’ ... “... .-. . . ..- ... ..- ... ... ... * ,,,~,‘,,,,,,,,,,,,,,,, ..,..., 1 **,,,,u,*,,,, 1.11.. ... ... .___. v.. .... ., ... . p.,.-,,,,, 11,111, ,,.,..,,..~..~...,~.~.~ ... *“““‘---~.--.-.--~)‘----.‘.““’ “_ -- ... ... . . . ..-.., .... (, ... * ,,,...)....,.,..., ... ::::::::~~;;;;:‘---“---““‘~’ ... .., ... Iu, ... ..I. Ml,, *,.,*,,,.~...,11,,.,,,...~ ... ... ..-..-.-.--...--- ... ~~~~~~~~~~;~;~;~;;:‘~...“‘...””..”...,.~~~...~.~~ B 1.1,. .. ,,,,,,,,, ~~~~‘1,,111,,,, Illl~lllltli,~- ... -.---...~--.r--.- m...em-.-.- .-. ... ... ... . ..-1, ‘...~. ::::::::-~ --- Bm...m..m .. .“.m...-..“..-.... ,,,,,,,,,, ~,1,,,~~~~,,1#1*1 ... ... ... ... . . . ..( ... *. ... “.“““-m - . “so.- . - V..., ..,,,,,,,, 1-1111,‘~~~1,**‘1*’ ... . ,,,(,, ... v ... .,,,,,,,,,,, 1~‘11111~- ..,,,,...- ... :-:::::.,r,;=-‘mlmml... . ._.._....__ w-.-r...-. .“- . ... ... ...“. .._ ... .,,,,,, *,,,,11-&,111~‘~~~ ... ..ll..., ... * ... *-* ... ..__._. ._ ... .... _ .. ^ ... . ..“. ... ... ... . . . ..l...~... ... -. ... . ... ... . ---. ... .__ -. _ ._ _ .. ._ _ ... ., ... . . ,..,..., ., I(...*, * .,., ... - ... *. ... ..). ,,.,, ... ~...ll.-..-....“~...~..-.-...-”...-.r-. ., ~‘~~~~“1*1111‘,1,,,~,*,,“’ .,,,,,,,,,, * ,(,,, u, ... . ... ... ..~.~....,,,.W .,,,,111111’ ... - ,),, *. .. .,(. ... ,, ( , ... , . ... . . . .,(,,,,,,,, ... . . ... . ... , , , ... , ::::::::~::.?“~~::::::::~:==:.:::::: ... I;Lc ... . ... -...- .. ... . . . ... . * ,,,,(,,,” ... . . . . ... ,...,..., ... . ..-. ... ..“. ... _ _...._...._ ...” .. _ .._ ... ... . . . * ,,,,,(,, ... . . ... ..-,...,..., ... ... ... * ,,,,,,,,,,,,,,,,,,,,,,,, w ... l, ... . :::::::: p:..* .-. ... ..r...-...- .... . ... - ::::::::: dL.e .... ...“. ..- ... . ... . -. ... ..-.-...- ... _. ... .,,,,,, I,‘,,.,,,,,,,,,,,,,, lw...l., .w - .._ .. . ... ... ... .,,,,,,a ml ,#I 11,011, -,~,lv~~~UI ,,,,~~‘~1,~-~~‘-“111111,,,,~~~~~~,
.._..._...__ ... -. ..-.-.-.‘C.-...IL.. . ... .. . ... ... .,,,,,, I I ,~.I,,,# ,,,,, ,111 ,,11,,,~~~~,~~,,,~~-~,,,,,,,,,,,.~~.~~~, d,:.::. ... ..~...L...“.~ .-. ..‘.” __ ... c “‘--” . . ... ~.,~1,,,,#.l,~‘,,,, -1,111” ,111 ~‘l,~~,~~“‘l,~,~,L(,,,,,,,,~,,,~~~~~~, ... . m .... -. ..-- .__ ... *m-r- -“I “...ll..-.m....W .@. -.w- ... ---...“m”o..” FIGURE 8
marked by “ v”, and the thresholded result in (c) with pixels filled with representa- tive gray values.
Figures 2 and 3 are the results of bilevel thresholding applied to some characters and a pattern. From Figs. 2b and 3b, we see that the computed threshold values are close to the bimodal histogram valleys. Similar results are also found in other cases described in the following. Figures 4 and 5 are the results of trilevel thresholding applied to a cell image and a three-color wheel pattern. Either of the input images shown in Figs 4a and 5a includes roughly three classes of gray values. And the thresholded images shown in Figs. 4c and 5c indicate that the pixel classes have been successfully thresholded. Similar situations can also be found in Figs. 6c and 7c which are the results of quaterlevel thresholding applied to Figs. 6a and 7a. Either image shown in Fig. 6a or 7a includes roughly four classes of pixel gray values. Finally, we include Fig. 8 to show the results of applying different-level thresholding to a single picture, the image of a girl.
APPENDIX
The solutions zi and pi (i = 0, 1, . . . N - 1) to the moment-preserving equations
for N-level thresholding (N = 2,3,4) are summarized here for reference conve-
nience. Detailed derivations of the solutions are not included. Interested readers are referred to any mathematical handbook like [17]. In the following, M,, denotes the value 1 and m, with i > 0 are computed according to Eq. (1) or (2). After all p, values are obtained, the ith threshold value ti is selected as the (Cli$pk)-tile of the input picture histogram.
A. 1. Bilevel Thresholding Solutions
(ii) (iii) Pd = Jo f, ; I I PO = (l/P,) 2 I 1 iI I ; Pl = 1 - Po-
A.2. Trilevel Thresholding Solutions ma ml m2 6) cd=ml m2 m,; m2 m3 m4 -3 ml m2 co = (l/c,) -m4 m2 m3 ; -m5 m3 m4 ma -m3 m2 cl = (I/C,) ml -m4 m3 ; m2 -5 m4 “0 ml -m3 c2 = (l/c,) ml m2 -m4 . m2 m3 -m5 (4 z,,= -cd3-A-B; z1 = -C2/3 - W,A - W,B; Z2 = -C2/3 - W,A - W,B,
where A, B, W,, and W, are as follows:
A = (co/2 - c1~2/6 + cQ27) i - [(co/2 - clcJ6 + ~;/27)~ + (cl/3 - c;/9)‘] 1’2]1’3; B = - (cl/3 - 4/9)/A; Wl = -l/2 + i(6/2); W2 = - l/2 - i(J?j/2) ; i=m. 1 1 1 (iii) pd = zo Zl z2 zo” zf z; 9 m0 PO = (l/P,) “1 1 1 Zl z2 ; m2 zf zz 1 m, 1 p1 = (l/p,) zo ml z2 ; zi m2 zz
A.3. Quaterlevel Thresholding Solutions mo ml m2 m3 (9 Cd = ml m2 m3 m4. m2 m3 m4 m5 ’ m3 m4 m5 m6 I -m4 ml m2 m3l -m5 m2 m3 m4 ‘0 = (l/‘d) -m6 m3 m4 m5 ; -ml m4 m5 ml5 mo -m4 m2 m3 ml -m5 m3 m4 c1 = (1/cd) m2 -m 6 m4 m5 ; m3 -ml m5 m6 Imo ml -m4 m3l mo ml m2 -m4 ml m2 m3 -m5 ‘3 = (l/‘d) m2 m3 m4 -m . 6 m3 m4 m5 --ml
(ii) z. = ($)( -(c,/2 + A) - [(c,/2 + A)2 - 4(Y + B)]1’2);
z1 = ($)( -(c,/2 + A) + [(c3/2 + A)2 - 4(Y + B)y2):
z2 = (i)( -(c,/2 - A) - [(c,/2 - A)2 - 4(Y - B)y2);
z3 = ($)( -(Q/2 -A) + [(Q/2 - A)2 - 4(Y -
B)y2j,
where A, B, and Y are as follows:
id = (;)( c; - ‘k, + 8Y)1’2; B = (c,Y - c&i; Y=cJ6-C-D; C = [G +(G’ + H3)1’2]1’3; D = -H/C; G = (&)(72c,c, + 9c,c,c, - 27~; - 27c,c,2 - 2~;); H = ($)(3c,c, - 12c, - c;).
(iii) 1 1 1 1 zo Zl z2 23 Pd = ~0’ ~1’ 2; ,$ ; z; z1’ z2 3 z3 3 1 1 1 1 ml 5 z2 z3 PO = (‘/Pd) m2 zf zz zi ; m3 4 z2 3 3 z3 1 1 1 1 z. ml z2 z3 Pl = (l/P,) ~0’ m2 ~2’ 232 ; zi m3 zz zi 1 1 1 1 20 Zl ml z3 P2 = (l/P,) 20’ zf m2 ~3’ ; 4 Zl 3 3 m3 z3 P3 = 1 - PO - Pl - P2.
Note that in all the three types of thresholding above, we assume all zi values, after they are obtained in step (ii), are sorted into an increasing order (with z. as the smallest) before they are substituted into step (iii) to compute pi values.
REFERENCES
1. A. Rosenfeld and A. C. Kak, Digital Picture Processing, Vol. II, Academic Press, New York, 1982.
2. J. S. We&a, A survey of threshold selection techniques, Comput. Graphics Image Process. 7, 1978,
259-265.
3. J. M. S. Prewitt and M. L. Mendelsohn, The analysis of cell images. Ann. New York Acad. Sci. 128
1966, 1031-1053.
4. C. K. Chow and T. Kaneko, Automatic boundary detection of the left views from cineangiograms,
Comput. Biomed. Res., 5 1972, 388-410.
5. S. Watanabe and CYBEST group, An automated apparatus for cancer preprocessing, Comput.
Graphics Image Process. 3, 1974, 350-358.
6. J. S. Weszka, R. N. Nagel, and A. Rosenfeld, A threshold selection technique, IEEE Trans. Comput.
C-23, 1974, 1322-1326.
7. D. P. Panda and A. Rosenfeld, Image segmentation by pixel classification in (gray level, gradient)
space, IEEE Trans. Comput. C-27, 1978, 875-879.
8. J. S. Weszka and A. Rosenfeld, Histogram modification for threshold selection, IEEE Trans. Systems
Man Cybernet. SMC-9,1979,38-52.
9. G. Leboucher and G. E. Lowitz, What a histogram can really tell the classifier, Pattern Recognition
10, 1978, 351-357.
10. T. Pun, A new method for gray-level picture thresholding using the entropy of the histogram, Signal
Process. 2, 1980, 223-237.
13. N. Otsu, A threshold selection method from gray-level histogram, IEZX Truns. System.? MUU Cybernet. SMC-9, 1979, 62-66.
14. A. J. Tabatabai and 0. R. Mitchell, Edge location to subpixel values in digital imagery, IEEE Truns
Pattern Anul. Mach. Intell. PAMI-6, 1984, 188-201.
15. G. Szego, Orthogonal Polynomials, Vol. 23, 4th ed., Amer. Math. Sot., Providence R. I., 1975.
16. A. Tabatabai, Edge Location and Data Compression for Digital ImagerJI, Ph.D. dissertation, School of
Elect. Engrg., Purdue University, Dec. 1981.
17. C. E. Pearson (Ed.), Handbook of Applied Mathematics, 2nd ed., Van Nostrand-Reinhold. New York.