Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

pcdownsample

Downsample a 3-D point cloud

Syntax

ptCloudOut = pcdownsample(ptCloudIn,'random',percentage)
ptCloudOut = pcdownsample(ptCloudIn,'gridAverage',gridStep)
ptCloudOut = pcdownsample(ptCloudIn,'nonuniformGridSample',maxNumPoints)

Description

ptCloudOut = pcdownsample(ptCloudIn,'random',percentage) returns a downsampled point cloud with random sampling and without replacement. The percentage input specifies the portion of the input to return to the output.

example

ptCloudOut = pcdownsample(ptCloudIn,'gridAverage',gridStep) returns a downsampled point cloud using a box grid filter. The gridStep input specifies the size of a 3-D box.

ptCloudOut = pcdownsample(ptCloudIn,'nonuniformGridSample',maxNumPoints) returns a downsampled point cloud using nonuniform box grid filter. You must set the maximum number of points in the grid box, maxNumPoints, to at least 6.

Examples

collapse all

Read a point cloud.

ptCloud = pcread('teapot.ply');

Set the 3-D resolution to be (0.1 x 0.1 x 0.1).

gridStep = 0.1;
ptCloudA = pcdownsample(ptCloud,'gridAverage',gridStep);

Visualize the downsampled data.

figure;
pcshow(ptCloudA);

Compare the point cloud to data that is downsampled using a fixed step size.

stepSize = floor(ptCloud.Count/ptCloudA.Count);
indices = 1:stepSize:ptCloud.Count;
ptCloudB = select(ptCloud, indices);

figure;
pcshow(ptCloudB);

Create a point cloud with all points sharing the same coordinates.

ptCloud = pointCloud(ones(100,3));

Set the 3-D resolution to a small value.

gridStep = 0.01;

The output now contains only one unique point.

ptCloudOut = pcdownsample(ptCloud,'gridAverage',gridStep)
ptCloudOut = 
  pointCloud with properties:

     Location: [1 1 1]
        Color: [0x3 uint8]
       Normal: [0x3 double]
    Intensity: []
        Count: 1
      XLimits: [1 1]
      YLimits: [1 1]
      ZLimits: [1 1]

Input Arguments

collapse all

Point cloud, specified as a pointCloud object.

Random downsample method, specified as the character vector, 'random'. This method is more efficient than the 'gridAverage' downsample method, especially when it is applied before point cloud registration.

Downsample the point cloud using 'random', 'gridAverage', or 'nonuniformGridSample' inputs, according to the Metric you use in the pcregrigid function for registration.

MetricPoint Cloud A Downsample MethodPoint Cloud B Downsample Method
'pointToPoint''random''random'
'gridAverage''gridAverage'
'pointToPlane''gridAverage''gridAverage'
'random''nonuniformGridSample'

Percentage of input, specified as a positive scalar in the range [0, 1]. The percentage input specifies the portion of the input for the function to return.

Grid average downsample method, specified as the character vector, 'gridAverage'. Points within the same box are merged to a single point in the output. Their color and normal properties are averaged accordingly. This method preserves the shape of the point cloud better than the 'random' downsample method.

The function computes the axis-aligned bounding box for the entire point cloud. The bounding box is divided into grid boxes of size specified by gridStep. Points within each grid box are merged by averaging their locations, colors, and normals.

Downsample the point cloud using 'random', 'gridAverage', or 'nonuniformGridSample' inputs, according to the Metric you use in the pcregrigid function for registration.

MetricPoint Cloud A Downsample MethodPoint Cloud B Downsample Method
'pointToPoint''random''random'
'gridAverage''gridAverage'
'pointToPlane''gridAverage''gridAverage'
'random''nonuniformGridSample'

Size of 3-D box for grid filter, specified as a numeric value. Increase the size of gridStep when there are not enough resources to construct a large fine-grained grid.

Data Types: single | double

Nonuniform grid sample method, specified as the character vector 'nonuniformGridSample'. The best use of this method is to apply it as a preprocessing step to the pcregrigid function for point cloud registration, when you use the 'pointToPlane' metric. When you use the 'nonuniformGridSample' algorithm, the normals are computed on the original data prior to downsampling. The downsampled output preserves more accurate normals.

Downsample the point cloud using 'random', 'gridAverage', or 'nonuniformGridSample' inputs, according to the Metric you use in the pcregrigid function for registration.

MetricPoint Cloud A Downsample MethodPoint Cloud B Downsample Method
'pointToPoint''random''random'
'gridAverage''gridAverage'
'pointToPlane''gridAverage''gridAverage'
'random''nonuniformGridSample'

Maximum number of points in grid box, specified as an integer greater than 6. The method randomly selects a single point from each box. If the normal was not provided in the input point cloud, this method automatically fills in the normal property in the ptCloudOut output.

Output Arguments

collapse all

Filtered point cloud, returned as a pointCloud object.

Introduced in R2015a