## 3 Approach
### Rail Track Topology Reconstruction
#### 3.2.2 Railway Track Correction and Clustering
Then, it selects the inner boundary points of the railway track as the candidate points for fitting. Following the coarse screening, points in the central region of the lower part of the orthogonal image are chosen as initial points. These points are theoretically positioned directly beneath the train and represent the area the train is about to traverse. The majority of these initial points are utilized to ascertain the number of tracks. For instance, if the majority of initial points in each row is four, it can be assumed that the train does not pass the switch ahead of it. When the train passes a switch, the majority of the initial points are eight. The key points of the first 100 rows of the graph are chosen as the initial points in this paper, as shown in Figure 7.  
Figure 7: The railway points in the orthogonal map are roughly segmented. Then, points from the region closer to the locomotive (lower part of the map) are designated as the initial confidence region. The initial clustering of key points is determined within this region. Subsequently, classification is predicted row by row to determine the clustering of each candidate point. Since it is not known which switch the train will be heading to, the track area for both teams of tracks needs to be calculated. Once the number of tracks has been determined using the initial points, a polynomial fit to the inner boundary of each pair of tracks is selected as an abstraction of the initial rail track alignment. After generating prediction points for the next row, the method calculates the distance between each candidate point and the corresponding prediction point. If the minimum distance falls below the threshold, the candidate point is categorized as belonging to that track; otherwise, it is disregarded. This process is outlined in Algorithm 1 and Figure 7.  
```
Input: \(p(u,v)\): Pixel set of railway tracks under orthogonal map \(H_{init}\): Number of rows for preset initial confidence points Output: \(I_{j}^{\mathcal{M}}\): Point set of railway track lines, where \(i\) is the number of rail lines. ``` for\(i=1\) to \(H_{init}\) do  (1) \(P_{i}=\) iterative filter key points in row i  (2) \(P_{L_{j}v}=\{p\in P_{i}||p\text{mod}4|=0\}\)  end  //Determine the initial confidence region's location on a single rail line or a diverging track based on the filtering results. (3) if (singleRailLine) { allocateToL1 toL2 (\(P_{i,v}[:100,0],P_{L_{v}}[:100,1]\)) } else if (divergingTrack)  allocateToL1 toL4 (\(P_{L_{v}[:100,0],P_{L_{v}}[:100,1],P_{L_{v}}[:100,2],P_{L_{v}}[:100,3]\)) } for \(i\) to the num of rails do  for \(j=1\) to \(H_{init}\) do  //Least squares fitting (4) \(F(u_{Lij})=\underset{\theta_{0}\theta_{1}}{\min}\sum\limits_{j=1}^{j}(v_{Lij}-( \theta_{0}+\theta_{1}u_{Lij}+\theta_{2}u_{Lij}^{2}))\) //Predict the key points of the next row based on the existing polynomial and add the maximum likelihood point to the existing rail line key points set. (5) \(L_{i}\)= update_clusters (\(L_{i}P_{j+1}\))  //Update the parametric equations for each rail lines. (6) \(F(u_{Lij})=\underset{\theta_{0}\theta_{1}}{\min}\sum\limits_{j=1}^{j+1}(v_{Lij +1})-(\theta_{0}+\theta_{1}u_{Lij(j+1)}+\theta_{2}u_{Lij(j+1)}^{2}))\) end (7) //Convert pixel coordinates to 3D coordinates based on the geometric information from the orthogonal range map. \(L_{j}^{\mathcal{M}}\)= projection (\(L_{j}^{\mathcal{M}}\)) Return \(L_{j}^{\mathcal{M}}\) ```  
**Algorithm 1**Railway Points Selection and Reconstruction