# Advanced Medical Image Segmentation Enhancement:
## 4 Results and Discussion
### Experimental Setup
#### 4.1.2 PSO Segmentation Parameters  
In our method, we tailor particle swarm optimization (PSO) parameters (Table 1) to the specific characteristics of the datasets and the challenges associated with lung CT scans and chest X-rays. In our experiments, the number of segments (\(k\)) is a pivotal parameter that determines how the images are partitioned, with \(k\) set to two segments in our experiments. The cost function (\(CostFunction\)) is the guiding force in the PSO process and directs the partitioning of medical images based on the optimization objective. The decision variable matrix size (\(VarSize\)) is specified as \([k,size(X,2)]\) and provides insight into the size of the matrix involved with decision variables. Furthermore, the number of decision variables (\(nVar\)) is calculated by the product of the dimensions of \(VarSize\), which signifies the total number of decision variables considered in the optimization. To ensure that particles adhere to suitable ranges during optimization, we establish lower and upper bounds of variables (\(VarMin\) and \(VarMax\)) by considering the minimum and maximum values in the image data. Figure 6: Histogram equalization (HE) preprocessing for lung CT scan and chest X-ray images demonstrating the resulting histogram distributions. Grayscaling 8-bit images of (**a**) lung CT scan and (**c**) chest X-ray images followed by HE preprocessing in (**b**) and (**d**), respectively, with histograms illustrating the outcome in each case. A series of critical PSO parameters influence the optimization process. Initially, the maximum number of iterations (_MaxIt_) was assessed (with the initial value set to 100) and the population size (_nPop_) varied within the range of 2 to 20 [100] and thereby controlled the duration of the optimization procedure. The optimal iteration was determined by the last iteration in which the minimum best cost function value was achieved and remained unchanged. This criterion is established by the information presented in Figure 5 under the second condition of cost evaluation. Analysis of the results indicated that setting _MaxIt_ to 50 and _nPop_ to 5 yielded the optimal outcome, with the best cost of 93.3202. Upon further evaluation, based on the results presented in Figure 7, it was determined that the optimal value for _MaxIt_ was 50. Consequently, for subsequent iterations of this experiment, the _MaxIt_ parameter was adjusted to 50 to enhance the optimization process. This evaluation also assessed the computation time for each parameter setting, with the aim of minimizing it while achieving the best results. The minimum time recorded was 0.25716 s. These results, including optimal iterations vs. population size and computation time, are presented in Figure 7.  
Additionally, we explored scenarios involving the inertia weight (_w_) by varying (decreasing) its value from 1 to 0.4 [101], as shown in Table 2. The results underscore that the optimal weight is 1, as this value demonstrated its effectiveness at achieving optimal outcomes. Optimal results can be obtained with an inertia weight damping ratio (_wdamp_) of 0.99, which dictates how the inertia weight diminishes over each iteration. The personal learning coefficient (_c_1) and global learning coefficient (_c_2) are assigned values of 1.5 and 2.5, respectively [102]. These parameters govern the impact of a particle's best-known position and the global best-known position on its movement within the optimization process. Velocity limits (_VelMax_ and _VelMin_) are instrumental for preserving the velocity of particles within acceptable boundaries. These limits are pivotal for ensuring that particle velocities do not exceed reasonable levels during optimization. By harmonizing these parameters, our method balances exploration and exploitation in order to seek reliable solutions while avoiding overfitting the training data.