Multilevel Image Segmentation Based on an Improved Firefly Algorithm

Multilevel image segmentation is time-consuming and involves large computation. The firefly algorithm has been applied to enhancing the efficiency of multilevel image segmentation. However, in some cases, firefly algorithm is easily trapped into local optima. In this paper, an improved firefly algorithm (IFA) is proposed to search multilevel thresholds. In IFA, in order to help fireflies escape from local optima and accelerate the convergence, two strategies (i.e., diversity enhancing strategy with Cauchy mutation and neighborhood strategy) are proposed and adaptively chosen according to different stagnation stations.The proposed IFA is compared with three benchmark optimal algorithms, that is, Darwinian particle swarm optimization, hybrid differential evolution optimization, and firefly algorithm. The experimental results show that the proposed method can efficiently segment multilevel images and obtain better performance than the other three methods.


Introduction
Image segmentation is an indispensable part of computer vision, which directly influences the quality of feature extraction and classification.In the past few decades, many image segmentation methods have been proposed and applied in different fields [1][2][3][4].Thresholding is one of the widely used techniques in image segmentation.The principle of thresholding is finding an adequate threshold to segment object from background through certain criteria, such as Otsu thresholding [5], maximum entropy thresholding [6], minimum error thresholding [7], and 2D maximum entropy thresholding [8].In the case of segmenting several objects from background, thresholding technique needs to be extended to multilevel thresholding.However, large amount of calculation and long computation time occur when exhaustively searching multilevel thresholds.
To overcome the exhaustive problems, several metaheuristics optimal algorithms were applied to multilevel thresholding.Hammouche et al. [9] presented optimal thresholding using genetic algorithms.Ghamisi et al. [10] developed particle swarm optimization (PSO), Darwinian particle swarm optimization (DPSO), and fractional-order Darwinian particle swarm optimization for determining thresholds.Liang et al. [11] designed an ant colony optimization segmentation algorithm for solving multilevel Otsu problem.Sathya and Kayalvizhi [12] applied bacterial foraging into finding thresholds for maximizing Kapur's and Otsu's objective functions.Cuevas et al. [13] used differential evolution optimization (DE) to find multilevel thresholds.Osuna-Enciso et al. [14] presented a comparison of three optimization algorithms for selecting multilevel thresholds.Nevertheless, with the number of thresholds increasing, these metaheuristics optimal algorithms cannot find the balance of global search and local search, which would lead to inaccurate results and a slow convergence rate [15,16].
Thus, this paper presents an improved firefly algorithm (IFA) to search multilevel thresholds.In IFA, a diversity 2 Mathematical Problems in Engineering enhancing strategy with Cauchy mutation is proposed to increase the global search ability.Moreover, a neighborhood strategy is present for local search.The main idea of IFA is adaptively choosing one strategy to help fireflies find the optima according to different stagnation stations.Furthermore, the multilevel Otsu thresholding function is considered as the objective function, and the IFA is applied to searching multilevel thresholds.
The rest of this paper is organized as follows.In Section 2, multilevel image segmentation problem is formulated.Section 3 proposes a novel improved firefly algorithm and describes the application of IFA to multilevel thresholding problem.In Section 4, experiments and comparisons are carried out and the corresponding results are discussed.Section 5 gives a conclusion.

Problem Formulation of Multilevel Image Segmentation
With the purpose of separating multiple objects from background, multilevel image segmentation is formulated.Otsu thresholding is a classical and efficient algorithm for image segmentation [30][31][32].In consequence, Otsu thresholding is selected to solve image segmentation problem in this paper.
The core idea of the Otsu thresholding algorithm is searching a threshold to maximize the between-class variance.Suppose that there are  pixels with  gray levels in an image; the probability distribution of the gray level  ( = 0, . . .,  − 1) can be defined by   = ℎ  /, where ∑ −1 =0   = 1 and ℎ  represents the number of pixels with the specific gray level .Hence, the mean value of the total image is   = ∑ −1 =0   .Let a threshold  partition the image into two classes: class  1 including the pixels  ≤  and class  2 including the pixels  > .Define the probability of  1 and  2 to be  1 = ∑  =0   and  2 = ∑ −1 =+1   .Then, mean values of the two classes can be calculated as In this situation, the maximum variance between two classes can be defined as To solve the multilevel Otsu thresholding problem, an image needs to be classified into  classes ( 1 ,  2 , . . .,   ) with the set of thresholds ( 1 ,  2 , . . .,  −1 ).In a similar way, the maximum between-class variance with multilevel thresholds can be defined as with In other words, the problem of multilevel Otsu thresholding can be understood as searching a set of thresholds ( t1 , t2 , . . ., t−1 ) that can maximize the between-class variance.The optimization problem is defined as Obviously, multilevel Otsu thresholding algorithm is timeconsuming and involves large computation.To solve this problem, an improved firefly algorithm is applied to searching multilevel thresholds.

Multilevel Image Segmentation Based on IFA
3.1.Firefly Algorithm.Firefly algorithm is a new natureinspired approach for optimization, which mimics the bioluminescent behavior of fireflies [17].In firefly algorithm, there are three idealized rules: (1) all fireflies are unisex so that one firefly is attracted to other fireflies regardless of their sex; (2) attractiveness is proportional to their brightness; thus, for any two flashing fireflies, the less bright one moves towards the brighter one.If there is no brighter one than a particular firefly, it will move randomly; (3) the brightness of a firefly is affected or determined by the landscape of the objective function.
The movement of firefly  attracted to another more attractive firefly  is determined by where  ()  and  ()  represent the solution of the th iteration for firefly  and firefly ; (  ) represents the attraction of firefly  to firefly , where   is the distance of firefly  and firefly ,  0 is the attractiveness at   = 0, and  is the light absorption coefficient.The third term is disturbing term with  being the randomization parameter.rand is a random number generator uniformly distributed in [0, 1].
The main steps of firefly algorithm can be concluded as follows: (1) calculate the fitness values of fireflies according to the objective function; (2) the fireflies with lower fitness values move to ones with higher fitness values according to (6); (3) sort the fireflies and find the one with highest fitness value; (4) repeat iterations until the maximum iteration number is reached.

Improved Firefly Algorithm.
In the previous section, the original firefly algorithm has been introduced.Many researchers have proven the efficiency of firefly algorithm in solving optimization problems.Nevertheless, in some cases, the algorithm is easy to fall into local optima which may lead to inappropriate results and slow convergence.The reason causing the above phenomena is the imbalance of global search and local search.Hence, to solve the problem, two strategies (i.e., diversity enhancing strategy with Cauchy mutation and neighborhood searching strategy) are proposed in Sections 3.2.1 and 3.2.2.A novel improved firefly algorithm with the two strategies is put forward in Section 3.2.3.

Diversity Enhancing Strategy with Cauchy Mutation.
In order to increase the global search ability and prevent the loss of diversities, a diversity enhancing strategy with Cauchy mutation is proposed.
The probability density function of one-dimensional Cauchy distribution can be described by where  > 0 is a scale parameter [33].The distribution function is In this paper, diversity enhancing mechanism with Cauchy mutation is defined by where Cauchy(0, ) denotes a random number with Cauchy mutation and  is the scale parameter.Moreover, this strategy is not generated for each individual, but for a certain number of random chosen individuals.Figure 1 illustrates the diversity enhancing process with Cauchy mutation.The main steps of diversity enhancing strategy with Cauchy mutation are as follows: (1) randomly select the  1 number of fireflies; (2) update the fireflies with (10).It is worth noting that the firefly with current best fitness value is not to be chosen to update with Cauchy mutation.The purpose is to avoid the retrogression phenomenon in the optimum search progress.
where  denotes the adjacent distance and  is a scale parameter.Therefore, a new firefly    generated by neighborhood strategy is where rand is a random value selected from A clear explanation of the process is presented in Figure 2. In order to punish the worst fireflies and accelerate the convergence, the neighborhood strategy is not generated for each firefly, but for a certain number of ranked bottom fireflies.Therefore, the neighborhood strategy can be described briefly as follows: choose the  2 number of ranked bottom fireflies and update the fireflies according to (12).

Improved Firefly Algorithm.
The purpose of the proposed improved firefly algorithm is to help fireflies escape from local optima and accelerate the convergence.The main steps of IFA are described in Algorithm 1, where  is the iteration number, Maxiter is the maximum number of iterations,  best ( − 1) indicates the best fitness value of last iteration, and  best () records the current best fitness value.In Algorithm 1, steps (8) to (22) are the essence of the proposed algorithm.When the best fitness value does not improve or shows very small improvement, it is considered that the fireflies may get stuck in local optima.
In case of  best () =  best ( − 1), count the continuously occurring number   .According to the value of   , the stagnated situation is divided into four stages with four thresholds (thr 1 , thr 2 , thr 3 , and thr 4 ).In the first stagnated stage (thr 1 <   < thr 2 ), the proposed diversity enhancing strategy with Cauchy mutation is applied to increasing the diversity and enhancing the global search ability.In the second stagnated stage (thr 2 ≤   < thr 3 ), two situations are likely to occur: fireflies get stuck in a local optimum that may be nearby or far from the real optimum.As a result, the Cauchy mutation strategy and the neighborhood strategy are selected randomly.If there is no improvement after the second stage (thr 3 ≤   < thr 4 ), it is considered that the local optimum is infinitely close to the real optimum.Therefore, the neighborhood strategy is applied to enhancing the local search ability.When the continuously occurring number   achieves the threshold thr 4 , it is considered that the global optimum has been found after the earlier three stagnated situations and the iteration would be terminated.In addition, if the difference between  best () and  best (−1) is less than the threshold thr 5 , the situation is similar to the second stagnated stage.Hence, the approach of this situation is the same as that of the second stage.Parameter  in original firefly algorithm is a randomization parameter.Normally, a large  encourages global search while a small  facilitates the local search [24].As a result, many researchers set parameter  as a monotonically decreasing function with iteration.However, in the situation of trapping in a local optimum, the small  may not play a role.Therefore, parameter  in IFA is defined as ) ) From (13), in the case of  best () =  best ( − 1) and ( best () −  best ( − 1)) < thr 5 , the value of  reduces the speed of recession, so as to increase the disturbance ability.

Multilevel Image Segmentation Based on IFA.
In this section, multilevel image segmentation based on IFA is proposed.As mentioned above, the multilevel image segmentation can be considered as an optimum problem.Therefore, the main steps of the proposed method are as follows: (1) Input image.
(2) Initialize the parameters of IFA and make the maximum between-class variance  2 mul be the objective function of IFA.

Experiment Results and Comparisons
The experiments were implemented in MATLAB on a computer with Intel Core 2.26 GHz and 2 GB memory.Four standard test images ("Lena," "Cameraman," "Baboon," and "Peppers") are used for conducting experiments.Three QFN defect images (QFN images with scratch defect, scrape defect, and void defect) captured from QFN test handler were also used for testing.In order to verify the efficiency of the proposed method, Darwinian particle swarm optimization (DPSO) [10], hybrid differential evolution optimization (HDE) [36], and FA are carried out for comparison.

Image Segmentation Results of the Proposed Method.
According to Section 3 and the characteristics of image segmentation, the parameters of IFA were set as shown in Table 1.
Image segmentation results of the proposed method are shown in Figure 3: from top to bottom, they are "Lena," "Cameraman," "Baboon," "Peppers," "QFN image with scratch defect (hereinafter referred to as QFN1)," "QFN image with scrape defect (hereinafter referred to as QFN2)," and "QFN image with void defect (hereinafter referred to as QFN3)"; the first column shows the original images and the second to the fifth columns show, respectively, the corresponding images of segmentation results with two, three, four, and five thresholds obtained by the proposed method.

Results
Comparisons.The efficiency of the proposed method was evaluated by comparing the results with DPSO, HDE, and FA.DPSO [10] is the variation of particle swarm optimization.In DPSO, there are many swarms existing in each iteration.Moreover, in order to escape the local optima, the swarms are judged according to the selection mechanism.HDE [36] is the variation of differential evolution optimization.In order to improve convergence, the local search routine and adaptive crossover operator are applied in HDE.The four methods were compared in four aspects: accuracy, computational time, convergence, and stability.Parameters of DPSO, HDE, and FA were set in Table 2.For fair comparison, in the iteration, if global best solution was not improved and the repeat time reached the threshold thr 4 in IFA, DPSO, HDE, and FA would be terminated and output the results.Owing to the randomness of the four algorithms, each algorithm was executed 50 times to verify the performance.

Comparison of Accuracy.
Due to the randomness, the best experimental results obtained by the four algorithms are listed in Tables 3 and 4, where  represents the number of thresholds.Tables 3 and 4, respectively, show the thresholds and the corresponding fitness values.The best values of the four algorithms are emphasized in boldface.It can be found that the four algorithms obtain the best fitness values when  = 2, 3.However, with the number of thresholds increasing, the fitness values of IFA are slightly higher than those of the other three methods.

Comparison of Computational Time.
The minimum computational time spent on finding the best fitness values in Table 4 is listed in Table 5.The results of computational time reveal that, in a few cases, the DPSO method and HDE method cost less time.However, the IFA method spends the minimum time in most situations.

Comparison of Convergence.
In order to demonstrate the convergence performance of the proposed method, convergence curves are drawn in this section.The convergence curves for Peppers ( = 2), Baboon ( = 3), QFN3 ( = 4), and Lena ( = 5) are, respectively, shown in Figures 4(a), 4(b), 4(c), and 4(d).It is easy to find that the IFA based method has a faster convergence speed than the other methods.The DPSO method and the HDE method rank second and third.The FA method has the slowest convergence speed.

Comparison of Stability.
As mentioned before, all the optimization algorithms are of the randomness characteristic.Tables 3, 4, and 5 show the best results of the four algorithms.However, it is necessary to calculate the mean value and standard deviation so as to show the quality of stability.The mean value  and standard deviation std are, respectively, defined as where   is the number of times the algorithm ran and  is the best objective value obtained each time.The mean values and standard deviations of four algorithms are shown in Table 6.As can be seen, the four methods almost get the best stability when the number of thresholds is 2. With the number of thresholds increasing, the IFA algorithm owns the best stability quality.4.3.Discussion.In the previous sections, the optimum results of the proposed method and the comparisons of four methods are given.In terms of accuracy, the IFA based thresholding method obtains slightly higher fitness values than the other three methods.On the part of computational time and convergence, IFA, DPSO, and HDE perform better than FA.
In the aspect of stability, IFA has the best performance.The superior performance by IFA is due to the diversity enhancing strategy with Cauchy mutation and neighborhood strategy.Two strategies are applied according to different level of stagnations.With the advance of the two strategies, the IFA based method can keep the balance of exploration and exploitation in the search space.The experimental results indicate that the proposed method performs better than the other three methods.

Conclusion
This paper presents a multilevel image thresholding approach based on the proposed improved firefly algorithm.There are two contributions in this paper.Firstly, an improved firefly algorithm is proposed.In IFA, diversity enhancing strategy  with Cauchy mutation and neighborhood strategy are conducted to increase the global search ability and accelerate the convergence.Secondly, IFA is applied to searching multilevel global best thresholds.Seven images are used to verify the proposed method.The experimental results reveal that the IFA based method can efficiently that the IFA based method can efficiently search the multilevel thresholds and segment images into background and objects.Moreover, the proposed method shows better performance than the DPSO method, HDE method, and FA method.
Suppose best is the best solution of each iteration; best  denotes the th value in best.The neighborhood of best is defined as [34,35]eighborhood Strategy.The diversity enhancing strategy with Cauchy mutation increases the global search ability.Nevertheless, an excellent optimization algorithm should keep the balance of exploration and exploitation.Hence, a neighborhood strategy for local search is proposed in this section.The concept of neighborhood in this paper is not the neighborhood individuals in the solution space[34,35], but the neighborhood values of the firefly with best solution.

Table 3 :
Threshold values obtained by the four methods.

Table 4 :
Objective function values obtained by the four methods.

Table 5 :
Computational time of the four methods.

Table 6 :
Stability of the four methods.