Breast cancer is a prevalent disease and the second leading cause of death in women globally. Various imaging techniques, including mammography, ultrasonography, X-ray, and magnetic resonance, are employed for detection. Thermography shows significant promise for early breast disease detection, offering advantages such as being non-ionizing, non-invasive, cost-effective, and providing real-time results. Medical image segmentation is crucial in image analysis, and this study introduces a thermographic image segmentation algorithm using the improved Black Widow Optimization Algorithm (IBWOA). While the standard BWOA is effective for complex optimization problems, it has issues with stagnation and balancing exploration and exploitation. The proposed method enhances exploration with Levy flights and improves exploitation with quasi-opposition-based learning. Comparing IBWOA with other algorithms like Harris Hawks Optimization (HHO), Linear Success-History based Adaptive Differential Evolution (LSHADE), and the whale optimization algorithm (WOA), sine cosine algorithm (SCA), and black widow optimization (BWO) using otsu and Kapur's entropy method. Results show IBWOA delivers superior performance in both qualitative and quantitative analyses including visual inspection and metrics such as fitness value, threshold values, peak signal-to-noise ratio (PSNR), structural similarity index measure (SSIM), and feature similarity index (FSIM). Experimental results demonstrate the outperformance of the proposed IBWOA, validating its effectiveness and superiority.