# Track Line Recognition Based on Morphological Thinning Algorithm +
## 3 Methods
### Improved ZS Thinning Algorithm  
The ZS thinning algorithm proposed by [PERSON] and [PERSON] [31] in 1984 is a very popular and fast parallel thinning algorithm [32; 33; 34; 35]; it has the advantages of fast speed, good connectivity, simple principles, etc., [36]. It involves the following basic definitions: a pixel at location (x, y) has two horizontal and two vertical neighbors. The set of four pixels, noted \(N_{4}(p)\), is called the 4-neighborhood of the pixel, as shown in Figure 6c. As is shown in Figure 6d, the four diagonal pixels, denoted \(N_{D}(p)\), represent the diagonal neighborhood of the pixel. The points of \(N_{4}(p)\) and \(N_{D}(p)\) together are called the 8-neighborhood of the pixel, as shown in Figure 6b. Figure 5: The result after adaptive threshold segmentation. Its function is to perform two iterations on the entire binary map in the \(3\times 3\) neighborhood boundary points that must be deleted by operation search. However, the thinning result cannot be guaranteed to be a single pixel; moreover, different degrees of noise exist, which affects recognition of the track line. Making full use of the advantages of the ZS thinning algorithm, we start by thinning into a single pixel and adapting to various complex scenes. An improved ZS thinning algorithm is proposed for track line detection. The specific process is as follows:  
Set the target point to 1 and the background point to 0. The algorithm performs the following operations on the boundary points:  
1. In the binary image obtained after the preprocessing described in Section 3.1, the algorithm looks for 8-neighborhoods centered on the boundary point, denotes the center point as P1, and the adjacent points in the clockwise direction as P2, P3,..., P9, where P2 is directly above P1, as shown in Figure 6a. Num(P1) represents the number of non-zero neighbors in P1's 8-neighborhood. \[\text{Num}(\text{P1})=\sum_{i=2}^{9}P_{i} \tag{10}\]  
S(P1) is the number of changes from 0 to 1 in the sequence P2, P3,..., P9, and the range is 0-4, which can be expressed in the following form. \[\text{S}(\text{P1})=\sum_{i=1}^{4}A_{i} \tag{11}\]  
\[A_{i}=\left\{ \begin{array}{c}1,\;\;P_{2i-1}=0\;\text{and}\;(P_{2i}=1\;\text{ or}\;P_{2i+1}=1)\\ 0,else\end{array} \right. \tag{12}\]  
The reason for the processing result of the ZS parallel thinning algorithm being a non-single pixel width is that there are pixels with an angle of \(90^{\circ}\), that is, existing points that are not deleted because they do not meet the conditions for deletion. Here, these points are defined as redundant points. The redundant points have four main directions, shown by the red dotted frames in Figure 7.  
Combining the four directions in which redundant points are generated, the specific reasons for their occurrence are analyzed in the 4-neighborhood. The number of non-zero neighbors in the 4-neighborhood of the central point P1. \[N_{(4)}=\sum_{i}^{9}P_{i}\;\;\;\;\;\;(i=2,4,6,8) \tag{13}\]  
Redundant points appear, \(N_{(4)}=2\). Express this in the form of a neighborhood template as, \"\" represents 0 or 1, as follows: \begin{tabular}{|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|} \hline
1 & 1 & 0 \\ \hline
* & 0 & 0 \\ \hline \end{tabular} \begin{tabular}{|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|} \hline
0 & 1 & 1 \\ \hline
0 & 0 & * \\ \hline \end{tabular} \begin{tabular}{|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|} \hline
* & 0 & 0 \\ \hline
0 & 1 & * \\ \hline \end{tabular} \begin{tabular}{|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|} \hline
0 & 0 & * \\ \hline
0 & 1 & * \\ \hline \end{tabular} \begin{tabular}{|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|p{28.5 pt}|} \hline
0 & 1 & * \\ \hline \end{tabular}