## 2 Materials and Methods
### Wear Measurement Algorithm for the Contact Strip
#### 2.3.2 Image Processing for Wear Measurement  
The target image is preprocessed before extracting the edge pixels. The noise in the acquired image is removed by applying a Gaussian filter represented by Equation (1) to improve the distribution of the grey level on the image [21]. Here, \(x\) is a horizontal coordinate, \(y\) is a vertical coordinate, \(\mu\) refers to an average for \(\sigma\), and \(\sigma\) refers to a standard deviation for smoothing the image by Equation (1). If \(\mu\) of each coordinate equals zero, \(\sigma\) of each coordinate equals \(\sigma\). Pixels are accurately extracted for edge detection according to \(\sigma\) because the decrease of \(\sigma\) results in a smaller standard deviation difference in a Gaussian distribution. The \(\sigma\) is fixed at 1 in this study. \[G_{\sigma}(x,y)=\frac{1}{2\pi\sigma^{2}}e^{-(\frac{x^{2}+y^{2}}{2\sigma^{2}})} \ \ \left\{ \begin{array}{l}\mu_{x}=\mu_{y}=0\\ \sigma_{x}=\sigma_{y}=\sigma\end{array} \right\} \tag{1}\]  
After applying the Gaussian filter, the top-hat transformation is used to brighten the white pixels of the laser line by Equation (2). This is derived by commuting images and structuring elements with the opening operator. Here, \(f\) is original image and \(b\) is a structuring element. The preprocessed image shows two laser lines included in white pixels as shown Figure 11. The top laser line, which is an area contrasted with the background, is selected for edge detection. \[T_{hat}(f)=f-(f\ \circ\ b) \tag{2}\]  
The local processing method for the linking edge is applied, considering simple pixels for edge detection using Open eVision library [22]. Local processing computes the pixels and angles of the vectorized images. The pixel compares the difference between the coordinates of the edge pixel (\(s\),\(t\)) and the coordinates (\(x\),\(y\)) around the edge with the threshold value (E) as shown in  
Figure 11: Extraction of top laser line on the acquired image of the contact strip. Figure 10: Detection of pantograph contact strip from R-CNN. is compared with the threshold value (A) in the same way as the size, as in Equation (4), to determine the edge direction. \[\left|M(s,t)-M(x,y)\right|\leq E \tag{3}\]  
\[\left|\alpha(s,t)-\alpha(x,y)\right|\leq A \tag{4}\]  
The size and angle of the image increases the computation since all neighboring pixels of the image must be considered. For this, the area processing is organized as in Equation (5), and the g (x,y) of edge detection is divided into 0 or 1 as a binary image. Here, T\({}_{\text{M}}\) is the threshold value of the magnitude, and T\({}_{\text{A}}\) is the error range of the angle. In this study, the image of the contact strip is converted into a binary image of 0 and 255. \[g(x,y)=\left\{ \begin{array}{ll}1&if\ M(x,y)\ >T_{M}AND\ \alpha(x,y)=A\ \pm T_{A}\\ 0&otherwise\end{array} \right\} \tag{5}\]  
The fitted line is extracted by applying the least squares method based on Equation (6) for comparison with the laser line. This method determines the parameter of the estimation function by minimizing the residual sum of squares, which represents the error between the laser line and the fitted line of the estimation function. Here, the laser line is the measured edge on the image and the estimation function is the polynomial. The laser line is derived as an estimate from the polynomial and fitted into a curve. In Equation (6), \(y_{i}\) represents the pixel value of the laser line obtained from the acquired image and \(x_{i}\) is the estimation data based on the pixels of the laser line through the polynomial. \(f(x_{i})\) is the polynomial function of \(x_{i}\) and \(r_{1}\) is the edge of the fitted line from the difference between the measured value (laser line) and the estimated value (polynomial function). \(A\) fitted line is the result of minimizing the squared difference value by subtracting the edge pixel of the laser and the estimated data.