Main Content


Spatially bin point cloud points



bins = pcbin(ptCloud,numBins) spatially grids points in the point cloud, ptCloud. The output bins stores spatial bin locations, which are the indices for the points. The function finds the bin locations by sampling the point cloud in each dimension by the number of bins specified by numBins.

bins = pcbin(ptCloud,numBins,spatialLimits) specifies the spatial limits to use when the function places points into bins.

[bins,binLocations] = pcbin(___) also returns binLocations, the spatial bounds of each bin in output bins. binLocations is the same size as bins.


collapse all

Read point cloud data into the workspace.

ptCloud = pcread('teapot.ply');

Spatially bin the point cloud into a 32-by-32-by-32 grid.

indices = pcbin(ptCloud,[32 32 32]);

Build an occupany grid.

occupancyGrid = cellfun(@(c) ~isempty(c), indices);

Display the occupany grid.

ViewPnl = uipanel(figure);

Read point cloud data into the workspace.

ptCloud = pcread('teapot.ply');

Spatially bin the point cloud into a 32-by-32-by-1 grid.

indices = pcbin(ptCloud,[32 32 1]);

Build a density grid.

densityGrid = cellfun(@(c) ~isempty(c),indices);

Display the density grid.


Input Arguments

collapse all

Point cloud, specified as a pointCloud object.

Number of bins, specified as a three-element vector of the form [numBinsX,numBinsY, numBinsZ]. The vector elements indicate the number of bins to use in each dimension, respectively.

Spatial limits, specified as a 3-by-2 numeric matrix of the form [Xmin, Xmas; Ymin, Ymax; Zmin, Zmax]. The spatial limits define the bounds used when the function bins points. Points that are outside of the specified limits are not included in the output.

Output Arguments

collapse all

Spatial bin locations, returned as a cell array of the same size as input numBins. Each cell in the array contains indices to locations of points in the input point cloud that define the bins.

Invalid points, which are points with coordinates that contain Inf or NaN. The function ignores and does not include invalid points in the output. Each bin includes the left bin edge, except for the last bin which includes both bin edges.

Bin spatial bounds, returned as a cell array the same size as output bins. Each cell in the array contains the spatial bounds of the bins in bins. The bounds for a bin are of the form [Xmin, Xmax; Ymin, Ymax; Zmin, Zmax].

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

See Also



Introduced in R2020a