How can I convert double from cell? (UAV LiDAR data workflow in forestry)

3 ビュー (過去 30 日間)
Atman Dhruva
Atman Dhruva 2022 年 9 月 23 日
コメント済み: Atman Dhruva 2022 年 9 月 24 日
I am using a toolbox 'Extract Forest Metrics and Individual Tree Attributes from Aerial LiDAR Data", and I have used the same in the past and it has worked well with some small tweaks and adjustments.
In this instance,
groundPtsIdx = segmentGroundSMRF(ptCloud);
nonGroundPtCloud = select(ptCloud,~groundPtsIdx);
groundPtCloud = select(ptCloud,groundPtsIdx);
figure
pcshow(nonGroundPtCloud)
title("Segmented Non-Ground Points")
uicontrol('Visible', 'off')
figure
pcshow(groundPtCloud)
title("Segmented Ground Points")
uicontrol('Visible','off')
this works fine. but in the next step is where I get the error of converting double from cell.
the unqiueXY variable seems to be in a cell but I need it in Double. (PS: used aerial LiDAR data in the past with the same toolbox and there have never been any issues with this step)
groundPoints = groundPtCloud.Location;
% remove duplicate points
[uniqueZ,uniqueXY] = groupsummary(groundPoints(:,3),groundPoints(:,1:2), @mean);
% interpolation to estimate ground elevation at each point
F = scatteredInterpolant(double(uniqueXY), double(uniqueZ), "natural");
% this is where I get an error using double - Conversion to double from cell is not possible.
estElevation = F(double(ptCloud.Location(:,1)), double(ptCloud.Location(:,2)));
% normalize elevation
normalizedPoints = ptCloud.Location;
normalizedPoints(:,3) = normalizedPoints(:,3) - estElevation;
point_cloud = pointCloud(normalizedPoints)
% visualise
figure
pcshow(point_cloud)
title("Point Cloud with normalized elevation")
uicontrol('Visible', 'off')
Any leads/suggestions are welcome to be able to convert from cell to double, and I'd be super thankful!!

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 9 月 23 日
% remove duplicate points
[uniqueZ,uniqueXY] = groupsummary(groundPoints(:,3),groundPoints(:,1:2), @mean);
Your first parameter groundPoints(:,3) is a numeric column vector (not a table() object), so you are using the "array data" form of groupsummary()
Your groupingvars input, groundPoints(:,1:2) is a matrix with two columns. The documentation says,
  • For array input data, groupvars can be either a column vector with the same number of rows as A or a group of column vectors arranged in a matrix or cell array.
Notice the wording here implies that having the groupingvars have more than one column, is to be treated as having multiple column vectors. This will be important in a second.
You are using multiple outputs from groupsummary. The second one, BG, is documented as
For more than one input vector, BG is a cell array containing column vectors of equal length. Information for each group is contained in the elements of a row across all vectors in BG. Each group maps to the corresponding row of the output array B.
Remember a moment ago the wording for groupingvars indicated that if there is more than one column that it is treated as multiple column vectors; now take that wording into the description of BG and we see that "For more than one input vector, BG is a cell array" -- so multiple columns in groupvars will get you a cell array output.
I would suggest that you
[uniqueXY, ~, G] = uniquetol(groundPoints(:,1:2), 'rows');
uniqueZ = groupsummary(groundPoints(:,3), G, @mean);
  1 件のコメント
Atman Dhruva
Atman Dhruva 2022 年 9 月 24 日
Thanks so much, Walter! I tried this approach as well as the following:
uniqueXY = [uniqueXY{:}]
and it works!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLabeling, Segmentation, and Detection についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by