I have a 3D point cloud image(.ply format). I need to cut it from center dividing into two. Tried to select only half of the Point cloud using following code but random points are obtained not the desired ones. Using following logic t divide a point cloud in Half(1/2 of original) and save the resultant in a new point cloud. Neither able to correctly slice cloud image from center nor save it in new cloud.
stepSize = 1;
indices = 1:stepSize:(i1.Count)/2;
pt = select(i1, indices);
I also checked following code:
points3d = i1.Location;
points3d_1 = points3d(points3d(:, 1) < 100, :);
points3d_2 = points3d(points3d(:, 1) >= 100, :);
ptCloud1 = pointCloud(points3d_1);
ptCloud2 = pointCloud(points3d_2);
pcshow(ptCloud1);
figure
pcshow(ptCloud2);
Both the snippets are doing same randomly a part is divided and the no matter what range i try in
point3d(:,1)<range
second slice is always full original image. Also the slice image is containing background of original image as shown below. how to get only cloud region stored in new ptCloud1 and ptCloud2.
How can I get new point cloud which is sliced. Using MatalbR2014b
You would need to look at the coordinates of the points, and not just their indices.
Let's say ptCloud
is your pointCloud
object, and you are using MATLAB R2015b or later with the Computer Vision System Toolbox.
>> points3d = ptCloud.Location;
gives you the [X,Y,Z] coordinates of your point cloud points in the form or a 3-column matrix. Let's say you want to cut your point cloud in half along the X axis by a plane X = 10. You would do that the following way:
points3d_1 = points3d(points3d(:, 1) < 10, :);
points3d_2 = points3d(points3d(:, 1) >= 10, :);
ptCloud1 = pointCloud(points3d_1);
ptCloud2 = pointCloud(points3d_2);