# Track Line Recognition Based on Morphological Thinning Algorithm +
## 3 Methods  
### Image Preprocessing  
The image obtained by the sensor contains much invalid information, so it is necessary to preprocess the entire image and reduce the calculations. The preprocessing in our method includes two sections: histogram equalization and image threshold segmentation.  
When acquiring images by camera, factors such as uneven illumination and environmental noise affect the final image quality. The necessary image-enhancement process is conducive to improving the image effect. Since image enhancement refers to the degraded image features, it can process the edges, contours and contrast to improve the visual effect of the image, thereby improving the clarity of the image, highlighting the effective information in the image, compressing the invalid information and transforming the image into a form more suitable for human or computer analysis and processing. A basic algorithm in image-enhancement processing, histogram equalization is simple in principle, mature in technology, and can significantly improve image quality. The essence of histogram equalization is to perform non-linear stretching on an image with uneven pixel distribution, redistribute the pixel values of the image, and finally evenly distribute the pixel values in the entire grayscale range. In this paper, we use the method of global histogram equalization. The original image is shown in Figure 3 and the processing effect is shown in Figure 4.  
Image threshold segmentation is a widely used segmentation technique in image processing. It uses the difference in grayscale characteristics of the target area to be extracted from the image and its background to treat the image as a combination of two types of areas with different grayscale levels. It is reasonable to choose one threshold to determine whether each pixel in the image should belong to the target or the background, thus generating a corresponding binary image. Considering that the scene studied in this paper is complex and changeable, the target and background will change greatly; as a result, a single fixed threshold poses great limitations. In this paper, we use the adaptive threshold method, in which the optimal threshold should be adaptively generated according to each image frame. In this method, we iterate through different thresholds and calculate the intraclass variance between background and target for different thresholds. When the intraclass variance is maximized, the corresponding threshold will be the desired threshold [30]. The calculation process is as follows:  
Assume that the gray range of threshold \(t\) is 0, 1, 2..., \(L-1\), and let the probability \(S_{i}\) of pixels with gray level \(i\) be:  
\[S_{i}=\frac{n_{i}}{N} \tag{3}\]  
\[\sum_{i=1}^{L-1}S_{i}=1 \tag{4}\]  
The probability value of the target is:  
\[\omega_{0}(t)=\sum_{i=0}^{t}S_{i} \tag{5}\]  
The mean value of target is:  
\[\mu_{0}(t)=\sum_{i=0}^{t}\frac{iS_{i}}{\omega_{0}} \tag{6}\]  
The probability value of the background is:  
\[\omega_{1}(t)=\sum_{i=t+1}^{L-1}S_{i} \tag{7}\]  
Figure 4: (**a**) presents the image of histogram equalization effect and (**b**) shows gray histogram image of freight track.  
Figure 3: (**a**) presents the original image of freight track and (**b**) shows the gray histogram image of freight track.  
The mean value of background is:  
\[\mu_{1}(t)=\sum_{i=t+1}^{L-1}\frac{iS_{i}}{\omega_{1}} \tag{8}\]  
The intraclass variance value is:  
\[f(t)=\omega_{0}(t)\omega_{1}(t)(\mu_{0}(t)-\mu_{1}(t))^{2} \tag{9}\]  
Traverse all the thresholds and find the corresponding \(t\) value that maximizes the intraclass \(f(t)\), which is the threshold required. The effect of the adaptive threshold method after the histogram equalization in Figure 4 is shown in Figure 5.