# Track Line Recognition Based on Morphological Thinning Algorithm +
## 3 Methods
### Denoising Algorithm  
The image obtained by the improved ZS thinning algorithm does not only include the track line, but also the interference from the factors beside the track, such as gravel, sleepers, gully fences, etc. Denoising must, therefore, be conducted to obtain the best track line. In this paper, a contour-based denoising method is proposed. According to the topology and distribution of the contour, the width, height and area of the contour are calculated using the minimum circumscribed rectangle. We then judge whether the contour is the boundary of the track profile we are looking for by the height, width and area of the minimum bounding rectangle of the contour, as shown in Figure 11.  
Figure 10: The result of freight railway after improved ZS algorithm processing. (**a**) is a multiple sets of straight track lines, (**b**) is curves with a small curvature track lines, (**c**) is the curved with a large curvature track line, (**d**) is the multiple turnout track lines. Figure 9: Single pixel rendering after macro-magnification. (**a**,**c**) is the original refinement results with the overlapping pixels, (**b**,**d**) is corresponding the refinement results for a single pixel. where \(\theta\) is the included angle between the counterclockwise rotation of the horizontal axis and the first side of the encountered rectangle. The side length is width, and the top and bottom sides are height. The thinned image is \(I_{1}\), imgW and imgH are the width and height of the original image, W and H are the width and height of the minimum circumscribed rectangle, T represents the width-height ratio of the minimum circumscribed rectangle, the length is L, and S represents the area. \[T=W/H\;\;W\in(0,imgW),H\in(0,imgH) \tag{17}\]  
\[L=Max\{W,H\}\;W\in(0,imgW),H\in(0,imgH) \tag{18}\]  
\[S=W*H\;\;W\in(0,imgW),H\in(0,imgH) \tag{19}\]  
The specific process is as follows:  
1. According to the length and area differences in track profile and side interference, find the minimum circumscribed rectangle of all profiles in \(I_{1}\), as shown in Figure 12a. The blue parts in the figure represent the generated rectangular boxes. It can be seen from the figure that there are various large and small rectangular boxes. By setting the threshold, we screen out the rectangular boxes that meet the conditions, and all the pixel values in the rectangular boxes in this part will be retained; the remaining pixels are then set to zero. This method can eliminate most noise points. The specific steps are as follows: The length of each minimum circumscribed rectangle in \(I_{1}\) is \(L_{i}\). If \(L_{i}\) is less than the threshold parameter \(\lambda 1\), all pixels in its domain are set to 0. If it is larger than the parameter, the first \(\lambda 2\) bits are reserved in order from large to small. Many experiments demonstrated that most noise points can be eliminated when \(\lambda 1\in(40,50)\) and \(\lambda 2\in(12,15)\), and the processed image is recorded as \(I_{2}\). 2. Morphological dilation is performed on \(I_{2}\) using 3 \(\times\) 3 structural elements to eliminate small patches, holes, small discontinuities, etc. The processed result is recorded as \(I_{3}\). 3. Remember that \(\lambda\) is the length-screening coefficient of the minimum circumscribed rectangle, and \(\delta\) is the area-screening coefficient of the minimum circumscribed rectangle. According to the geometric properties of image \(I_{3}\), a filtering rule is defined:  
Figure 11: Schematic diagram of minimum circumscribed rectangle. When the height, width and area of the minimum bounding rectangle of a contour do not meet the formula, the contour is excluded (all pixels in the contour are set to 0). After screening the length and area coefficients, the complete track area is finally obtained. The experimental results show that when \(\lambda\in\) (400, 500) and \(\delta\in\) (1400, 1600), the denoising effect is significant. \[\left\{ \begin{array}{l}\lambda<W<\text{imgW}\\ \lambda<H<\text{imgH}\end{array}