The improved KMeans point cloud clustering algorithm calculates the point density based on the number of points in the voxel, and obtains the top K voxels with the highest point density as the initial clustering center (matlab code attached)

The main logic of the KMeans function is as follows:

  • The cluster center is initialized using the InitCenter function, which selects the initial cluster center based on voxel density. The input parameters of this function include data (data), the number of cluster centers (centerNum) and the number of voxels (voxelNum).
  • Calculate the volume (V) and voxel side length (d) of the bounding box based on the value range of the point cloud.
  • Divide the point cloud data into voxels according to the voxel side length, and record the point set and point number of each voxel.
  • Calculate the point density based on the number of points in the voxel, and obtain the top K voxels with the highest point density as the initial clustering center.
  • The initial clustering center is iteratively optimized until the clustering center no longer changes or the maximum number of iterations is reached. In each iteration, each point is assigned to the nearest cluster center and the new cluster center position is calculated.
  • Returns the final clustering results (clusters) and cluster center positions (centers).
  • Next, the code plots the clustering results in a 3D graphics window. It uses the plot3 function to plot the set of points for each cluster separately and sets the title to "k-means clustering".

The InitCenter function is used to initialize the cluster center. Its main logic is as follows:

  • Calculate the side length of the voxel (d) and the number of rows (rows), column number (cols) and height (height) of the voxel according to the value range of the point cloud and the number of voxels.
  • Create an array that stores the point set and number of points for each voxel.
  • Traverse the point cloud data, assign each point to the corresponding voxel, and update the point set and point number.
  • Convert the voxel array to a 2D array and sort by number of points in descending order.
  • The first K voxels with the highest point density are extracted as the initial clustering center, and the centroid of each voxel is calculated as the cluster center position.
  • <

Guess you like

Origin blog.csdn.net/a394467238/article/details/132585980