Clear Filters
Clear Filters

How to extract individual tree pointcloud to las/laz file?

6 views (last 30 days)
Hi,
From here, I wonder how to get these 5 trees into 5 different las/laz files?
Base on LAS or LAZ file writer - MATLAB - MathWorks Australia, I tried "lasWriter = lasFileWriter(TreeId1)" but it says "Unrecognized function or variable 'TreeId'.
Thanks in advance,

Answers (1)

Pratyush Swain
Pratyush Swain on 27 Nov 2023
Hi Ha Ninh,
I understand you want to convert individual tree points into point clouds and save them into laz files. For this purpose we have to utilize the 'normalizedPoints' and 'label3D' variables.
Please follow the implementation below after you have realised the tree metrics with reference to the example in https://www.mathworks.com/help/lidar/ug/extraction-of-forest-metrics-and-individual-tree-attributes.html#ExtractionOfForestAndIndividualTreeMetricsExample-8 :
% Consider points belongs to valid labels
validLabels = label3D ~= 0;
filteredLabels = label3D(validLabels);
filteredPoints = normalizedPoints(validLabels,:);
[filteredLabels, sortedIds] = sort(filteredLabels);
filteredPoints = filteredPoints(sortedIds,:);
The above data processing is similar to that performed 'helperExtractTreeMetrics' function. However instead of performing tree metrics analysis, we can proceed towards grouping points as per corresponding labels.
% Find groups based on filteredLabel
groups = findgroups(filteredLabel);
% Split the filteredPoints array based on the groups and apply a function to each group
groupedData =(@(x) {x}, filteredPoints, groups);
Finally we can iterate over grouped data to convert the points into point cloud and finally write them to laz files.
for i = 1:numel(groupedData)
points = groupedData{i}; % Access the points for a specific group
ptCloud = pointCloud(points); % Convert the points into a pointCloud
filename = sprintf('group_%d.laz', i); % Generate a filename for the LAS file
lasWriter = lasFileWriter(filename);
writePointCloud(lasWriter,ptCloud);
end
For more information please refer to:
Hope this helps.

Products


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!