## 3 Spiral Rail Spike Positioning Method
### Positioning Road Studs Through Shape Features  
As shown in Figure 5, the pink circles represent the visualization of the circular fitting results using the least squares, and the red circles represent the visualization of the circular fitting results using the gradient Hough transform, compared with the gradient Hough transform [18], the least squares circle fitting [19] requires more complex calculations, and the detection effect is not good when facing the railway environment. Therefore, after completing the image edge detection work, the gradient Hough transform is used for circle fitting processing to determine the center coordinates and corresponding radii of all the circular regions of the spiral rail spikes to be screened. Standard image features include texture [20] and shape [21]. Considering that the gradient Hough transform mainly relies on the gradient line intersection of the edge features for cumulative calculation, the non-spike interferent of the edge feature circle, such as ballast, can easily be mistakenly identified as a circle meeting the detection radius range and its surface features are very similar to spikes. Hence, it is not easy to distinguish them by texture features. Compared with the texture feature, its shape feature is not affected by various interference on the spot, and it is more stable and can be described. HOG feature [22; 23] is an image feature description method. Its essence is the distribution statistics of gradient information in the image, which can capture the local shape of the image well. Compared with other feature representations, HOG is not sensitive to the illumination and geometric changes in the image and has higher detection accuracy and stability. Therefore, after circle fitting, HOG features are used to describe the shape of the area to be screened, and finally, the area most similar to the shape features of the standard spike template can be determined as the spike area. The steps of HOG feature extraction are as follows:  
Figure 5: Fitting results of two methods for circles: (**a**) least squares; (**b**) gradient Hough transform. * As shown in formula (9), the gradient magnitude and gradient direction are calculated. \[\left\{ \begin{array}{l}G_{x}(x,y)=H(x+1,y)-H(x-1,y)\\ G_{y}(x,y)=H(x,y+1)-H(x,y-1)\\ G_{hog}(x,y)=\sqrt{G_{x}(x,y)^{2}+G_{y}(x,y)^{2}}\\ \alpha_{hog}(x,y)=\arctan(G_{y}(x,y)/G_{x}(x,y))\\ \end{array} \right.\] (9)  
In the formula, \(G_{x}\) and \(G_{y}\) represent the horizontal gradient and vertical gradient of the pixel at point \((x,y)\), respectively, while \(G_{hog}\) and \(\alpha_{hog}\) represent the gradient magnitude and gradient direction of the pixel at point \((x,y)\), respectively. We then take the following steps:  
* Calculate the gradient histogram. Divide the image into several cells, with each cell being 10 \(\times\) 10 pixels in size. Meanwhile, quantize the gradient directions into 9 bins. Accumulate the gradient magnitudes of the pixels in the quantized gradient directions to describe each cell with a nine-dimensional vector, thereby obtaining the gradient histogram. * Block normalization. A Block is composed of \(2\times 2\) cells, resulting in a \(2\times 2\times 9\)-dimensional feature vector. To prevent excessive variation in gradient intensity, the Block is normalized using the L2 norm. * Calculate the HOG feature vector. With a scanning step size of 10 pixels, for example, in a region of size 100 pixels \(\times\) 100 pixels, the dimension of the HOG feature vector is calculated as shown in formula (10): \[(\frac{100}{10}-1)\times(\frac{100}{10}-1)\times 2\times 2\times 9=2916\] (10)  
The final output of HOG feature extraction is a vector, so the similarity measurement of the HOG feature can be transformed into the similarity measurement of vectors. This paper uses the standard Euclidean distance (SED) of two feature vectors to measure their similarity, and spike region screening is realized. The smaller the SED value, the more similar the two vectors, and vice versa.