# Boundary-Aware Transformer for Optic Cup and Disc Segmentation in Fundus Images
## 3 Proposed Method
### Boundary-Aware Transformer Attention  
To improve the accuracy of boundary delineation between the OD and OC in fundus images, we propose the BAT module. While the conventional CNN-based U-Net architecture excels at learning local feature-level information, it has limitations in explicitly capturing global structural relationships, relative object positioning, and boundary information. In particular, accurately segmenting the OC located within the OD requires more than local features alone, as it is difficult to precisely distinguish the complex relationship between the two structures. The self-attention mechanism in Transformers can selectively emphasize highly relevant regions across an entire image, making it advantageous for integrating broader contextual information compared to standard CNNs. However, conventional self-attention generates the Query, Key, and Value from the same feature map, limiting its ability to explicitly learn boundary relationships between structurally distinct objects. While it can model positional correlations, it is not optimized for clearly distinguishing boundaries between different structures. To overcome these limitations, we designed the BAT module. In BAT, the Query (Q) is extracted from the OC feature map to focus attention on the relatively smaller cup region, while the Key (K) is generated from the OD feature map to encode the structural relationship between the cup and disc. The Value (V) is taken from the global feature map,  
Figure 3: Examples of colormap-based augmentation. These conversions enhance visual diversity while preserving anatomical boundaries of the optic disc and cup. integrating the relationship between Q and K to produce the final segmentation output. This independent setting of Q, K, and V directly reflects the inclusion structure of the OC within the OD and is implemented as the input configuration for the Transformer attention. As a result, the BAT enables boundary-focused feature enhancement, effectively compensating for the structural boundary recognition that conventional U-Net-based segmentation models tend to miss. BAT is designed to take the feature maps extracted at each resolution stage of the U-Net encoder as inputs, allowing the model to explicitly learn boundary relationships between the OD and OC across multiple spatial scales. This design not only improves fine boundary recognition but also contributes to enhanced precision and structural consistency in segmentation performance. \[Q=f_{emb}(F_{OC}),\quad K=f_{emb}(F_{OD}),\quad V=f_{emb}(F_{Global}) \tag{2}\]  
where \(f_{\text{emb}}(\cdot)\) denotes a linear transformation that embeds the feature maps into the appropriate input dimension for the Transformer. The BAT module includes a transformation step that converts the feature maps extracted from the intermediate skip connections of the U-Net's convolutional layers into suitable inputs for Transformer attention. To achieve this, the feature maps are passed through an embedding layer, which projects them into fixed-dimensional vectors as follows:  
\[F_{emb}=W_{emb}F+b_{emb},\quad F_{emb}\in\mathbb{R}^{32\times 32\times d} \tag{3}\]  
where \(W_{\text{emb}}\) is a learnable weight matrix, \(b_{\text{emb}}\) is the bias term, and \(d\) denotes the model dimension used in the Transformer. Following the embedding step, Multi-Head Self-Attention (MHSA) is applied to learn the structural relationship between the OD and OC. Each attention head plays a critical role in distinguishing the OC boundary within the OD, and through the attention weights, the model is able to capture key boundary features essential for accurate segmentation. \[\text{Attention}(Q,K,V)=\text{softmax}\bigg{(}\frac{QK^{T}}{\sqrt{d_{k}}} \bigg{)}V \tag{4}\]  
The embedded feature maps are processed through MHSA, which enables the model to learn the structural relationship between the OD and OC across multiple attention heads.