# Advanced Medical Image Segmentation Enhancement:
## 3 Materials and Methods
### Particle Swarm Optimization (PSO)
The optimization goal is to find the optimal partition by minimizing \(f(X)\). 3. **Optimization Iterations:** The PSO algorithm iteratively updates the positions of particles based on their previous best positions and the best positions found by neighboring particles. Particles adjust their positions in search of the optimal image partition. The optimization continues until convergence criteria are met or a specified number of iterations is reached. Each particle keeps track of two pivotal fitness values: \"local best (pbest)\" (Equation (2)) and \"global best (gbest)\" (Equation (3)) [95]. The term \"pbest\" signifies the best value achieved by an individual particle throughout the optimization process and is recalculated iteratively at each time step. In contrast, \"global best\" represents the overarching best value attained among all particles \"pbest\" values up to that specific time step. \[\mathbf{p}_{best_{i}}^{t}=\mathbf{x}_{i}^{*}\mid f(\mathbf{x}_{i}^{*})=\min_{ k=1,2,\ldots,t}\Big{(}\Big{\{}f\Big{(}\mathbf{x}_{i}^{t}\Big{)}\Big{\}}\Big{)}, where(i\in\{1,2,\ldots,N\})\] (2) \[\mathbf{g}_{best}^{t}=\mathbf{x}_{*}^{t}\mid f\Big{(}\mathbf{x}_{*}^{t}\Big{)} =\min_{ \begin{array}{c}i=1,2,\ldots,N\\ k=1,2,\ldots,t\end{array} }\Big{(}\Big{\{}f\Big{(}\mathbf{x}_{i}^{t}\Big{)} \Big{\}}\Big{)}\] (3) In optimization [98], \(i\) represents the particle's index (1 to \(N\)), \(t\) is the current iteration, \(f\) is the objective function to be minimized, \(x\) is the position vector, and \(N\) is the total number of particles in the swarm. 4. **Optimal Partition Extraction:** The final result of PSO is the image partition that minimizes the objective function. This partition represents segmentation of the input medical image into distinct regions of interest. The partition is chosen based on the collective behavior of particles, which adapt and explore the search space to find the best segmentation. Particle positions and velocities evolve dynamically based on Equations (4) and (5). \[X^{i}_{(n+1)}=X^{i}_{n}+V^{i}_{(n+1)} \tag{4}\]  
\[V^{i}_{(n+1)}=V^{i}_{n}+c_{1}r_{1}(pbest^{i}_{n}-X^{i}_{n})+c_{2}r_{2}(gbest^{i }_{n}-X^{i}_{n}) \tag{5}\]  
In particle swarm optimization (PSO), key variables and parameters shape the optimization process [28]. These include the positions (\(X^{i}_{n}\) and \(X^{i}_{(n+1)}\)) and velocities (\(V^{i}_{(n+1)}\)) of particles as well as essential factors like the inertia weight (\(w\)), cognitive component (\(c_{1}\)), social component (\(c_{2}\)), and random values (\(r_{1}\) and \(r_{2}\)) within the range \([0,1]\). Additionally, PSO tracks two significant values: \(pbest^{i}_{n}\), the best position found by a particle at time step \(t\); and \(gbest^{i}_{n}\), the best position found across the entire swarm at time step \(t\). These elements collectively steer particle dynamics and the quest for optimal solutions. The application of PSO in medical image segmentation offers several advantages, including its ability to handle non-convex and non-linear objective functions [99], its simplicity of implementation, and its capacity to explore a diverse range of solutions. However, like other optimization techniques, PSO is sensitive to its parameter settings and may converge to local optima if not carefully tuned [22; 57]. In our method, PSO plays a central role in optimizing the image segmentation process. It is seamlessly integrated with histogram equalization (HE), which enhances the quality of the segmented regions. This integration addresses the limitations associated with traditional segmentation methods and offers a novel and effective solution to the challenges associated with medical image segmentation. By incorporating PSO as a core component, our methods optimize the segmentation process and seek the best partitioning of the input medical image. The synergy between PSO and HE enhances the accuracy and robustness of the segmentation results: ultimately improving the quality of the segmented regions and making them more suitable for subsequent analysis and clinical applications.