### Multilevel recursive discrete PSO for image segmentation

In discrete particle swarm optimization (DPSO) [8], every particle stipulates the probable solution having *k* elements. Accuracy of the solution is evaluated by using fitness function. Every element is treated as a location in *r*-dimensional space, and every component of an element is constrained to ‘0’ and ‘1’, where ‘0’ signifies ‘added’ and ‘1’ signifies ‘not added’. Every component can diverge from *0* to *1* and from *1* to *0*. Furthermore, every component of an element will have *r*-dimensional speed ranging among [− *V*max, *V*max]. To update speed and location of an element use:

$$V_{m}^{t + 1} = V_{n}^{t} + k_{1} c_{1} \left( {p_{\text{best}} \,_{m}^{t} - X_{m}^{t} } \right) + k_{2} c_{2} \left( {n_{\text{best}} \,_{m}^{t} - X_{m}^{t} } \right)$$

(1)

$$X_{m}^{t} \left( n \right) = \left\{ {\begin{array}{*{20}l} {1,} \hfill & {{\text{if}}\;{\text{Sig}}\;V_{m}^{t + 1} \left( n \right) > r_{mn} } \hfill \\ {0,} \hfill & {{\text{if}}\;{\text{Sig}}\;V_{m}^{t + 1} \left( n \right) \le r_{mn} } \hfill \\ \end{array} } \right.$$

(2)

Sigmoid function is given by the relation

$${\text{Sig}}\;(V_{m}^{t + 1} \left( n \right)) = \frac{1}{{1 + e^{{ - \left( {V_{m}^{t + 1} \left( n \right)} \right)}} }}$$

(3)

where \(X_{m}^{t} \left( n \right)\) is *n*th factor of *m*th element in the *t*th iteration of the method. \(V_{m}^{t} \left( n \right)\) is *n*th factor of the velocity vector of *m*th element in *t*th iteration of the method. *k*_{1} and *k*_{2} are positive enhanced coefficients which regulates the impact of *p*_{best} and *n*_{best} on the hunt procedure. *c*_{1} and \(c_{2} \in \left[ {0, 1} \right]\) are arbitrary values experimented from a even distribution, and \(r_{mn} \in \left[ {0, 1} \right]\) is arbitrary numeral.

For segmenting an image by swarm intelligence-based technique, graphical structure of an image is generated, in which pixels of an image are the vertices of the graph and weight of an edge in the graph is the subtraction of pixel intensities of the connecting vertices. On this weighted graph, multilevel recursive discrete particle swarm optimization algorithm (MRDPSO) is applied which operates in three stages. In the initial stage, population on the smallest graph is being initialized by MRDPSO. Refinement of the graph is the second step in which particles are projected back successively to the finer graphs in the next level. Lastly, bisected graph is partitioned into *k*-parts.

Initially in the coarsening phase, operative matching-based coarsening structure is applied. In this step, CSHEM [9] technique is applied to initially generated weighted graph and then SHEM on the reduced graphs. Graphs having a smaller number of vertices core number is not required, since the matching generated by core number and that of SHEM is same. Hence, directly SHEM is implemented on the original graph in case of the graphs with less than fifteen vertices. Core numbers are determined by arranging the vertices in the increasing degrees after that for every vertex *u* list out all the nodes connected to it and having degrees larger than *u*. Decrease the degree of all these connected nodes by ‘1’. Continue the procedure till every vertex in the graph gets core number. Order to visit for the matching by sorting nodes of the graph in increasing order is being decided by SHEM.

Apply GGGP [10] for the preliminary partitioning of the coarsened graph to create \(G_{m} = \left( {V_{m} ,E_{m} } \right)\), which divides the nodes into three groups, say *P*, *Q*, and *R*. *P* is generated by arbitrarily choosing node from the graph, and groups *Q* & *R* are then generated. For generation of group *P*, choose closest node (assume *v*) from the group *Q* to the node in group *P* and then add it in group *P* that is the node with highest gain in *Q*. Subsequently, every node in group *R* that is connected to *v* is added into the group *Q and* then determined its gain. Likewise, redetermine the gain of every node from group *Q* which is connected to *v* and consequently the following iteration begins. Sustain the process until the weight of group P becomes half of the total weight, i.e., \(w\left( P \right) = \frac{1}{2}w\left( V \right)\).

\(\overrightarrow { U}_{mn} , \vec{V}_{mn}\), and \(\vec{W}_{mn}\) are the position velocity and personal best vectors, respectively, for the graph \(G_{m} = \left( {V_{m} ,E_{m} } \right)\) for each *n*th particle. Partitioning phase of MRDPSO resets the population on *G*_{m} and continuously sends position velocity and personal best vectors, \(\overrightarrow { U}_{mn} , \vec{V}_{mn} , \vec{W}_{mn}\) to the succeeding stage improved graph.

Internal and external weights of every element are calculated in the second step. The summation of weights of all the edges incident on the vertex *x* inside the block is an internal weight. The summation of weights of the all edges incident on the node *u* outside the group is an external weight.

Boundary hash table contains the border nodes with positive external weight. Internal and external weights and boundary hash table are determined at time *t* = 0. MRDPSO has nested loop structure, the outer loop decides stopping criteria whether to run MRDPSO for determined quantity of rounds *C*_{max} or not. Internal and external weights of an element are the key features of MRDPSO to determine the gain and border node. For preserving the uniformity in internal and external weights, the weights of all the adjacent nodes of the shifted node are restructured, at each iteration. The boundary hash table also gets updates with the progress in partitioning. Process flow is of MRDPSO as shown in Figs. 1 and 2.

In the third stage, we apply recursive algorithm for *k*-partitioning of the bisected graph generated in the first two steps of MRDPSO. This recursively generated *k*-partitioned graph is projected back to the segmented image

### Conversion of an image to the weighted graph