## 2 Three-Dimensional Object Segmentation and Labeling Algorithm
### Distance Connected Component Algorithm  
Because the edge image detected after being processed by TCEDA is pixel-wise information, the adjacent connected pixels should be labeled as the same line segment to obtain contour information of each line segment. Currently, the connected component labeling algorithm is the most widely used object labeling method. When objects with different distances overlap within the image, the connected objects will be labeled incorrectly owing to the adjacency edge pixels of the overlapping objects, and different overlapping objects will be labeled as the same object. Therefore, this paper proposes a distance connected component algorithm that combines the distance information of stereo vision and the characteristic of adjacent pixels and uses 3D information to label the edge image with different distances as different objects, thereby solving the labeling problem of overlapping objects. The distance connected component algorithm is mainly divided into three steps--distance calculation, ground edge contour removal, and distance object labeling. During distance calculation, the edge pixels of the edge image are used as the processing pixels, and the image matching method is used to compare the displacement between \(I_{R}\) and \(I_{L}\), and calculate the disparity value which represents the distance to the camera. The larger  
Figure 2: Detection result of edge contours of Test image 1 processed by TCEDA. **(a)** The compared image; **(b)** The processing image; **(c)** Edge image of the processing image. the disparity value, the closer the distance to the camera; the opposite is true. As shown in Figure 3, we assume that there is a point \(P\) in the space, and its positions in the images of the left and right cameras are \(P_{I}\left(u_{l},v_{l}\right)\) and \(P_{r}\left(u_{r},v_{r}\right)\), respectively. The disparity value \(d\) can be obtained using Equation (1). Subsequently, the distance to the camera can be calculated using Equation (2), where \(Z\) is the distance from point \(P\) to the camera, \(B\) is the distance between the two cameras, and \(f\) is the focal length. \[d=u_{l}-u_{r} \tag{1}\]  
\[Z=\frac{\text{B}f}{d} \tag{2}\]  
The block matching method is commonly used for image comparison. It calculates the difference in the gray level or color of the images in the two blocks within the search area. The smaller the difference, the higher the similarity between the two blocks. However, the images captured by different cameras are different in brightness and color, thereby affecting the accuracy of block matching. Therefore, this paper proposes a gradient weight comparison method, which replaces the pixel value with the gradient amplitude, and assigns different weights \(\rho\) to the edge and non-edge pixels to improve the accuracy of block matching. Each edge pixel in the edge image of \(I_{R}\) is defined as the center point and extends a block image of \(n\times n\) pixels. The difference in gradient amplitude \(GD(u^{\prime},v^{\prime})\) of each matched block in the search area \(SA\) of \(I_{L}\) is calculated in sequence, as shown in Equation (3), where \(G_{R}(x,y)\) and \(G_{L}(x,y)\) are the gradient values of each pixel in \(I_{R}\) and \(I_{L}\), respectively, the weight value of the edge pixels is 5, and the weight value of other pixels is 1. As shown in Equation (4), we identify the displacement coordinates \((u,v)\) with the smallest weighted gradient amplitude difference in the search area. Then, we use Equations (1) and (2) to calculate \(d\) and \(Z\), respectively. \[\text{GD}(u^{\prime},v^{\prime})=\sum_{j=0}^{n-1}\sum_{i=0}^{n-1}\rho\times \left|G_{R}(x+i,y+j)-G_{L}(x+u^{\prime}+i,y+v^{\prime}+j)\right| \tag{3}\]  
\[(u,v)=\arg\min_{(u^{\prime},v^{\prime})\in SA}\text{GD}(u^{\prime},v^{\prime}) \tag{4}\]  
where \(\rho= \begin{cases}5,&\text{if}G_{R}(x+i,y+j)\ \in\text{edge pixel}\\ 1,&\text{if}G_{R}(x+i,y+j)\ \
otin\text{edge pixel}\end{cases}