Automated segmentation of Mycobacterium tuberculosis bacilli in Ziehl Neelsen stained sputum smears is essential for scalable tuberculosis (TB) screening, particularly in low resource settings where heterogeneous staining and poor illumination degrade image quality. Most encoder and decoder models such as Unet rely on overlap based supervision and lack embedding level discrimination, leading to feature confusion between bacilli and staining artifacts under low light conditions. To address this limitation, we propose a Hybrid Residual Unet with Triplet Embedded Metric Learning (RTL), which incorporates margin based metric supervision at the residual bottleneck using structured anchor, positive, and negative sampling and a joint Dice, binary cross entropy, and triplet objective. Evaluated on the DDS1 dataset with illumination stratified analysis, RTL outperformed Unet, Resunet, triplet based baselines, and Transunet, achieving higher Dice and mIoU, lower margin violation rates, and significantly improved embedding separability (p < 0.05). RTL also showed reduced performance variance across illumination subsets, indicating improved robustness to domain shift and more reliable bacilli delineation, which can support downstream components of automated TB microscopy workflows (detection, counting and slide level grading).
Copyrights © 2026