# Scene Text Detection Based on Multi-Headed Self-Attention Using Shifted Windows
## 3 Method
### Label Generation  
The training phase generated three feature maps: a probability map, threshold map, and binary map. The probability map and binary map used the same supervisory signal, and the threshold map used a separate supervisory signal, so two labels need to be generated to guide the training.  
For a given input image, a number of vertices are generally used to represent the external polygons of the text regions in the image. The label generation for probability and binary maps used the Vatti clipping algorithm to shrink the original polygonal text region G to G_s. The shrinkage offset D was calculated from the circumference \(C\) and area \(A\) of the original polygon, according to Equation (16):  
\[\text{D}=\frac{A(1-r^{2})}{C}, \tag{16}\]where \(A\) is the area of the original region; \(C\) is the circumference of the original region; \(r\) is the shrinkage factor, which was empirically set to \(r=0.4\).  
Using a similar process, labels were generated for the threshold map. The original polygon text region G was expanded to G\({}_{d}\), and the offset D of the expansion was the same as D in the probability map. Then, the gap between the shrinking box G\({}_{s}\) and the expanding box G\({}_{d}\) was considered the boundary of the text area, and the normalized distance from each pixel point in this gap to the original image boundary G was calculated. According to the calculation results, the value of the normalized distance between the pixel point on the expansion box G\({}_{d}\) and the pixel point on the contraction box G\({}_{s}\) was the largest, and the pixel point on the original text border had the smallest value of 0. The overall trend was to gradually increase the values in the direction of G\({}_{s}\) and G\({}_{d}\), with the original text border as the base. The values were then normalized by dividing them by the offset D. The values on G\({}_{s}\) and G\({}_{d}\) became 1. The values were then subtracted from 1 to obtain the values on the original text border as 1 and on G\({}_{s}\) and G\({}_{d}\) as 0. The values in the direction of G\({}_{s}\) and G\({}_{d}\) became progressively smaller with the original text border as the base. At this point, the values in the G\({}_{s}\) and G\({}_{d}\) regions were in the range [0, 1]. We normalized again and took the value of (0, 1) to obtain the final label.  
In the inference phase, text bounding boxes can be computed using either probability maps or binary maps. For efficiency, using probability graphs was chosen to make it possible to remove threshold branches during inference. The formation of the text box can be divided into three steps. First, the probability map (or binary map) was binarized using a fixed threshold (0.2) to obtain a binary map. Then, the connected region (shrink text region) was obtained from the binary map. Finally, the shrink text region was expanded by the offset factor \(D^{\prime}\) of the Vatti clipping algorithm to obtain the final text box, and the formula for calculating \(D^{\prime}\) is shown in Equation (17):  
\[D^{\prime}=\frac{A^{\prime}\times r^{\prime}}{C^{\prime}}, \tag{17}\]  
where \(A^{\prime}\) and \(C^{\prime}\) are the area and circumference of the shrinking region, respectively; and \(r^{\prime}\) is empirically set to 1.5 (corresponding to the shrinking ratio \(r=0.4\)).