## 3 SAM-Based Approach to Improve Panoramic Image Segmentation in Indoor Construction Environments
### Label Extraction and Labeling  
While the proposed method effectively extracted high-quality object masks using SAM and the three processing techniques, the segmented objects lacked labels, necessitating an additional labeling process. As mentioned in Section 2.2, this study used the Panoplane360 labels for vertical and horizontal plane segmentation as a reference to label the SAM-generated object masks.  
Given a panoramic image of an indoor construction site, Panoplane360 outputs the following two label masks: one for vertical planes and another for horizontal planes. To assign these labels to the SAM-extracted objects effectively, Algorithm 4 was applied. First, the object masks were overlaid with the label masks, and the dominant label within each object region was determined. The most dominant label was then assigned to an object only if it occupied at least one-third of the object mask area, ensuring that minor overlaps did not lead to incorrect label assignment.  
After the label assignment, multiple object masks were found to have the same label, necessitating an additional merging process. Using the filtered labels, object masks with identical labels were merged into a single mask, ensuring a one-to-one correspondence between objects and labels. Figure 6 illustrates the overall process, where the extracted Panoplane360 labels are systematically assigned to the SAM-generated objects.  
Figure 5: Separation of intersecting detected object masks and definition of new masks.  
```
1:List of object masks \(\mathbf{M}_{\text{obj}}\), label mask \(\mathbf{L}\) of size \(H\times W\)
2:Merged labeled masks \(\mathbf{M}_{\text{merged}}\)
3:Step 1: Overlapping masks and Filter Labeled masks
4:Initialize enhanced label mask \(\mathbf{L}_{\text{enhanced}}\leftarrow\mathbf{0}_{H}\times W\)
5:Initialize labeled mask list \(\mathbf{M}_{\text{labeled}}\leftarrow\emptyset\)
6:for each object mask \(\mathbf{M}_{i}\mathbf{\in}\mathbf{M}_{\text{obj}}\)do
7: Compute object mask area: \(\mathbf{A}_{i}\)
8: Compute label overlap: \(\mathbf{L}_{\text{overlap}}\leftarrow\mathbf{M}_{i}\cdot\mathbf{L}\)
9: Extract label and compute frequencies: \(\mathbf{L}_{\text{}}\mathbf{C}\leftarrow\text{UniqueCounts}(\mathbf{L}_{\text{ valid}})\)
10: Select dominant label: \(\mathbf{L}_{\text{dom}}\leftarrow\mathbf{L}[\text{arg max }\mathbf{C}]\)
11: Get dominant label count: \(\mathbf{C}_{\text{dom}}\leftarrow\max\mathbf{C}\)
12:if\(\mathbf{C}_{\text{dom}}\geq\mathbf{A}_{i}/3\)then
13: Assign dominant label: \(\mathbf{M}_{\text{labeled}}\leftarrow\mathbf{M}_{i}\cdot\mathbf{L}_{\text{dom}}\)
14: Append \(\mathbf{M}_{\text{labeled}}\) to \(\mathbf{M}_{\text{labeled}}\)
15: Update enhanced label mask: \(\mathbf{L}_{\text{enhanced}}\leftarrow\mathbf{L}_{\text{enhanced}}+\mathbf{M}_{ \text{labeled}}\)
16:endif
17:endfor
18:Step 2:Merge Object Masks Based on the Same Labels
19: Extract sorted unique labels: \(\mathbf{L}_{\text{sorted}}\leftarrow\text{SortByFrequency}(\mathbf{L}_{\text{enhanced}})\)
20:Initialize merged mask list \(\mathbf{M}_{\text{merged}}\leftarrow\emptyset\)
21:for each label \(\mathbf{L}\in\mathbf{L}_{\text{sorted}}\)do
22: Initialize merged mask \(\mathbf{M}_{\text{merged}}\leftarrow\mathbf{0}_{H\times W}\)
23:for each labeled mask \(\mathbf{M}_{\text{labeled}}\in\mathbf{M}_{\text{labeled}}\)do
24:if\(\mathbf{L}\in\mathbf{M}_{\text{labeled}}\)then
25:\(\mathbf{M}_{\text{merged}}\leftarrow\mathbf{M}_{\text{merged}}+\mathbf{M}_{ \text{labeled}}\)
26:endif
27:endfor
28:Return \(\mathbf{M}_{\text{merged}}\)
```  
**Algorithm 4**Object mask assignment and merging  
Figure 6: Label assignment and merging process of the object masks.