Search code examples
matlabimage-processingpointmesh

Point cloud decimation in matlab


I created 10 point clouds in matlab but I have different number of points in each cloud. I want to decimate it to the same number of points. Is there any function in matlab to resample/decimate point cloud to the fixed numer of points (for example : to 1000 points) ?

I would appreciate for any help&advice please :)


Solution

  • Assuming that your cloud points are stored as matrices, you will have 10 matrices with different number of rows each (Or maybe you have just a cell storing the matrices). (lets call them PointCloud1, PointCloud2 ... PointCloud10)

    If you want to randomly take 1000 points of each matrix (assuming that the smallest matrix have at least 1000 points) I would suggest using randperm to generate a random permutation of indexes and then take the first 1000 indexes.

    Example using PointCloud1:

    [nrows, ncols] = size(PointCloud1);
    idx = randperm(nrows);
    
    sub_PC1 = PointCloud1(idx(1:1000),:);
    

    Here sub_PC1 is a subsample of 1000 random rows of PointCloud1.