Centroid in uniform sampling is actually not a centroid

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Centroid in uniform sampling is actually not a centroid

copk
This post was updated on .
Hi guys,
According to the PCL documentation the uniform sampling approximates the pointcloud with a centroid of each voxel in the voxel grid
(doc: class creates a 3D voxel grid (think about a voxel grid as a set of tiny 3D boxes in space) over the input point cloud data. Then, in each voxel (i.e., 3D box), all the points present will be approximated (i.e., downsampled) with their centroid)
I had however some strange results and tried to test the uniform sampling. The outputs are weird, look at the code below.

I create the pointcloud with 3 points, all lying in the cube 1m x 1m x 1m and perform the uniform sampling with the voxel size of 1. Having the points as below, the centroid (to my best knowledge) should be at the point (0.5, 0.5, 0.5) however the uniform sampling outputs the centroid as (0.5, 0.2, 0.5). Why is it so, why the centroid in the uniform sampling is not the actual centroid of the voxel?

      pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
      pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>);

        cloud->resize(3);
        cloud->points[0].x = 0.5;
        cloud->points[0].y = 0.2;
        cloud->points[0].z = 0.5;

        cloud->points[1].x = 0.5;
        cloud->points[1].y = 0.5;
        cloud->points[1].z = 0.5;

        cloud->points[2].x = 0.5;
        cloud->points[2].y = 0.8;
        cloud->points[2].z = 0.5;

// --- filtering
        pcl::UniformSampling<pcl::PointXYZ> filter;
        filter.setInputCloud(cloud);
        filter.setRadiusSearch(1);
        pcl::PointCloud<int> keypointIndices;
        filter.compute(keypointIndices);
        pcl::copyPointCloud(*cloud, keypointIndices.points, *cloud_filtered);

// --- displaying
        for (size_t i = 0; i < cloud_filtered->points.size(); i++)
        {
                std::cout <<"filtered point: "<< cloud_filtered->points[i].x << " " << cloud_filtered->points[i].y << " " << cloud_filtered->points[i].z<< std::endl;
        }


to verify I also ran this piece of code, and this gives correct result i.e. (0.5, 0.5, 0.5).

Eigen::Vector4f centroid;
pcl::compute3DCentroid(*cloud, centroid);
std::cout << "The XYZ coordinates of the centroid are: (" << centroid[0] << ", " << centroid[1] << ", " << centroid[2] << ")."<< std::endl;

Can some of you test if have similar output and if so why it is like that?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Centroid in uniform sampling is actually not a centroid

copk
This post was updated on .
Hi once again,

I partially figured out the problem so maybe it will be useful for somebody. The documentation is limited that's why there are some confusions but let me describe it more thoroughly.

First of all, in the documentation it says that: in each voxel (i.e., 3D box), all the points present will be approximated (i.e., downsampled) with their centroid. which is not exactly true.
In case of UniformSampling filter, the output of each voxel will be a point that is closest to the centroid (because the output is the index of the point) not the actual centroid. Centroid however will be the output of the voxel filter. Those two algorithms have the same description in the documentation but actually differ in what they do. Uniform Sapling gives a cloud of points that exist in the original cloud, while the voxel filter creates a new pointcloud.

The other thing is: the phenomenon I decribed before highly depends on the selection of the origin of the first voxel - whether it's center is declared on the first point in the pointcloud or is it selected randomly or other approach. If anybody knows how it works i.e. what is the approach to assigns voxels in the space and can elaborate on that it will be useful to know.
Thanks!
Loading...