## 2 Methods
### Acquisition of Crack Defect Candidate Regions
#### 2.1.2 Gaussian Similarity Measure  
In the fluorescent magnetic particle inspection images of bearing rings, there are some false indications caused by the accumulation of magnetic particles at the edge or groove of the workpiece. The false indications and cracks have similar linear structural characteristics and obtain the centerline by the Steger algorithm. To suppress the interference of false indications in the process of crack extraction, we analyze the greyscale distribution property of cracks. In the normal direction of the local area of the crack, the curve of grey levels is similar to the Gaussian curve, as shown in Figure 3.  
To fit the greyscale distribution of cracks in the normal direction, a Gaussian curve \(g(x)\) is defined as follows:  
\[g(x)=a\cdot e^{\frac{-x^{2}}{2\omega^{2}}}+b\hskip 14.226378 ptx\in R \tag{10}\]  
Figure 3: The greyscale distribution curves of crack defects in the normal direction. In Equation (10), \(b\) represents the vertical offset of the Gaussian curve, which is equal to the average greyscale of the crack. As a rule of thumb, we set \(b\) to 90 in this work. \(a+b\) is the maximum value of the curve and \(a\) is defined as follows:  
\[a=\frac{800}{\sigma\cdot\sqrt{2\pi}} \tag{11}\]  
According to the above characteristics, the 9 \(\times\) 3 sliding window is designed to obtain the normal greyscale distribution of the centerline obtained by the Steger algorithm, as shown in Figure 4. The greyscale values in the tangent direction of the crack basically remained unchanged, while the change in the normal direction followed Gaussian variation. Therefore, we assign values to the sliding window according to these characteristics. The sliding window is divided into three rows, \(l_{1}\), \(l_{2}\), \(l_{3}\), and the value distribution of each row follows the variation of \(g(x)\). The sliding window traversed all pixels of the extracted centerline in inspection images, and the y-axis (vertical direction) of the window is rotated to coincide with the e2 direction (tangent direction of the extracted centerline). Then, we compare all pixel values in the mask region and the corresponding values in the sliding window before obtaining their cosine similarity. The Gaussian similarity of the regions is measured using cosine similarity by calculating the cosine value of the angle between two vectors. The closer the cosine value is to 1, the closer the angle \(\theta\) is to 0, and the more similar the two vectors are. The cosine similarity \(C_{i}\) between the vector \(g_{i}\) in the row (\(i\)) of the sliding window and the corresponding vector \(h_{i}\) in the image is calculated as follows:  
\[C_{i}=\cos(\theta)=\frac{\sum\limits_{i=1}^{n}{(g_{i}*h_{i})}}{\sqrt{\sum \limits_{i=1}^{n}{(g_{i})^{2}*\sqrt{\sum\limits_{i=1}^{n}{(h_{i})^{2}}}}}} \tag{12}\]  
where \(g_{i}\) is the value of each coordinate point in one row of the sliding window and \(h_{i}\) is the greyscale value of the corresponding pixel in the original image. After calculating the similarity between the three linear vectors of the sliding window and the greyscale value vector of the original image corresponding to the window. The Gaussian similarity \(GS\) is obtained by weighted average, which is calculated as follows:  
\[GS=\frac{C_{1}+C_{2}+C_{3}}{3},GS\in[0,1] \tag{13}\]  
We reserve the pixels whose Gaussian similarity \(GS\) is smaller than the threshold that we set. After this operation, the centerline display caused by the accumulation of magnetic particles at the edge or groove of the workpiece can be effectively removed. As shown in  
Figure 4: Structure of the sliding window. Figure 5, the centerline result in Figure 5b is obtained by the Steger algorithm. Figure 5c show the results after using the Gaussian similarity measure. It can be seen that most of the centerline results caused by the false indications are removed. Then, we take the maximum bounding rectangles of connected regions in the image and merge the adjacent bounding rectangles.