A new Optimization-Based Image Segmentation method By Particle Swarm Optimization

This paper proposes a new multilevel thresholding method segmenting images based on particle swarm optimization (PSO). In the proposed method, the thresholding problem is treated as an optimization problem, and solved by using the principle of PSO. The algorithm of PSO is used to find the best values of thresholds that can give us an appropriate partition for a target image according to a fitness function. in this paper, a new quantitative evaluation function is proposed based on the information theory. The new evaluation function is used as an objective function for the algorithm of PSO in the proposed method. Because quantitative evaluation functions deal with segmented images as a set of regions, the target image is divided into a set of regions and not to a set of classes during the different stages of our method (where a region is a group of connected pixels having the same range of gray levels). The proposed method has been tested on different images, and the experimental results demonstrate its effectiveness. KeywordsThresholding-based segmentation; Particle swarm optimization; Quantitative image segmentation evaluation.


INTRODUCTION
Recently, swarm intelligence (SI) has been applied in numerous fields including optimization [1].One of SI methods performing well in solving optimization problems is particle swarm optimization (PSO).PSO is a stochastic search method that was developed in 1995 [1] based on the sociological behavior of bird flocking.The algorithm of PSO is easy to implement and has been successfully applied to solve a wide range of optimization problems in many fields such as image processing fields including image segmentation.Image segmentation is a low-level image processing task aiming at partitioning an image into homogeneous regions [2].The result of image segmentation is a set of regions that collectively cover the entire image, or a set of contours extracted from the image.All of the pixels in a region are similar with respect to some characteristic or computed property, such as color, intensity, or texture [3].Image segmentation methods have been classified into numerous categories of which region and thersholding based segmentations.
Thresholding based segmentation is definitely one of the most popular and effective approaches used in image segmentation [5].Over the years a wide range of thresholding techniques has been developed and considerable research continues nowadays.Marcello et al. in [6] has classified the thresholding techniques into two groups, local and global thresholding techniques, and the global ones again classified according to the information they exploit into histogram shapebased methods, clustering-based methods, entropy-based methods, object attribute-based methods and spatial methods.All the thresholding techniques involve a bi-level thresholding and a multilevel thresholding.The main objective of thresholding is to determine a threshold for bi-level thresholding or several thresholds for multilevel thresholding giving a suitable classification for pixels in an image.The simplest problem will be a bi-level thresholding one, where only one threshold, which separates the pixels into only two classes, is selected and the image able to be segmented by thresholding it at this value.This can facilitate to generate a binary image where all pixels having gray levels higher than the threshold are assigned to one class and pixels having gray levels lower than the threshold are assigned to another class.However the problem gets more and more complex when we try to achieve segmentation with greater detail by multilevel thresholding.Then the image segmentation problem becomes a multi-class classification problem where, based on the determined thresholds, pixels having gray levels within a specified range are grouped into one class.Determination of appropriate threshold values, that can segment the image efficiently, is the most important task involved in thresholding techniques.Over the years many method has been developed to solve this problem [5,7].The determination of appropriate thresholds is still the most difficult task in the thresholding techniques and it is still a challenge and a hot research topic for the researchers.Now, the PSO technique has been used to solve the problem of thresholding based segmentation.Zahara et al. in [8] combined a hybrid Nelder-Mead simplex search method and the PSO technique to solve the objective functions of Gaussian curve fitting and the Otsu's method.This combination is applied to image thresholding with multi-modal histograms.In [9] a multilevel threshold selection based on PSO was proposed.The PSO technique was used to find near-optimal thresholds by minimizing the cross entropy between the original image and its thresholded version.Maitra et al. [10] proposed a new thresholding algorithm for histogram-based image segmentation using a hybrid cooperative-comprehensive learning based on the PSO algorithm.In their algorithm, the entropy criterion has been used as a fitness function and near www.ijacsa.thesai.orgoptimal threshold values have been searched out through maximizing the normal entropy function.Zhiwei et al. in [11] presented a new method to select image threshold automatically based on PSO.They employed the PSO technique to deal with the criteria of Otsu's for Bi-level thresholding image segmentation and Wei et al. in [12] combined the PSO technique with Otsu's for multilevel thresholding image segmentation.Sathya et al. [13] presented a new histogram-based method for multilevel thresholding segmentation based on PSO.This method used Tsallis entropy as a fitness function.The PSO algorithm is used to find the near optimal threshold values that maximize the Tsallis objective function.Hongmei et al. in [14] proposed a multilevel thresholding method segmenting images based on the maximum entropy and an improved PSO.First, the parameters and the evolutionary process of the basic PSO have been improved, and then the combinations of near optimal thresholds are searched out by combining the improved PSO with maximum entropy.
The goal of this paper is to propose a new multilevel thresholding image segmentation method based on the idea of PSO.The PSO algorithm will try to find the near-optimal threshold values that can give us a near optimal segmentation for a target image according to a fitness function.A new quantitative evaluation function will be proposed and used as a fitness function for the algorithm of PSO.The new function manipulates with a segmented image as a set of regions not a set of classes.So, in the prooposed method, a given image is segmented into a set of regions, where a region is a group of connected pixels having a specific range of gray levels.This paper is organized as follows.Section 2 gives an overview of the PSO method.Section 3.A gives an overview of image segmentation evaluation and section 3.B proposed a new quantitative evaluation function.Section 4 presents the proposed method.In Section 5, the experimental results are presented, and, finally, the conclusions are stated in Section 6.

II. PARTICLE SWARM OPTIMIZATION
Particle swarm optimization (PSO) is a population-based optimization algorithm modeled after the simulation of social behavior of birds in a flock [6,15].The algorithm of PSO is initialized with a group of random particles and then searches for optima by updating generations.Each particle is flown through the search space having its position adjusted based on its distance from its own personal best position and the distance from the best particle of the swarm.The performance of each particle, i.e. how close the particle is from the global optimum, is measured using a fitness function which depends on the optimization problem.
Each particle, i, flies through an n-dimensional search space, R n , and maintains the following information:  x i , the current position of i th particle ( x -vector ),  p i , the personal best position of i th particle ( p -vector ), and  v i , the current velocity of i th particle i (v -vector ).
The personal best position associated with a particle, i, is the best position that the particle has visited so far.If f denotes the fitness function, then the personal best of i at a time step t is updated as: If the position of the global best particle is denoted by gbest , then : The velocity updates are calculated as a linear combination of position and velocity vectors.Thus, the velocity of particle i is updated using equation ( 3) and the position of particle i is updated using equation (4).
x i (t+1) = x i (t) + v i (t+1) In the formula, w is the inertia weight [16], c1 and c2 are the acceleration constants, r 1 and r 2 are random numbers in the range [0,1] and Vi must be in the range [-V max , V max ], where V max is the maximum velocity.

A. Related Work
In order to measure the performance of image segmentation methods without human interactions, we need an evaluation criterion.There are many image segmentation evaluation functions have been presented in the literature.Those functions have been divided into numerous types including quantitative evaluation measures [17,18,19].Borsotti et al. in [18] empirically proposed a quantitative evaluation function, Q , such as: Where I is a given image, Na is the number of pixels in I, n is the number of regions, R j denotes to j th region, L(R j ) is the number of pixels in j th region and e j is the color error of j th region.The first term of Equation 5 is a normalization factor and the second term penalizes results with too many regions.The last term in Q function penalizes simultaneously regions with big color error and small regions.
Zhang et al. [19] proposed an information theoretic approach for segmentation evaluation, E function, based on entropy theory.Given a segmented image, they define V j as the set of all possible values for the luminance in the region j and let L m (R j ) denote the number of pixels in the region R j that have luminance of m.The entropy for the j th region is defined such as: Next, they define the expected region entropy of the segmented image, ) (I H r , such as: As it is seen, ) (I H r is simply the expected entropy across all regions where each regions has weight (or probability) proportional to its area.The expected region entropy serves in a similar capacity to the term involving the squared color error used in Q function.The expected region entropy must be combined with another term or factor that penalizes segmentations having a large number of regions since there would otherwise be a strong bias to over-segment the image.Instead of penalizing the expected region entropy, they instead introduced the layout entropy, ) (I H l , such as: Finally, they define their evaluation function, E , where a lower entropy value means a better segmentation, as follows: For more study about the image segmentation evaluation methods, the reader is advised to refer to Zhang [20] and Zhang et al. [21].They have explained a lot of evaluation methods with detailed information.

B. A new Quantitative Evaluation Function
This section presents a new quantitative evaluation function, \ Q , based on the information theory.The new function is equivalent to Q function.The main problem of Q function is it was designed empirically.This makes Q function produces less balancing between the homogeneities and number of regions in a segmented image.Figure 1 illustrates this problem.Figures 1(a, b, c, d) show the segmentation results produced through multithresolding the image of House using k=1, k=10, k=15 and k=30 respectively (where k represents the number of thresholds -Note that the gray levels were divided into equal interval according to k). Figure 1(a) shows a segmented image with many merged regions.Figure 1(b) shows a segmented image with fewer details. Figure 1(c) shows a segmented image with more details reflecting more homogenous regions.Figure 1(d) shows the segmentation with many noises.Each figure has its evaluation values computed using \ Q , Q and E functions respectively.From those results, we can see that the differences between the evaluations of Q function are very large especially between the evaluations of Figure 1(b) and Figure 1(d).These differences don't reflect the visual judgment of the segmentation quality.This is due to the fact that Q function produces less balancing between the number and homogeneities of regions where it was designed empirically.The results shown in Figure 1 illustrate that the evaluations obtained by \ Q function, which will be described bellow, are the same as that obtained by Q , but the order and scores given by \ Q reflect the visual evaluation of segmentation quality.This is due to \ Q function produces more balancing between the number of regions and their homogeneities.To show that, see the difference between the evaluations of \ Q function shown in Figure 1(b) and Figure 1(d).The balancing of \ Q isn't the optimal but it is acceptable so far.The orders of segmented images produced by Q & \ Q functions are both acceptable but the order of \ Q function is the best.The order of the segmented images according to E function is k=1, k=10, k=15, k=30.This order gives Figure 1(a) the best segmentation.This is due to the fact that E function performs well in evaluating segmented images having explicit objects (real-world objects) [21] -Note: \ Q , Q and E functions are computed according to the gray levels and the values of \ Q and E are scaled to be in the range [0,10].
In describing the \ Q evaluation function, considered here, we will use the following notations.Let I be a given image and let Na be the number of pixels in the given image.We will use www.ijacsa.thesai.orgR j to denote j th region, and use L(R j ) to denote the area of j th region (as measured by the number of pixels).The homogeneity of the region R j is computed according to the color errors.Let e(px i,j ) be the color error of i th pixel in j th region, we define e(px i,j ) according to the mean of a region as: Where g(px i,j ) is the gray level of px i,j and mean j is the mean of j th region computed using the gray levels of pixels being in this region.So, we will define a new group, j Re , containing the integers of color errors of the pixels included in j th region and it is defined such as: Let Re is split into two groups ' Re j & " Re j , where ' Re j contains the integers of color errors of the near similar pixels (homogeneous) and " Re j contains the integers of the rest color errors, we define ' Re j such as: Where d is a constant value.Empirically, we found that the proper value of d falls in the range [0, 0.3] and the value d=0.15 gives us good evaluation results.Also, we found that the value of d can be detected mathematically according to the homogeneity of a given image -we will illustrate this principle later.Thus, d divides the pixels of regions in a segmented image into near similar and non-similar pixels according to the color errors.Consequently, we have ' Q function is a lower entropy value means a better segmentation result and vise versa, and it is computed such as: Where, w 1 & w 2 are weighting parameters.Empirically, we found that \ Q function gives us a good evaluation if the value of w 1 is greater than the value of w 2 .Throughout this work we will set w 1 = 0.55 and w 2 = 0.45.The users can tailor these parameters according to their objectives.The first term, \ l H , represents the layout entropy, and it is computed such as: (16) From the information coding theory, the above function indicates the number of bits needed to specify a region id in a segmented image according to the number of near similar pixels in different regions.The second term, e H , represents the entropy of color errors in the overall segmented image and it is computed such as: Where, min e and max e represent the minimum and maximum color errors in " e I respectively.From the information coding theory, e H indicates the number of bits needed to encode the color errors of non-similar pixels.The entropy of color errors serves in a similar way to the term involving the squared color error used in Q function.
The two entropies of \ l H & e H components are computed according to the number of pixels in the overall image, Na.This make \ l H and e H are complements to each other making \ Q function gives more balancing between the number of regions and their homogeneities.The value of \ l H is increased if the number of regions in a segmented image increases and vise versa and the value of e H is increased if the homogeneities of regions decrease and vise versa.In the case of a segmented image with one pixel per region, the first term is maximized to a very large value and the second term is minimized to zero.This means that \ Q function gives a large value in the case of non-segmented image.

 d detection
The value of d splits the pixels in a region into near-similar (homogeneous) and non-similar (non-homogeneous) so this value can be extracted mathematically according to the homogeneity of the overall image, ) (I H . Entropy theory is one of the ways used to measure the homogeneity of images.Let g max is the maximum gray level in a given image, I, then the homogeneity of I is computed depending on the image entropy as follows: In the case of images having 256 gray levels, the number of bits needed to represent a pixel is 8 bits per pixel.So if the value of ) (I H is less than 4 bits per pixels, this means that the pixels in the given image are near-similar.In this case, the value of d is equaled to zero.In other cases the value of d is equaled to ( ) (I H -4). Empirically, we found that the proper value of d falls in the range [0, 0.3].So the value of d after it has been computed is scaled to be in that range.www.ijacsa.thesai.org

IV. A NEW IMAGE SEGMENTATION METHOD BASED ON PSO
This section develops a new multilevel thresholding method segmenting images using the principle of PSO.The new method will be named PSOTH.The algorithm of PSO, in PSOTH, tries to find near-optimal values of thresholds that can give us a near-optimal segmentation.Consequently, the PSO algorithm initializes a random swarm of m particles, where each one has its k thresholds, and flies them on a search space to look after the target partition according to a fitness function.The PSO algorithm uses \ Q function as a fitness function and the gray levels {g min , ..., g max } as a search space, where g min and g max are the minimum and maximum gray levels in a given image respectively.

A. PSO Representation
One of the key issues in designing a successful PSO algorithm is the representation step, i.e. finding a suitable mapping between a problem and PSO particles.Figure 2 shows the PSO representation that is used in PSOTH.As it is shown, PSO has the following information: In PSO of PSOTH method, a single particle represents k thresholds.That is, each vector x i is constructed such as x i = ( t i,1 , . . ., t i,j , . . ., t i,k ) where t i,j refers to the j th threshold value of the i th particle.Therefore, in the PSOTH method, after applying the thresholding to each particle, a swarm represents a number of segmented images.

B. Fitness Function
In PSOTH, the algorithm of PSO uses the \ Q evaluation function presented above as a fitness function.The idea behind using \ Q function can be formulated as: the smaller the value of \ Q , the better is the segmentation result.Consequently, The PSO algorithm, in the PSOTH method, looks after the threshold values that minimize the value of \ Q .It should be noted that \ Q function manipulates with a segmented image as a set of regions.So, in PSOTH, a given image is thresholded into a set of regions (where a region is a group of connected pixels located in the same rang of gray levels).Let there be L gray levels in the given image and these gray levels are in the range M={g min , …, g max }, So the PSO algorithm tries to obtain a near optimal k-dimensional vector {t 1 , t 2 , ..., t k }  M that thresholds the given image into regions which can minimize the value of \ Q function shown in Equation 15.

C. PSOTH Algorithm
Firstly, the algorithm of PSOTH starts by applying (3x3) low pass filter to remove a noise from a target image, after that, every particle in the swarm is initialized randomly to contain k thresholds.Secondly, the target image is thresholed and divided into regions using the threshold values of each particle separately, and the fitness function, which is the \ Q evaluation function, is calculated for each particle.Once the fitness values have been found the global best solution, gbest, is computed and the updates of PSO velocities and vectors are then done.This procedure is repeated until the number of iterations has been satisfied.The algorithm of PSOTH is summarized in Algorithm 1.The algorithm initializes the vectors of each particle randomly.The threshold values of each particle are initialized in the range [g min , g max ].The thresholds are sorted in our method optionally.The sorting step is added to increase the symmetric between the thresholds in different particles.
To threshold and group a target image into regions, the principle of normal region based segmentation is applied as follows.The image is scanned from left to right and from top to bottom and the current pixel, px, is used as a seed point growing with its neighboring pixels according to a connectivity and a similarity condition.Here, the 4-connectivty is used and the similarity condition is formulated using the range of gray levels as follows.If g(px) falls in a rang [t i,j , t i,j+1 ] then a neighbored pixel N(px) append to the region of px, if g(N(px)) also falls in the rang [t i,j , t i,j+1 ].Where, [t i,j , t i,j+1 ] is the rang of gray levels specified by two threshold values t i,j and t i,j+1 of i th particle, g(px) is the gray level of px, and g(N(px)) refers to the gray level of a pixel neighboring to the region px, in 4connectivity.The algorithm of thresholding and grouping the target image into regions is summarized in Algorithm 2. The fitness of every particle is evaluated by using the quantitative evaluation function, \ Q , shown in Equation 15.
\ Q function uses the information stored in the list of regions to Swarm Size ( . .
-For each pixel, px, in the target image.
-If Pixel, px, is ungrouped Then (i) Grow px with its neighboring pixels according to the threshold values of particle i. (ii) -Add the new region to the list of regions.
-End if -End For get the fitness of a particle.The gbest takes the position of the particle having the best fitness value.Once the gbest has been found, the threshold values of each particle are updated using Equation ( 3) and ( 4) in 2-dimention space (i, j), where i represents ith particle and j represents jth threshold.
Step 3 of PSOTH algorithm is repeated until the stopping criterion has been satisfied.The segmented image of the global best solution, gbest, after finishing the final iteration, is chosen as a best solution.For the best segmentation, merging small regions must be done.In the merging step, the final list of regions is scanned to merge regions having pixels less than a predefined number (e.g. 10 pixels), with their neighboring regions that satisfy a similarity condition.The similarity condition that is used in merging processes is the smallest difference between means.In the algorithm of PSOTH, the number of final regions is determined after merging small regions step.

V. EXPERIMENTAL RESULTS
In order to prove the efficiency and accuracy of PSOTH, it has been applied to many different images.In this section we will present the results produced through applying the PSOTH method to the three images shown in Figure 3.These images have been selected to test the algorithm of PSOTH, and to compare it with other algorithms.All the test images are 256x256 pixels in size.This section is organized as follows.Section A presents the examination of \ Q function.Section B shows the tracing steps of PSOTH algorithm and Section C shows the performance measuring of PSOTH method.A.

Q Function Examination
\ Q function was examined through applying it to evaluate the segmentation results produced through segmenting the test images using the principle of normal region-based segmentation.Here, the normal region based segmentation segments the test images through multithresholding them into a group of regions using k thresholds, where k thresholds divide the gray levels into a number of gray level ranges with equal interval.Consequently, a test image scanned from left to right and left to bottom, and the connected pixels that fall in the same range of gray level grouped into a single region.This action is repeated for n=40 iterations.In each iteration, a different segmentation is produced, where k is set to the number of iteration so k = {1, 2, …, n}.
Figure 4 shows the best segmentations that were chosen by \ Q function.To show the efficiency of \ Q function for choosing the best segmentation, the results produced by \ Q will be compared with the results chosen by Q function.Figure 5 shows the best segmentations that were produced by Q function.With human visual perception, it can be seen that the results produced by \ Q function are better than the results produced by Q function.

B. Tracing Steps of PSOTH Algorithm
For tracing purpose, the algorithm of PSOTH is used to get a near optimal segmentation for Cameraman image.Firstly, the algorithm starts by applying (3x3) low pass filter, Figure 6(a) shows the filtered image, and, then, the particles are randomly initialized.The x-vector and v-vector values are initialized in the ranges [g min , g max ] and [V max , -V max ] respectively, where g min = 13, g max =233 for Cameraman image.
For the PSO algorithm, in this experiment, 20 particles are trained for 50 iterations.The PSO parameters are initially set as follows.V max = 3, w = 1 decreased over time to 0.4 and C 1 = C 2 = 1.49.The particles are trained with k=10.Empirically, we found that the proper value of k falls in the range [7,12], where if we increase the value of k, more details will be produced and if we decrease it, more flat regions will be produced.
The algorithm of PSO starts by segmenting the target image using the gray level ranges of each particle and computing the fitness of each one using the \ Q evaluation function.The flow chart shown in Figure 7 illustrates the values of \ Q related to each particle in the first iteration.In the flow chart, the best particle, 2 nd particle, is white in color and the worst particle, 11 th particle, is black in color.Figure 6(b) and Figure 6(c) show the best and worst segmentation in the first iteration, i.e. illustrating that the segmentation of 2 nd particle is clearly better than the segmentation of 11 th particle.After that, the particle having the best fitness value is taken as gbest.Finally the velocities and positions of each particle are updated respectively according to the updating functions.These steps are repeated until the number of iterations has been satisfied.Figure 8 illustrates for the target image how the fitness of PSO improves over time.The fitness value, as measured using \ Q function, improved from the initial 0.2720554 to 0.1326954.
After that, the segmented image of gbest is chosen as a near optimal segmentation (the best solution), Figure 6(d) shows the best solution choosing by PSO.For the best solution small regions having pixels less than 10 pixels are merged with their neighboring regions.Figure 6(e) shows the best solution after merging small regions.Clearly, we can see that the segmentation in Figure 6(e) is better than the segmentation shown in Figure 6(c).This means that the segmentation of House image was improved over item according to the values produced by \ Q function.Finally, Figure 6(f) shows the regions of the best solution after filling with their means.Figures 9(a, b, c) illustrate the segmented images produced through applying the PSOTH method to the test images, while Figures 9(d, e, f) and Figures 9(g, h, i) illustrate the segmented images obtained from applying the k-mean algorithm and the region based segmentation to the test images respectively.With human visual perception, it can be seen that the results shown in the figures clearly illustrate that the segmented images obtained by the PSOTH method are better than the segmented images obtained by the region based segmentation and the kmeans algorithm.This means that the PSO algorithm is a good optimization method can be used to segment images if it is complicated with a good fitness function such as \ Q function. Evaluation Measuring Table 1 summarizes the values of \ Q function produced by applying the normal region based segmentation, k-means algorithm and PSOTH method to the test images respectively (the values in Table 1 are the evaluations of segmented images in Figure 9).The results show that, in all cases, the k-means algorithm performed better than the region based segmentation method, and the PSOTH method performed better than both the region based method and k-means algorithm.Note that the values of \ Q function were scaled to be in the range [0, 10].

VI. CONCLUSION
In this work, PSO has been used to produce a new optimization-based image segmentation method, PSOTH.In the PSOTH method, the algorithm of PSO tries to find a near optimal segmentation for a given image using a fitness function.PSO is a flexible optimization method, where many objective functions can be used.For this reason, a new quantitative evaluation function for segmented images has been proposed in this paper.So in the PSOTH method, the new evaluation function has been used as a fitness function for the algorithm of PSO.The experimental results have illustrated that the efficiencies of the PSOTH method and the new evaluation function.

Q
n denotes to the number of regions in a segmented image, then: function as E function has two components, \ l H & e H , where \ l H represents the layout entropy and e H represents the entropy of color errors.The working principle of \

Figure 2 :
Figure 2: PSO Representation in the PSOTH Method

Algorithm 1: PSOTH Algorithm 1 - 4 - 5 -
Do (3 x 3) Low pass filter.2-Initialize randomly each particle to contain k threshold values.3-For each particle, i, Sort the threshold values.// Optional 3-Repeat the following Until the number of iterations has been satisfied (a) For each particle i : (i) Threshold the target image into regions using the threshold values of particle i. (ii) Compute the fitness of particle i by using \ Q function.(b) Find the global best solution (gbest).(c) For each particle i, Update the threshold values.Fix the gbest as a best solution.Merge small regions of the best solution.

Figure 7 :
Figure 7: Fitness of Particles in First Iteration.Figure8: PSOTH Performance on House Image

Figure 8 :
Figure 7: Fitness of Particles in First Iteration.Figure8: PSOTH Performance on House Image

Figure 9 :
Figure 9: The best Segmentation of Test Images Produced by (a, b, c).PSOTH method.(d, e, f).Normal region based algorithm.(g, h, i) k-means algorithm.

TABLE I .
COMPARISON BETWEEN REGION BASED, K-MEANS AND PSOTH