# Boundary-Aware Transformer for Optic Cup and Disc Segmentation in Fundus Images
## 3 Proposed Method
### Loss Function: Geometry-Aware Loss  
To more precisely delineate the boundaries between the OD and OC, this study proposes a Geometry-aware Loss that combines Dice Loss with normalized Hausdorff Distance Loss. Conventional segmentation models typically use Cross-Entropy or Dice Loss to measure the degree of overlap between the predicted mask and the ground truth, focusing on maximizing overall region matching. However, these loss functions have limitations in fully capturing fine-grained segmentation performance at the boundary areas. In glaucoma diagnosis, where boundary recognition between the OD and OC is critical, relying solely on pixel-centric loss functions makes it difficult to achieve stable and high precision. Accordingly, we designed a loss structure that considers both region overlap and boundary precision. The Dice Loss effectively measures the overall degree of overlap between two regions, while the Hausdorff Distance captures local boundary errors by measuring the maximum distance between the predicted and ground truth boundaries. In  
Figure 4: Structure of the proposed BAT module (**left**) and attention map visualization (**right**). The inputs to the attention mechanism are set as Query from the optic cup features, Key from the optic disc features, and Value from the global feature map, enabling boundary-aware representation learning. particular, the Hausdorff Distance emphasizes extreme boundary outliers, encouraging the model to learn even subtle errors near the boundary. In this study, we normalized the Hausdorff Distance by the diagonal length of the image, reducing the scale gap between the Dice Loss and Hausdorff Distance when combined, thereby improving both training stability and boundary recognition performance. The combination of the Dice Loss and normalized Hausdorff Distance Loss effectively reduces prediction errors near the OD/OC boundaries and plays a critical role in elevating boundary precision and overall segmentation quality to clinically meaningful levels. \[\mathcal{L}_{Dice}=1-\frac{2\sum_{i}y_{i}\dot{y}_{i}}{\sum_{i}y_{i}+\sum_{i} \dot{y}_{i}} \tag{7}\]  
where \(y_{i}\) denotes the ground truth label, and \(\dot{y}_{i}\) represents the predicted segmentation output. While the Dice Loss effectively evaluates the overall region overlap, it is less sensitive to discrepancies near object boundaries, which is a critical limitation in tasks requiring fine boundary localization. To overcome this, we incorporate Hausdorff Distance Loss to improve the precision of boundary delineation between the OD and OC. The Hausdorff Distance measures the maximum deviation between the closest points of two sets, in this case, between the predicted and ground truth segmentation boundaries. By minimizing this distance, the model is encouraged to align its predicted boundaries more closely with the actual anatomical contours. \[\mathcal{L}_{HD}=\max\left(\sup_{x\in Y}\inf_{y\in\hat{Y}}d(x,y),\sup_{x\in \hat{Y}}\inf_{y\in Y}d(x,y)\right) \tag{8}\]  
where \(Y\) denotes the set of boundary points in the ground truth, \(\hat{Y}\) represents the set of predicted boundary points, and \(d(x,y)\) is the Euclidean distance between points \(x\) and \(y\). The operator sup refers to the maximum distance from a point to the closest point in the other set, capturing the worst-case scenario, while inf indicates the minimum distance between two points. In this context, the Hausdorff Distance \(\mathcal{L}_{HD}\) serves as a metric that quantifies the worst-case deviation between the predicted and actual boundaries, making it particularly effective for penalizing large boundary errors in segmentation tasks. However, the Hausdorff Distance is sensitive to image scale, as its values can vary significantly depending on image resolution. When combined directly with the Dice Loss, which is bounded in the range \([0,1]\), the mismatch in scale can destabilize the training process. While the Dice Loss yields normalized values, the Hausdorff Distance may range from tens to hundreds of pixels.