Chapter 2. Multi-level Thresholding Approaches for Image Segmentation
2.3 The Proposed Fast Combinatorial Scheme for Efficient Selection of Multiple
2.3.1 The Combinatorial Search Scheme of Optimal Threshold Set Selection 21
To obtain the optimal threshold set T = {t1,..., tn,…, tk}, it is necessary to evaluate all the possible threshold sets to optimize the aforementioned criterion functions
ψ
( )T . Traditionally, one can obtain the optimal threshold set by a simple and iterative, but exhaustive search procedure. The values of all thresholds in T are iteratively incremented andevaluated till the maximum or minimum
ψ
( )T is obtained, and is performed as the pseudo code procedure presented in Figure 2.1._ 0
Figure 2.1. Conventional search procedure of optimal
ψ
( )TIt is obvious that the exhaustive search for finding the optimal
ψ
( )T is very time consuming. In order to obtain the optimal threshold set with k thresholds,( 1) ( 2)... ( 1) !
( )!
L L L L k L
× − × − × − + = L k
− possible threshold sets must be evaluated! Thus, for example, when the number of thresholds is k = 3, and the number of gray levels L = 256, the number of potential threshold sets for which the criterion function
ψ
( )T must be evaluated is 16581120. This is because many equivalent threshold sets are repeatedly evaluated. In addition, this implementation is not scalable and parameterizable for variable amount of thresholds in multilevel thresholding, that is, the thresholding procedure cannot beadapted to the changing of the number of desired thresholds k.
To overcome these above mentioned drawbacks which arise from extending bi-level thresholding to multilevel thresholding cases, we introduce a combinatorial scheme to suppress the computation complexity, and to accomplish the parameterization of a desired threshold number k. The iterative procedure of evaluating all potential threshold sets for determining the optimal threshold set can be viewed as a combinatorial problem [69]. So we implement an efficient combinatorial generation procedure to obtain all potential threshold sets T. This combinatorial scheme avoids duplicate evaluation of equivalent threshold sets, and significantly reduces the amount of computation required.
Looking at it as a combinatorial problem, the multilevel thresholding for selecting a set with k thresholds can be regarded as an “L choose k” problem, i.e.
( )
kL . The combination of a potential threshold set is denoted as a k-subset of the set of L gray levels. There are( )
Lk =k L k!( L−! )! k-subsets possible in L gray levels. The task now of the multilevel thresholding is to find all these possible threshold combinations and determine the appropriate threshold set which achieves the optimal condition of the criterion function.In this study, we employ the Twiddle algorithm [70] to obtain all candidate combinations of thresholds. The Twiddle algorithm is a simple and efficient method for generating a threshold set. It has several features: 1) at each stage, only one element of the combination, i.e. C[z] as mentioned below, is altered for generating a new successive combination of numbers (threshold values), 2) this algorithm is order preserving in the sense that the elements of each threshold combination generated in each stage are strictly increasing with respect to the order of the set of L gray levels.
We implement this algorithm using the C++ programming language, including several
necessary modifications for utilization in the C++ environment. Let the array G[0…L-1] store all elements of the set of L gray levels; and let the successive combinations be stored in the array C[0…k-1]. Consequently, one consecutive k-subset of combinations of thresholds is stored in this array in each stage of performing the Twiddle,. Then the auxiliary integer array p[0…L+1] is utilized to store the states of the Twiddle procedure. The auxiliary array p is initialized as follows: p[0] is set equal to L+1; p[1] through p[L-k] are set equal to 0;
p[L-k+1] through p[L] are set equal to 1 through k, respectively, and p[L+1] is set equal to -2.
When the Twiddle procedure is performed, three indexing numbers x, y, z are utilized to alter the states of the auxiliary array p and produce new successive combinations. A Boolean variable “finish” is employed as a return value of the Twiddle procedure to reflect if there are still new successive combination that can be produced. Initially, the “finish” is set equal to false, and the elements of the first combination C[0] through C[k-1] are set equal to G[L-k]
through G[L-1], respectively. Hence the Twiddle procedure is called upon, and is performed repeatedly to produce consecutive combinations by setting C[z] equal to G[x], until the
“finish” is toggled to be true. The pseudo code procedure of the Twiddle is presented in Figure 2.2.
procedure Twiddle(x, y, z, p, finish):
{
0
finish ←true; (All combinations have been produced. Then the Twiddle procedure should be terminated by toggling “finish”)
Return (finish = true);
finish ←false; (there are still more successive combinations to be produced.)
return (finish = false);
}
Figure 2.2. The pseudo code of the Twiddle procedure
Hence, the optimal threshold set can be obtained by recursively performing the Twiddle procedure. The potential threshold sets are successively produced by Twiddle .They are then evaluated until the maximum or minimum
ψ
( )T is achieved, and can be performed as the pseudo code procedure shown in Figure 2.3.G[0…L-1] stores the set of L gray levels
_ 0
Max ψ← ; (Min_ψ ← ∞; for using the Minimum Error criterion) _
Optiaml T← 0;
C[0]…[k-1] ← G[L-k] …G[L-1], respectively; (Initialize combination array C [0…k-1]) x ← 0, y ← 0, and z ← 0;
T C; (assign the combination to the current threshold set to be evaluated) Evaluate
ψ
( )T ; (ofψ
BCV( )T ,ψ
Ent( )T orψ
ME( )T )Figure 2.3. Improved search procedure of optimal
ψ
( )T using the combinatorial schemeConsequently, the amount of evaluations of potential threshold sets that obtain the optimal threshold set using the combinatorial scheme is 1 !k of those using the original exhaustive search scheme. For example, when performing in the case of quarter-level thresholding with three thresholds as previously mentioned, only 2763520 threshold sets are needed to be evaluated for determining the optimal one using the combinatorial scheme, which reduces 3! 6= times of evaluations compared with those using the exhaustive search scheme. Consequently the amount of evaluating values of the criterion function can be significantly reduced. Furthermore, this combinatorial scheme also parameterizes the number of desired thresholds. This means that by using this procedure the thresholding process can be adopted, without any changes, on a variable desired number of thresholds.
2.3.2 Fast Implementation of Criterion Functions for Multilevel Thresholding Methods
As described in the previous section, it can be seen that finding one evaluation value of a certain criterion function (ψBCV( )T , ( )ψEnt T or ψME( )T ) of one threshold set T requires the computation of some class statistics of prospective threshold partitions, i.e. w , n μn, σn, and H in Eqs. (2.13), (2.14), (2.17), and (2.15), respectively. These class statistics involve n summations which are performed on each position of gray values on the histogram to obtain a certain value of them. Most of calculations of these summations are repeatedly performed many times using their original computation forms in Eqs. (2.13), (2.14), (2.17), and (2.15), and most of these calculations are redundant and time consuming. It can be found that complete summations of the above-mentioned class statistics are not necessarily performed for obtaining each criterion function value of a given threshold set T. To further reduce the
computation timing for obtaining one evaluation value of a certain threshold set T, such redundant computations can be avoided by using pre-computed look-up tables of these summation terms of the class statistics involved in the thresholding criterion functions. By observing the computation equations of w , n μn, σn, and H , it can be seen that these class n statistics comprise of summations of the zeroth moment, the first moment, the a priori entropy, and the second moment, respectively, as viewed in the following expansion forms of their computation equations. In here, the summation terms of the zeroth moment, the first moment, the second moment, and the a priori entropy which are calculated on an interval ta - tb formed by two thresholds of T, i.e. the summation is performed from ta -position to tb-position on the histogram, are denoted as ( , )Z t t , ( , )a b F t t , ( , )a b S t t , and a b E t t , respectively. They are ( , )a b
1 function values. The re-calculation of the complete summations of them can be avoided in obtaining each criterion function value by using the following pre-computed tables for storing all potential values of ( , )Z t t , ( , )a b F t t , ( , )a b S t t , and ( , )a b E t t with respect to all a b possible intervals of ta - tb on the histogram, and hence the computation cost of these summations can be significantly saved. The pre-computed tables of Z, F, S, and E are depicted in Table 2.1 – Table 2.4. In here, the ta - tb intervals are bounded within
0≤ ≤ ≤ −ta tb L 1.
Table 2.1. The values of the zeroth moment ( , )Z t t of intervals ta b a - tb on the histogram tb
ta
0 1 … b … L-1
0 Z(0,0) Z(0,1) … Z(0,b) … Z(0,L-1)
1 0 Z(1,1) … Z(1,b) … Z(1,L-1)
… 0 0 … … … …
a 0 0 0 Z(a,b) … Z(a,L-1)
… 0 0 0 0 … …
L-1 0 0 0 0 0 Z(L-1,L-1)
Table 2.2. The values of the first moment F t t of intervals t( , )a b a - tb on the histogram tb
ta
0 1 … b … L-1
0 F(0,0) F(0,1) … F(0,b) … F(0,L-1)
1 0 F(1,1) … F(1,b) … F(1,L-1)
… 0 0 … … … …
a 0 0 0 F(a,b) … F(a,L-1)
… 0 0 0 0 … …
L-1 0 0 0 0 0 F(L-1,L-1)
Table 2.3. The values of the second moment ( , )S t t of intervals ta b a - tb on the histogram tb
ta
0 1 … b … L-1
0 S(0,0) S(0,1) … S(0,b) … S(0,L-1)
1 0 S(1,1) … S(1,b) … S(1,L-1)
… 0 0 … … … …
a 0 0 0 S(a,b) … S(a,L-1)
… 0 0 0 0 … …
L-1 0 0 0 0 0 S(L-1,L-1)
Table 2.4. The values of the a priori entropy ( , )E t t of intervals ta b a - tb on the histogram tb
ta
0 1 … b … L-1
0 E(0,0) E(0,1) … E(0,b) … E(0,L-1)
1 0 E(1,1) … E(1,b) … E(1,L-1)
… 0 0 … … … …
a 0 0 0 E(a,b) … E(a,L-1)
… 0 0 0 0 … …
L-1 0 0 0 0 0 E(L-1,L-1)
To rapidly construct the necessary tables for evaluating the criterion functions, we apply the recursively accumulative property of ( , )Z t t , ( , )a b F t t , ( , )a b S t t , and ( , )a b E t t for a b saving the amounts of “additions” for obtaining their summation terms during computing their values for consecutive (ta - tb) intervals. Their recursively accumulative computation forms can be obtained as,
1
Similarly, the computation forms of F, S, and E can be obtained as (0, )= (0, − +1)
Step 1. For the values of the first rows of Table 2.1 – Table 2.4, the recursively accumulative forms of in Eqs. (2.28), (2.30), (2.32), and (2.34) are utilized for obtaining the values of
(0, )b
Z t , (0, )F t , (0, )b S t , and (0, )b E t , respectively. b
Step 2. Then, for the rest rows of the tables, the values of Z t t , ( , )( , )a b F t t , ( , )a b S t t , and a b ( , )a b
E t t are obtained using Eqs. (2.29), (2.31), (2.33), and (2.35), respectively.
Hence, the class statistics wn, μn, σn, and Hn terms in the criterion functions, ψBCV( )T (applying Z and F), ( )ψEnt T (applying Z and E), and ψME( )T (applying Z, F, and S) can be rapidly computed by using index operations with the look-up tables of Z, F, S, and E, as depicted in Table 2.1 – Table 2.4 and Eqs. (2.24) – (2.27). By integrating the fast look-up table scheme with the combinatorial scheme based search procedure, the computation timing for obtaining the optimal threshold set T can be dramatically reduced.
2.4 The Proposed Automatic Multilevel Thresholding Method
When segmenting objects from a given image, different objects with homogeneous illuminations must be separated into different segmented images. For this purpose, the discriminant criterion, for measuring separability among the segmented images with different objects, is described in this section. By evaluating the separability criterion, the number of objects, into which the image should be segmented, can be automatically determined. Hence, an automatic multilevel thresholding method, based on this criterion, is proposed as follows.
The discriminant criterion functions mentioned in Section 2.2 can be considered a measure of separability, among all existing classes, decomposed from the original image I.
We introduce this concept as a criterion of automatic image segmentation, denoted by the
“separability factor” – SF in this study, which is defined as,
BC( )
T
v v
SF = T (2.36)
where v is the total variance of the gray-level values of the image I and serves as the T
normalization factor in this equation. The SF value measures the separability among all existing classes, and the SF value lies within the range 0≤SF ≤1. Maximizing the SF value is the objective, to optimize the segmentation result. This property is more obvious when using an alternative expression of this measure:
( ) ( )
This can be supported by the property of the total variance is equivalent to the sum of the between class-variance and the within-class variance. This property is obtained by,
1
In the above derivation, the dummy threshold t0 =0 is utilized for convenience in simplifying the expression of equation terms. Through observation of the terms comprising
WC( )
v T , if the pixels in each class are broadly spread, i.e. the contribution of the class variance σn2 is large, then the corresponding SF measure becomes small. Hence, when SF approaches 1.0, all classes of gray levels decomposed from the original image I are ideally and completely separated. This property also satisfies the concept of uniformity of the segmented regions, as presented by Levein and Nazif [68].
Accordingly, based on this efficient discriminant criterion on measuring the separability of the object regions of homogenous gray levels, an automatic multilevel thresholding method can be developed to recursively segment homogeneous objects from the image I, regardless of the number of objects and the complexity of the image. The multilevel thresholding process can be recursively performed on the gray levels of the image I until the
SF measure is large enough, i.e. SF approaches 1.0, to reflect that the appropriate discrepancy among the resultant classes of gray levels is achieved so that the homogeneous objects are completely segmented into separate thresholded images.
Through the aforementioned properties, this objective can be reached by minimizing the total within-class variance vWC( )T . This can be achieved by the scheme that selects the class with the maximal contribution (wnσn2) of the total within-class variance for performing the bi-level thresholding procedure to partition it into two more classes in each recursion. Thus, the SF measure will most rapidly achieve the maximal increment to satisfy sufficient separability among the resultant classes of gray levels. Furthermore, objects with homogeneous gray levels, will be well-separated.
Based on the above definitions, a new automatic multilevel thresholding method is developed. The details of the proposed method are presented below.
Step 1: In the beginning, compute the histogram of gray values of the image I, and all the gray values in I are assigned to one initial class C0. Let q denote the number of currently determined thresholds in the threshold set T, which classify the gray values into q+1 classes;
Initially, T comprise of no thresholds and q = 0.
Step 2: In current recursion, q thresholds have been determined, i.e. T = {t1, ..., tn, …, tq}, which partition the gray values of the image I into q+ 1 classes (C0, …, Cn, …, Cq). Compute the class-mean μn, the cumulative probability mass function wn, and the standard deviation
σn of each existing class Cn using Eqs. (2.13) – (2.15), respectively, where n denotes the index of the present classes and n = 0 ~ q.
Step 3: From all classes Cn, determine the class Cp with the maximal contribution (wnσn2) of the total within-class variance v , which is to be partitioned in the following step to achieve WC the maximal increment of SF .
where wp and μp are the class-probability and class-mean of Cp, respectively.
Then t is put into the threshold set T, and is applied to partition *S C into p C and p0 C , i.e. p1
0:
Cp
{
tp+1,tp+2,...,t , and *S}
Cp1:{
tS*+1,t*S+2,...,tp+1}
. Hence the gray values of the imageI are then divided into q+ 1 classes. Then re-label all the thresholds in T and let q = q+ 1.
Step 5: Computed the SF measure of all currently obtained classes using Eq. (2.36). If the following “Objective Condition” is satisfied,
≥ThSF
SF (2.44)
then go to Step 6; otherwise, go back to Step 2 to perform further partition process on the obtained classes.
Step 6: Deliver the obtained threshold set T, and then classify the pixels into q+ 1 separate classes C0, C1,…, Cq using to the resultant threshold values t1, t2, …, tq; and terminate the thresholding procedure.
As pointed out in the above-mentioned derivations in Eqs. (2.37)-(2.38), it can be seen that the intensity of the SF measure reflects whether if the obtained classes of gray levels (homogenous objects) have sufficient discrepancies, and are well-separated with each other.
Hence, at each recursion in the proposed automatic multilevel thresholding procedure, one optimal threshold is determined to partition the class which comprises of the most divergent distribution of gray levels, i.e. with the maximal contribution (wnσn2) of the vWC( )T , to achieve maximum increment of the SF measure. This way can accomplish the satisfactory thresholded results by means of the smallest number of thresholding levels. In plain words, the number of thresholding levels is determined by the number of the necessary times of recursions for partitioning the gray levels of the image into appropriate number of classes so that the resultant SF measure can satisfy the above-mentioned objective condition. Here the parameter THSF is the pre-defined threshold to determine whether the thresholded objects are sufficiently separated to satisfy the objective condition. This study employs ThSF =0.92, which is determined from the training using numerous images, such that all existing classes
are satisfactorily separated. Consequently, we obtain q+1 thresholded classes of gray levels,
0 ... ...
= C
U U U U
Cn CqI
where each class Cn represents one homogeneous object decomposed from the original image I.
Besides, the proposed multilevel thresholding method can also be modified to be performed on the demand for thresholding the gray levels of the image into a desired number of classes. To accomplish this demand, the only necessary change is to replace the objective condition in Eq. (2.44) in Step 5 of the algorithm by the following one:
q = K (2.45)
where K is the desired number of thresholds (K ≥1) to divide the gray levels of the image into K+1 classes. Hence, the thresholds can be determined one by one in each recursion until the desired number of thresholding levels is achieved, and each determined threshold is ensured to achieve the maximum separation on the obtained thresholded images.