## 2 Calligraphy Dataset
### Centroid Algorithm
#### 2.2.2 Character Segmentation  
The distance between each centroid point in the figure is calculated as Equation (7):  
\[D_{(a,\ b)}=\sqrt{\left(C_{x_{a}}-C_{x_{b}}\right)^{2}+\left(C_{y_{a}}-C_{y_{b}} \right)^{2}}, \tag{7}\]  
For the distance between a shape's heart points, the heart point distance of strokes from the same character is closer in most cases. However, there are also situations where strokes connected by many strokes result in a bigger distance between the heart points. By setting the closest point distance threshold \(d_{1}\) and the relative distance threshold \(d_{2}\), only one point that is closest but smaller than \(d_{1}\) and all points smaller than \(d_{2}\) are taken as strokes of the same character. Typically, \(d_{2}<d_{1}\).  
As depicted in Figure 4, the following operations are performed:  
1. Only take the nearest point to the centroid that is less than distance \(d_{1}\), and recognize it as the centroid point of the stroke of the same character. There may be cases where points are mutually nearest to each other. Figure 4b illustrates the connection of centroid points.
2. Recognize all centroid points based on threshold \(d_{2}\). If the centroid points are located within a distance less than \(d_{2}\) from each other, they are recognized as centroid points of the stroke of the same character. Figure 4c illustrates the connection of centroid points.
3. Combine the recognition results from (1) and (2) to obtain a set of centroid points that meet the conditions for a single character, representing strokes of the same character. Based on the recognition results, calculate the minimum foreground value \((x_{min},y_{min})\) and maximum foreground value \((x_{max},y_{max})\), and obtain the coordinates for the character box for all strokes of the same character, as depicted in Figure 4d.  
The centroid algorithm can effectively utilize the geometric information of foreground values to divide characters, preventing the failure of the character box recognition algorithm caused by large character deformation. However, the algorithm itself also has disadvantages. When processing images with a large number of characters, it is challenging to determine suitable threshold values \(d_{1}\) and \(d_{2}\) for the Shape Center Algorithm. After testing, it is proven that this algorithm has a good effect when there are not many characters in the image, and thus, it can be used to supplement the character box algorithm.  
This paper uses the projection algorithm combined with the Shape Center Algorithm in data processing. Specifically, the projection algorithm first calculates the character box and sets the character box threshold width as W and height as H. If there is a character box width \(x_{max}-x_{min}>\) W or height \(y_{max}-y_{min}>H\), shape center point calculation is applied to that character box, as depicted in Figure 5. Compared to using only the character box algorithm, the Shape Center Algorithm effectively improves segmentation accuracy. Combining these two algorithms can achieve better segmentation results for calligraphy characters.  
According to Figure 5, the font box algorithm, which is solely based on the projection method, demonstrates poor performance, capturing only 36 out of 277 characters. The font box algorithm based on connected component analysis achieves a relatively better result, capturing 173 characters. However, the proposed font box algorithm combining the projection method and centroid algorithm significantly captures 233 characters. This effectively enhances the efficiency of generating the required dataset for neural network training.