In order to detect 3D-MRI brain tumors accurately, contours should be determined correctly. To achieve this goal, the proposed model fuses semantically k-means and DA optimization. Herein, the semantic fusion is achieved using k-means inside DA clustering, i.e., rather than using a random center of the mass of the neighborhood (cluster centers) within DA clustering, k-means regulate these accurately.

Figure 4 shows the main model’s components and the way they are linked to each other. Our proposed brain tumor segmentation model consists of three main steps: pre-processing, two-step dragonfly algorithm clustering, and the last phase, level set segmentation. The following subsections discuss these components in detail.

#### 3.1. Preprocessing Phase

Segmentation of MRI brain tumor scans always challenged by poor image quality, the main cause for image degradation in MRI is the contamination of the MRI images with noises like irregularities [

37]. Pre-processing operations are required to enhance the image quality, the target for these procedures is to reduce the contaminated noise and improve segmentation of image edges by eliminating inhomogeneous areas of the image. In the proposed model, four steps were applied: conversion of the 3D-MRI into 2D slices, skull-stripping, anisotropic diffusion, and contrast enhancement.

Figure 5 shows an example of one patient’s 2D slices after pre-processing. Herein, the conversion process was applied using 3D Slicer, which is an open- source software web application for medical image informatics, image processing, and three-dimensional visualization.

Skull-stripping comprises three steps involving morphological operations: Step 1: The input 2D-MRI slices are converted to binary images using Otsu’s thresholding. Step 2: Dilation and erosion operations are undertaken to preserve the minute features of the brain in the resultant 2D-MRI slices (creation of the mask). By filling the holes, the brain becomes a complete connected component. Step 3: (Superimposition): The final skull stripped image is obtained by superimposing the mask on the input image [

37]. An anisotropic diffusion filter is employed to diminish the noise in the image and homogenize it in regions having a similar grey level by preserving regions’ edges. As a generalization of the diffusion process, anisotropic diffusion filter creates a set of parameterized images, such that each image in the resulting images is a fusion of the original image and an original image local content-based filter. Therefore, anisotropic diffusion is a space variant and non-linear transformation of the original image. See reference [

38] for more information. Finally, contrast enhancement is applied using a histogram equalization technique in which the tumor conspicuity is improved by redistributing the greyscale of the images in a non-linear way to advance the separation of latent or hidden variations in pixel intensity into a more visually discernible distribution, thus taking advantage of the human vision physiological attributes [

37,

38].

#### 3.2. Two Steps Dragonfly-Based Clustering Phase

Clustering is a powerful tool in machine learning systems, it uses predefined similarity criterion for grouping unlabeled group of data objects or clusters [

39,

40]. The clustering problem can be formulated as an optimization problem as follow: given a set

$S=\left\{{s}_{1},{s}_{2},{s}_{3}\dots {s}_{n}\right\}$ is a set of

$n$ objects

$\mathrm{and}{T}_{n\ast m}$ is a data matrix consisting of

$n$ rows and

$m$ columns where

$n$ represents the number of objects of a dataset, and

$m$ represents the number of attributes (features) or dimensions of a given dataset. The

$i$-th data object

${x}_{i}=\left\{i=1,2,3,\dots n\right\}$ is defined using a real-valued

$m$-dimensional vector where each object

${x}_{ij}$ denotes the

$j$-th feature

$\left(j=1,2,3,\dots m\right)$ of the

$i$-th object

$\left(i=1,2,3,\dots n\right)$. The objective of the clustering algorithm is to create a set of partition

$Z=\left\{{z}_{1},{z}_{2},\dots {z}_{k}\right\}$ for the given data matrix

${T}_{n\times m}$ and satisfying the following conditions:

In our model, to accelerate the convergence rate and preserve the stability during exploration and exploitation, a two-step DA algorithm is used to improve it for clustering problems using the k-means algorithm [

40]. The main steps of the DA clustering algorithm are shown in Algorithm 1. Herein, to handle randomization of the selection of the center of the mass of the neighborhood within the DA algorithm, k-means is used to generate accurate centers.

**Algorithm 1**: Two-step Dragonfly Clustering. |

**Input**: $\mathit{D}$ dataset contains MRI brain images
**Output**: Best solution of final cluster center (${\mathit{C}}_{\mathit{b}\mathit{e}\mathit{s}\mathit{t},\mathit{j}}$) $\mathit{j}=\mathbf{1},\mathbf{2},\mathbf{3},\mathbf{4}$
**Begin** **Initialization phase** Initialize the position of dragonfly population X_{i} (i = 1 2, ..., n). Initialize step vectors Δ X_{i} **For** $\mathit{i}=\mathbf{1}:{\mathit{S}}_{\mathit{N}}$ /* ${\mathit{S}}_{\mathit{N}}$ is the total number of food sources (number of clusters) */ Initialize the food source within the boundary of given dataset in random order; Evaluate the better potions of food sources by applying the k-means algorithm / *Algorithm 2*/ Send the dragonflies to the food sources; / * Computed centers */ **End** For **Dragonfly algorithm Phase** Iteration = 0; **Do While** (the end condition is not satisfied) For i = 1:n Calculate the fitness of each dragonfly Update the food source and enemy Update w, s, a, c, f, and e Calculate S, A, C, F, and E using Equations (4) to (8) Update neighboring radius **If** (a dragonfly has at least one neighboring dragonfly) Update step vector (ΔX) using Equation (9) Update position vector X using Equation (10) **Else** Update position vector using Equation (11) **End if** Check and correct the new positions based on the boundaries of variables **End For** **For** $\mathit{i}=\mathbf{1}:{\mathit{S}}_{\mathit{N}}$ Compute the probability. /* Calculate the probability for each one */ **End For** **For** $\mathit{i}=\mathbf{1}:{\mathit{S}}_{\mathit{N}}$ **If** (rand ( ) < ${\mathit{P}}_{\mathit{i}}$) /* ${\mathit{P}}_{\mathit{i}}$ denotes the probability associated with ${\mathit{i}}^{\mathit{t}\mathit{h}}$ food source */ Calculate the new fitness of the new food source using Equation (14); Select the best food source by using a greedy selection between the old and new food source; **Else** $\mathit{i}=\mathit{i}+\mathbf{1}$; **End If** **End For** **End While** Output: Final clusters‘ centers.
**End** |

Initialization stage: The K-means algorithm (see Algorithm 2) is used to find the initial food sources (center of the mass of the neighborhood). Herein, four clusters representing background (

${\mathit{R}}_{\mathit{B}}$), gray matter (

${\mathit{R}}_{\mathit{G}}$), white matter (

${\mathit{R}}_{\mathit{G}\mathit{W}}$), and tumor (

${\mathit{R}}_{\mathit{G}\mathit{T}\mathit{C}}$) as stated in [

41] are identified. Each point is then assigned to the nearest centroid. In this paper, the Euclidean distance is used as a measure to the proximity which used to assign objects to the nearest centroids. The clusters are created by assigning each object to the suitable cluster based on the proximity measure, the centroids then updated based on the average of the object proximity measures in each cluster. The reassigning process and centroids updating are repeated until there is no change in each cluster’s objects [

42].

**Algorithm 2**: K-means clustering [42]. |

Input: $\mathit{K}=\mathbf{4}$. // the number of clusters; $\mathit{D}$ dataset contains MRI brain images (2D slices).
**Begin** Arbitrary choose $\mathit{K}$ objects from $\mathit{D}$ as the initial cluster centers;
**Repeat** - (re) group the most similar objects into a cluster, based on the Euclidian distance between the object and the cluster centroid (mean); - Update the cluster centroid, i.e., calculate the mean value of the objects for each cluster.
**Until** no change. |

Determine initial segmentation points using dragonfly algorithm

The behavior of swarms follows three primitive principles [

14,

15,

43,

44]: (1) Separation principle, this principle relies on the fact that the swarm individuals tries to avoid static collision with other individuals in the neighborhood. (2) Alignment principle, this principle reflects the attitude of the each individual in the swarm to match its velocity with other individuals in the neighborhood; and (3) Cohesion principle, this principle refers to the tendency of swarm individuals to centralized around the neighborhood mass center. In order to survive, all the swarm individuals should be attracted towards food sources and repelled from enemies. Each of these behaviors is mathematically formulated as follows:

Separation is calculated as follows [

44]:

where

X is the position of the current individual,

${X}_{j}$ represents the position

j-th neighboring individual, and

N is the number of neighboring individuals.

Alignment is calculated as follows:

where

${V}_{j}$ is the velocity of

j-th neighboring individual.

Cohesion is calculated as follows:

where

N is the number of neighborhoods, and

X_{j} shows the position

j-th neighboring individual.

Attraction towards a food source is calculated as follows:

where

${X}^{+}$ is the position of the food source.

Repulsion from an enemy is calculated as follows:

where

${X}^{-}$ is the position of the enemy.

The behavior of dragonflies is assumed to comprise the combination of these five corrective patterns. To update the location of artificial dragonflies in a search space and simulate their movements, two vectors are considered: step (

$\Delta $X) and position (

X). The step vector shows the direction of the movement of the dragonflies and is defined as follows:

where

s,

a, and

c are the weights of separation, alignment, and cohesion respectively.

Si,

Ai, and

Ci represent separation, alignment, and cohesion of the i-th individual respectively

f is the food factor,

${F}_{i}$ is the food source of the i-th individual,

e is the enemy factor,

${E}_{i}$ is the position of enemy of the i-th individual,

w is the inertia weight, and

t is the iteration counter. After calculating the step vector, the position vectors are calculated as follows:

With separation, alignment, cohesion, food, and enemy factors (

s,

a,

c,

f, and

e), during dragonfly optimization, different explorative and exploitative behaviors can be reached. Neighbors of dragonflies are very important, so a neighborhood (circle in a 2D) with a certain radius is assumed around each artificial dragonfly. Dragonflies tend to align their flying while keep proper separation and cohesion in a dynamic swarm. In a static swarm, however, alignments are very low while cohesion is high to attack prey. Therefore, while exploring the search space, dragonflies with high alignment and low cohesion weights were assigned, on the other hand dragonflies with low alignment and high cohesion when exploiting the search space. Due to switching between exploration and exploitation, the radii of neighborhoods are increased proportionally to the number of iterations. Another way to balance exploration and exploitation is to adaptively tune the swarming factors during optimization. While converging to the global optimum in the final stage of the algorithm, the neighborhood area became larger as the swarm becomes one group. The best and the worthiest reached solutions are used as the food source and enemy. This causes convergence towards promising areas of the search space and divergence from non-promising regions of the search space.

Figure 6 shows the flowchart of the dragonfly algorithm.

When there are no neighboring solutions, dragonflies must travel around the search space. Dragonflies use a random walk (

$L\mathrm{\xe9}vy$ flight) to boost the randomness, stochastic behavior, and. In this case, the position of dragonflies is updated using the following equation [

44]:

where

d is the dimension of the position vectors.

${r}_{1},{r}_{2}$ are two random numbers in [0,1],

$\beta $ is a constant, and

$\mathsf{\Gamma}\left(x\right)=\left(x-1\right)!$. Herein, the fitness function is calculated as:

${n}_{j}$ is the number of data instances that are used to normalize the sum, and

${C}_{i}$ is the class which data instances belong to.

#### 3.3. Level Set Segmentation

Level set (LS) techniques are powerful tools for modelling time varying objects, by using level set techniques it is not difficult to follow topological changes in the object shape. They use deformable models with active contour energy minimization techniques without parametrizing the surface to find a solution for the minimal distance curves problem. LS methods are controlled by curvature-dependent speeds of moving curves or fronts [

21,

45,

46]. The initial position of the contour is always a key challenge in some LS methods while solving segmentation problems. The contour can move inward or outward and its initial position determines the target for segmentation. In segmenting images with poorly defined boundaries, some methods replace the initial contour with a region-based active contour and the re-initialization step has been eliminated by including a term in the Partial Differential Equation (PDE) that penalizes the deviation of level set function from a contour based signed distance function. Different level set methods differ either in how to form an initial contour or the energy functional to be minimized or some combination of both. There are still key challenges in using level set in image segmentation and there is no general level set method that can solve segmentation problem for all applications. In our case, the deformable model initialization uses the cluster centers that are computed using the previous phase for each slice as the initial placement for final tumor segmentation.

Level set segmentation techniques are based on two main stages: first, the insertion of the interface as the zero level set of a higher dimensional function, and, second, the interface’s speed to this higher dimensional level set function. The evolvement of the contour or surface is managed by a level set equation. The solution to which this partial differential equation tends to is determined iteratively by updating

φ at each time interval. The level set method is a numerical algorithm that gradually tracks the motion of a curve (in 2D slices) implicitly by embedding a propagating interface Γ as the zero level set

$\phi \left(X,t\right)=0$ of a higher dimensional function

$\phi \left(X,t\right)$, where

$X=\left(x,y\right)$, and

$t$ represents time. The level set function

$\phi $, defined over the image space, is a surface which is positive inside the region

$\mathsf{\Omega}$, negative outside

$\mathsf{\Omega}$, and zero on the interfaces between

$\mathsf{\Omega}$ and other regions. The general form of the level set equation is [

21]:

where

$\frac{\partial \phi \left(x\left(t\right),t\right)}{\partial t}$ is the evolution of

$\phi $,

$F$ is the field for speed,

$\overrightarrow{N}$ is the normal interface vector,

$k$ is a curvature controlled term with the parameter

$\alpha $,

$g$ is a velocity term weighted by

$\beta $,

$\left(\nabla {G}_{\sigma}\right)\otimes I\left(X\right)$ is equal to the scale of the image

$I$ outline, and

$\sigma $ is the variance of the Gaussian

${G}_{\sigma}$. Finally,

$\nabla g.\frac{\nabla \phi}{\left|\nabla \phi \right|}$ represent a local advection force that pulls the level set towards the tumor boundaries; this force is weighted by the parameter

$\lambda $. After some repetitions of the PDE or once

$\phi $ has converged, the final level set function

$\phi $ is achieved. Algorithm 3 illustrates the main steps of the level set segmentation procedure.

Figure 7 shows the result of applying the level set segmentation to a set of images.

**Algorithm 3**: Level set segmentation. |

1: Insert initial contour points using two-step DA clustering output (ROI indexes). 2: Construct a signed distance function. 3: Calculate feature image using Gaussian filter and gradient. 4: Obtain the curve’s narrow band. 5: Obtain curvature and use gradient descent to minimize energy. 6: Evolve the curve. 7: Repeat step number two and stop after obtaining the segmented region. |

In summary, in the traditional level set algorithm, if the initial contour is far from the actual contour, the algorithm will require a greater number of iterations, and significant computation is needed. In contrast, two-step DA clustering places the initial contour set near the actual tumor contour, resulting in good convergence and requiring fewer iterations.