Accurate medical image segmentation is paramount for precise diagnosis and treatment in modern healthcare. This research presents a comprehensive study of the efficacy of particle swarm optimization (PSO) combined with histogram equalization (HE) preprocessing for medical image segmentation, focusing on lung CT scan and chest X-ray datasets. Best-cost values reveal the PSO algorithm’s performance, with HE preprocessing demonstrating significant stabilization and enhanced convergence, particularly for complex lung CT scan images. Evaluation metrics, including accuracy, precision, recall, F1-score/Dice, specificity, and Jaccard, show substantial improvements with HE preprocessing, emphasizing its impact on segmentation accuracy. Comparative analyses against alternative methods, such as Otsu, Watershed, and K-means, confirm the competitiveness of the PSO-HE approach, especially for chest X-ray images. The study also underscores the positive influence of preprocessing on image clarity and precision. These findings highlight the promise of the PSO-HE approach for advancing the accuracy and reliability of medical image segmentation and pave the way for further research and method integration to enhance this critical healthcare application.