## 3 Approach
### Rail Track Topology Reconstruction
#### 3.2.2 Railway Track Correction and Clustering  
The semantic segmentation results after orthogonal projection are first screened initially to retain the valid key points. After the momentum tracking method proposed in this paper, the key points in the orthogonal map are connected as rail track lines and, based on the fitted curve, the railway line points can be clustered. In this paper, the distribution of a single railway track into left and right tracks is defined as _L1_ and _L2_. If there are branching points, additional branches are defined such as _L3_, _L4_, and so forth. As shown in Figure 6, the orthogonal map result is first edge-detected [39] to find the left and right boundaries of the railway track lines. Specifically, the orthogonal image should be denoted as \(O(u,v)\). Gaussian smoothing should be performed on it as shown in Equation (4), resulting in the smoothed image \(G(u,v)\). \[G(u,v)=\frac{1}{2\pi\sigma^{2}}e^{-\frac{u^{2}+v^{2}}{2\sigma^{2}}}\times O(u,v) \tag{4}\]  
On the smoothed image, compute the gradients in the horizontal and vertical directions using the Sobel operator. The formula for computing the gradient is Equations (5) and (6) as follows:  
\[G_{u}=O(u+1,v)-O(u-1,v) \tag{5}\]  
\[G_{v}=O(u,v+1)-O(u,v-1) \tag{6}\]  
where \(G_{u}\) and \(G_{v}\) are the gradients in the horizontal and vertical directions, respectively. Then, compute the magnitude and direction of the gradient using Equations (7) and (8):  
\[M(u,v)=\sqrt{G_{u}^{2}+G_{v}^{2}} \tag{7}\]  
\[\theta(u,v)=\arctan(\frac{G_{x}}{G_{y}}) \tag{8}\]  
Figure 6: The orthogonal projection map of railway track pixels undergoes edge detection. Subsequently, each row is scanned to determine if the number of key points in the current row is valid. Key points from valid rows are retained as candidate points, while points from invalid rows are discarded. where \(M(u,v)\) is the magnitude of the gradient and \(\theta(u,v)\) is the direction of the gradient. For the gradient magnitude image, retain pixels with local maximum gradients and suppress non-maximum values. Then, determine which edge pixels are true edges by setting high and low thresholds. Pixels above the high threshold are considered strong edge pixels, while pixels connected to strong edge pixels but below the low threshold are considered weak edge pixels. By performing edge tracking, convert weak edge pixels to strong edge pixels to obtain the final edge image [40]. Based on Characteristic 2, a set of railway tracks can be conceptualized as two parallel lines. In other words, within a reasonable distance, a pair of railway tracks are parallel and coplanar. Therefore, when the semantic map is projected onto the bird's eye view (BEV) perspective, a true pair of railway tracks should have four edge points. This holds true even in the presence of switches where the number of edge points remains a multiple of 4. Based on the analysis above, we can conduct a row-by-row search on orthographic images to identify the correct railway track points. When scanning boundary points row by row, a rail line pair can be found with two boundary points in a single row. Therefore, in one row of the orthographic image, a pair of railway tracks should have four edge points. The initial coarse screening process involves removing boundary points from the railway track that are not equal to four or multiples of four within the same row. Through this approach, we retain valid track points for each row in the orthographic image. For rows deemed invalid, we discard all track points within that row. While this may result in a certain degree of information loss, subsequent techniques such as curve fitting compensate for this loss. Empirical evidence suggests that the lost information does not significantly affect the experimental results. The initial coarse screening process involves removing boundary points from the railway track that are not equal to four or multiples of four within the same row. Figure 7 illustrates this screening process.