This paper presents a novel Hausdorff distance loss function for image segmentation, particularly in the field of medical imaging. The proposed Hausdorff distance loss function, based on the Felzenszwalb distance transform algorithm, addresses the computational complexity associated with previous Hausdorff distance loss function implementations, bringing it closer to the efficiency of the Dice loss function. The new method significantly reduces the computational time, making it only 11.2% slower than the Dice loss function, compared to the 125.9% slower rate of previous implementations. Furthermore, the proposed Hausdorff distance loss function improves the Dice similarity coefficient from 0.918 to 0.925 and reduces the Hausdorff distance from 4.583 to 3.464, demonstrating enhanced segmentation accuracy. The study’s findings suggest that the proposed Hausdorff distance loss function can be a valuable tool for medical image segmentation, providing a balance between computational efficiency and segmentation precision. The code for the new Hausdorff distance loss function is publicly available for use.