## 2 Three-Dimensional Object Segmentation and Labeling Algorithm
### Object Extension and Merge Algorithm  
After the distance connected component algorithm is implemented, most of the object contours have fragmented problems. Therefore, the object extension and merge algorithm is used to extend and connect the fragmented line segments of the same object contour to obtain a more complete object contour as the boundary of subsequent object segmentation. The object extension and merge algorithm is composed of isolated point connection, single-distance plane line segment extension, and cross-distance plane line segment extension. The isolated point connection is used to solve the fragmentation problem of line segments caused by isolated points, and other line segment fragmentation problems are solved in the other two steps. The isolated point connection places the result of the distance connected object on a 2D plane, fetches isolated points in sequence, and uses the isolated point as the center to find whether there are other objects in the adjacent points in the 3 \(\times\) 3 block. If there is only one adjacent point, the isolated point is located at the endpoint of the line segment and can be directly merged with the adjacent point. If there are two adjacent points, the isolated point is in the middle of the line segment or the overlapping area of different object contours. In this case, we need to determine the difference in distance between adjacent points. When the difference in distance of two adjacent points is less than _TH_dis_, the isolated point is merged with the two adjacent points. When the difference in distance is greater than _TH_dis_, the isolated point is deleted. As shown in Figure 7a, there are 1435 red points, which are isolated points. Figure 7b shows the result of isolated point connection, that is, 4073 objects are merged into 2663 objects. Subsequently, the single-distance plane line segment extension is processed to merge the fragmented line segments. The single-distance plane line segment extension mainly focuses on the line segments that are classified to the same distance plane and merges line segments that meet the extension connection condition. Before the processing, all objects should be arranged into planes with different distances based on the distance of objects. The minimum distance between the two endpoints of the line segment in each object is defined as the object distance. Therefore, objects with endpoints of the same minimum distance are classified into the same distance plane. Then, the line segment extension is processed for each distance plane in sequence. Because the object distances are calculated by Equation  
The single-distance plane line segment extension comprises three processing steps, extension object search, extension connection judgment, and overlapping object processing. The first step is extension object search. The extension object search is sequentially to search whether the line segment endpoints of each object have extension objects in the extension direction in the same distance plane. The extension direction refers to the direction of the vector from the endpoint through the adjacent point, which can be divided into eight directions, as shown in Figure 9. Searching the extended area of the perpendicular line at the endpoint of the extension direction. If no object exists, we do not perform the extension connection judgment but process the next object. If the object exists, these objects are defined as extension objects and perform the extension connection judgment. Figure 8: All objects in Figure 7b classified into different single-distance planes. (**a**) All distance planes; (**b**) Enlarged view of part of Plane 62. Figure 7: Isolated point connection. (**a**) Isolated points; (**b**) Result of isolated point connection. The second step is to perform extension connection judgment in which two characteristics of a line segment, the closure property, and color continuity, are used to determine whether to extend and connect the endpoints of two different objects.