## 2 Data Preparation
### Internal Defects Classification from Collected B-Scan Images
#### 2.2.2. Distinction of Defects Based on Geometric Moments  
Holes including bolt holes, wire guide holes and structure holes, are normal ultrasonic reflectors. Its B-scan imaging is difficult to distinguish from that of holes surrounding cracks. It is shown in Figure 4. [PERSON] et al. [29] analyzed and extracted features of every rail defect, including color features, distribution features, and contour features, and built the numerical constraint relationship of the different defect categories, which solved this problem. Based on color and distribution features, the B-scan image of a bolt hole is displayed by intersecting green-red-blue channels, and the channels of bolt hole cracks are located on both sides of that bolt hole. Generally, the channels represent the upper cracks of a bolt hole are typically positioned on either side of the bolt hole's channel, with the green channel commonly situated to the right and the blue channel to the left of the bolt hole channel. When cracks adjacent to the bolt hole are absent, the channels of identical hues associated with the bolt holes exhibit a pattern of equidistant arrangement along the horizontal axis. Conversely, the presence of cracks in the vicinity of the bolt hole disrupts this equidistant channel distribution. Concerning the lower cracks of the bolt hole, they are categorized into two distinct formations, separated lower screw cracks and bonded lower screw cracks, which need numerical constraints. The contour moments are calculated by  
Figure 3: (a) Rail cross-section image. (b) Ultrasonic B-scan image in the corresponding area.  
\begin{table}
\begin{tabular}{c c} \hline \hline
**Rail Defects** & **B-Scan Image** \\ \hline \hline \multirow{2}{*}{
\begin{tabular}{c} crescent-shaped \\ fatigue cracks \\ \end{tabular} } & \\ \cline{2-2}  & \\ \cline{2-2}  & \\ \cline{2-2}  & \\ \cline{2-2}  & \\ \cline{2-2}  & \\ \cline{2-2}  & \\ \cline{2-2}  & \\ \cline{2-2}  & \\ \cline{2-2}  & \\ \cline{2-2}  & \\ \cline{2-2}  & \\ \cline{2-2}  & \\ \cline{2-2}  & \\ \hline \hline \end{tabular}
\end{table}
Table 3: The classification of rail defects and the representatives of B-scan images.  
integrating over all pixel points on the contour boundary. For a \(M\times N\) size of image, when its function is \(f(i,j)\), the calculation of \(p+q\) order geometric moment \(m_{pq}\) is as follows:  
\[m_{pq}=\sum_{i=1}^{M}\sum_{j=1}^{N}i^{p}j^{n}f(i,j) \tag{1}\]  
Then, calculate the 0 th-order moment and 1 st-order moment of \(m_{pq}\), respectively. When the image is a binary image, the 0 th-order moment gains the area of the image contour and the 1 st-order moment gains the coordinates of the center of gravity of the image (\(\bar{l}\), \(\bar{\jmath}\)). The specific calculation is as follows:  
\[m_{00}=\sum_{i=1}^{M}\sum_{j=1}^{N}f(i,j) \tag{2}\]  
\[m_{10}=\sum_{i=1}^{M}\sum_{j=1}^{N}i\cdot f(i,j) \tag{3}\]  
\[m_{01}=\sum_{i=1}^{M}\sum_{j=1}^{N}j\cdot f(i,j) \tag{4}\]  
\[\bar{\imath}=\frac{m_{10}}{m_{00}},\,\bar{\jmath}=\frac{m_{01}}{m_{00}} \tag{5}\]  
Based on contour features, the horizontal distance between the center of gravity of the upper crack channel and the center of gravity of the bolt hole channel is greater than its vertical distance, that is \(\Delta\bar{\imath}>\Delta\bar{\jmath}\). And the rule for lower crack is the opposite, that is \(\Delta\bar{\imath}<\Delta\bar{\jmath}\).