Abstract This research aims to enhance X-ray lung segmentation by addressing boundary distortions in anatomical structures, with the objective of refining segmentation boundaries and improving the morphological shape of segmented objects. The proposed approach combines the K-segment principal curve with Gaussian Process Regression (GPR) to refine segmentation boundaries, evaluated using lung X-ray datasets at varying resolutions. Several state-of-the-art models, including U-Net, SegNet, and TransUnet, were also assessed for comparison. The model employed a custom kernel for GPR, combining Radial Basis Function (RBF) with a cosine similarity term. The effectiveness of the model was evaluated using metrics such as the Dice Coefficient (DC) and Jaccard Index (JC) for segmentation accuracy, along with Average Symmetric Surface Distance (ASSD) and Hausdorff Distance (HD) for boundary alignment. The proposed method achieved superior segmentation performance, particularly at the highest resolution (1024x1024 pixels), with a DC of 95.7% for the left lung and 94.1% for the right lung. Among the different models, TransUnet outperformed others across both the semantic segmentation and boundary refinement stages, showing significant improvements in DC, JC, ASSD, and HD. The results indicate that the proposed boundary refinement approach effectively improves the segmentation quality of lung X-rays, excelling in refining well-defined structures and achieving superior boundary alignment, showcasing its potential for clinical applications. However, limitations exist when dealing with irregular or unpredictable shapes, suggesting areas for future enhancement.