# The Identification and Assessment of Rail Corrugation Based on Computer Vision
## 3 Rail Corrugation Identification Based on Improved SPM Model
### Rail Head Surface Localization  
The rail images collected from the field usually contain irrelevant components such as fasteners, sleepers and subgrade on both sides of the track, which would cause unnecessary interference. Therefore, the exact rail head surface area should be first extracted to reduce this interference. It is observed that the gray level of the rail area is mainly continuous along the longitudinal direction of the rail, while in the other non-rail regions, the gray scale of the pixels has apparent discontinuity both on the horizontal and vertical direction. And, along with the transverse direction, there are distinct gray scale discontinuities between the rail area and the other regions. Furthermore, the rail is usually located in the middle of the obtained rail image.  
Based on these observations, the vertical edge of the rail image is enhanced by using horizontal gradient operator to highlight gray level change along the horizontal direction and sharpen the boundaries of the rail head surface. From Reference [35], the operator templates used in this paper are stated as follows  
\[p=\left[\begin{array}{ccc}-1&2&-1\\ -2&4&-2\\ -1&2&-1\end{array}\right],q=\left[\begin{array}{ccc}-1&0&1\\ -2&0&2\\ -1&0&1\end{array}\right] \tag{5}\]  
hence, the enhanced rail image \(E(x,y)\) is computed as  
\[E(x,y)=|p*O(x,y)|+|q*O(x,y)| \tag{6}\]  
Figure 2: The procedure of the two-stage image pre-processing method. (**a**) original image; (**b**) image de-noised by bilateral filter; (**c**) illumination extraction result; (**d**) corrected image of the proposed two-stage method.  
where \((x,y)\) denote the pixel coordinates. \(O(x,y)\) is the corrected rail image. \(*\) represents the convolution operation.  
The enhanced rail boundaries indicate significant gradient information along the transversal direction, as shown in Figure 3b. Therefore, the horizontal gradient for each pixel of the enhanced rail image is first computed and then the sum of gradient value (SG) for each column of the rail image is calculated, the SG is defined as  
\[SG(y)=\sum_{x=1}^{h}grad(x,y),y=1,2,...,w. \tag{7}\]  
where \(w\) and \(h\) stand for the width and height of the rail image, respectively. \(grad(x,y)\) represent the gradient value at the coordinates \((x,y)\).  
Subsequently, in terms of the horizontal position of each column in the rail image, the SG is further multiplied with an adaptive weight. The adaptive weight \(AW(y)\) of position \(y\) is defined as  
\[AW(y)=\frac{1}{\sqrt{2\pi}\sigma}e^{-\frac{(y-y)^{2}}{2\sigma^{2}}},y=1,2,...,w. \tag{8}\]  
where \(\mu\) is set with \(w/2\) in this study. Therefore, the weighted gradient SUM value is computed as  
\[WG(y)=SG(y)\times AW(y),y=1,2,...,w. \tag{9}\]  
Finally, a weighted gradient projection profile for rail locating is formed by using all of these values. In the light of practical experience, when the setup of image acquisition equipment is fixed, the rail width \(w_{r}\) in a rail image will be a constant. Therefore, the starting position of the rail is obtained based on the following rules [15]  
\[p_{r}=\arg\max_{x}SWG(y),y=1,2,...,w-w_{r}. \tag{10}\]  
with the sum of weighted gradient value  
\[SWG(y)=\sum_{i=y}^{i+w_{r}-1}WG(i) \tag{11}\]  
Figure 3: The process diagram of rail surface localization method. (**a**) original corrected image; (**b**) image processed by vertical edge enhanced; (**c**) the result of calculating weighted gradient sum value; (**d**) the result of rail surface localization.  
where \(y\) stands for the starting position with the length of \(w_{r}\) and then the exact rail location would be determined by them. The procedure of rail surface localization is shown as in Figure 3. Brief pseudocode about the method for rail surface localization is described in Appendix A.