## 2 Research Methodology
### Point Cloud Contrustion and Pre-Processing
#### 2.2.2 Object Segmentation  
After the scene point cloud has been created and processed by the pass-through filter, statistical outlier removal filter, and voxel grid filter to achieve the proper view of the region of interest, the object's point cloud will be segmented from the scene point cloud by combining the random sample consensus (RANSAC) [11] and the Euclidean cluster extraction algorithms [12].  
The RANSAC Algorithm 1 is a learning technique to estimate the parameters of a model by random sampling of inspected data. RANSAC utilizes the voting scheme to estimate the optimal appropriate result of a processing dataset in which data components carry both inliers and outliers. Data components in the dataset are used to determine one or multiple models. In this study, the RANSAC algorithm was utilized to determine the plane model, and the following will illustrate its pseudocode.  
```
Input: Point cloud and model estimation. Output: Plane Model \(M\), which was rated best amongst all iterations  While (\(i\leq maxIterations\)) do  Sample \(k\) points;  Estimate a plane model \(M\);  Compute model inliers;  If (\(M\) is better than bestModel) then \(MbestModel\); \(updateMaxIteration()\);  End if; \(ii+1\);  End while;  Return bestModel
```  
**Algorithm 1** RANSAC algorithm to find plane model  
The target workpiece is placed on a worktable. In order to extract the point cloud of the target object, a worktable plane is required to be removed from the scene. After inputting the point cloud data, the plane model is estimated by applying RANSAC; then, the plane inliers are eliminated from the input cloud data [13].  
To achieve the object extraction, a method called clustering classification is applied. A simple and powerful data clustering approach in the Euclidean sense can be executed using an octree data structure. This algorithm will calculate the minimum distance between points and divide the point cloud data into clusters by setting the distance threshold. The cluster definition formula is as follows:  
\[min\big{|}p_{i}-p_{j}\big{|}\geq d_{th} \tag{14}\]  
where \(p_{i}\) is the \(i\) point cloud data, \(p_{j}\) is the \(j\) point cloud data, and \(d_{th}\) is the distance threshold. The distance between points is searched through the Nearest Neighbor Search (NNS) in the K-Dimension Tree (KD-Tree) [14], and the Euclidean cluster extraction algorithm is defined as follows Algorithm 2.  
```
Input: Point cloud data \(P\). Output: Point cloud clusters \(C_{i}\varnothing\); // list of clusters \(Q\varnothing\); // list of checked points  While (\(p_{i}\in P\)) do \(p_{i}\rightarrow\mathcal{Q}\);  While (\(p_{i}\in\mathcal{Q}\)) do  If (\(r_{p_{i}}<d_{th}\)) then \(p_{k}\to p_{k}\);  End if;  While (\(p_{k}\in P_{k}\))  If (\(p_{k}\) has not been processed) then \(p_{k}\rightarrow\mathcal{Q}\);  End if;  End while;  If (all points \(p_{i}\in Q\) are processed) then \(C_{i}\mathcal{Q}\); \(Q\varnothing\);  End if;  End while  End while
```  
**Algorithm 2** Euclidean cluster extraction algorithm to extract the workpiece point cloud  
```
Input: Point cloud data \(P\). Output: Point cloud clusters \(C_{i}\). \(C_{i}\varnothing\); // list of clusters \(Q\varnothing\); // list of checked points  While (\(p_{i}\in P\)) do \(p_{i}\rightarrow\mathcal{Q}\);  While (\(p_{i}\in\mathcal{Q}\)) do  If (\(r_{p_{i}}<d_{th}\)) then \(p_{k}\to p_{k}\);  End if;  While (\(p_{k}\in P_{k}\))  If (\(p_{k}\) has not been processed) then \(p_{k}\rightarrow\mathcal{Q}\);  End if;  End while;  End while;  If (all points \(p_{i}\in Q\) are processed) then \(C_{i}\mathcal{Q}\); \(Q\varnothing\);  End if;  End while  End while
```  
**Algorithm 3** RANSAC algorithm to find plane model  
After processing through the above steps, the original point cloud model can be clustered, and according to the threshold value, the target object from the scene can be obtained to be input in the pose estimation program. Figure 4 will demonstrate the effect as well as the steps of object segmentation in this study.