Downsample a 3-D point cloud
___ = pcdownsample(___,
specifies a name-value argument in addition to any combination of arguments from
Downsample Point Cloud Using Box Grid Filter
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.
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);
Remove Redundant Points from Point Cloud
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] Count: 1 XLimits: [1 1] YLimits: [1 1] ZLimits: [1 1] Color: [0x3 uint8] Normal: [0x3 double] Intensity: [0x1 double]
Preserve Organized Structure of Point Cloud After Downsampling
Load an organized point cloud from a saved MAT-file.
ld = load('drivingLidarPoints.mat'); orgPtCloud = ld.ptCloud;
Downsample the point cloud.
percentage = 0.1; orgPtCloudOut = pcdownsample(orgPtCloud,'random',percentage,PreserveStructure=true);
'random' — Random downsample method
Random downsample method, specified as
'random' method is more efficient than the
'gridAverage' downsample method, especially when it
is applied before point cloud registration.
percentage — Percentage of input
Percentage of input, specified as a nonnegative scalar in the range [0, 1]. The
percentage input specifies the portion of the input
for the function to return.
'gridAverage' — Grid average downsample method
Grid average downsample method, specified as
'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
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.
gridStep — Size of 3-D box for grid filter
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.
'nonuniformGridSample' — Nonuniform grid sample method
Nonuniform grid sample method, specified as
you use the
'nonuniformGridSample' algorithm, the normals
are computed on the original data prior to downsampling. The downsampled
output preserves more accurate normals.
maxNumPoints — Maximum number of points in grid box
Maximum number of points in grid box, specified as an integer
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
Specify optional pairs of arguments as
the argument name and
Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name in quotes.
PreserveStructure=true preserves the organized
structure of a point cloud.
PreserveStructure — Preserve the organized structure of a point cloud
false (default) |
Preserve the organized structure of a point cloud, specified as
false. The table
describes the point cloud structure according to the value of
|The function returns|
An organized, downsampled, point cloud.
The Location property that describes the structure of the point cloud, contains an M-by-N-by-3 matrix.
Points that are not selected
in the downsampled point cloud are filled with
An unorganized, downsampled, point cloud.
The Location property that describes the structure of the point cloud, contains an M-by-3 matrix.
 Pomerleau, F., F. Colas, R. Siegwart, and S. Magnenat. “Comparing ICP variants on real-world data sets.” Autonomous Robots. Vol. 34, Issue 3, April 2013, pp. 133–148.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Usage notes and limitations:
GPU code generation for nonuniform grid sample method is not optimized.
For the random downsample method, GPU Coder™ uses the NVIDIA® CUDA® random library (cuRAND) to generate the random numbers. Because of architectural and implementation differences between the random number generators on the GPU and CPU, numerical verification does not always match.
PreserveStructurename-value argument is not supported for GPU code generation.