问题描述
我有一个3D点云(XYZ),其中Z
可以是位置或能量.我想将它们投影在 n -by- m 网格(在我的问题n = m
中)的2D曲面上,方式是每个网格单元的值为在Z
是位置的情况下,Z
的最大差,在Z
是能量的情况下,Z
的总和值.
I have a 3D point cloud (XYZ) where the Z
can be position or energy. I want to project them on a 2D surface in a n-by-m grid (in my problem n = m
) in a manner that each grid cell has a value of the maximum difference of Z
, in case of Z
being position, or a value of summation over Z
, in case of Z
being energy.
例如,在0 <= (x,y) <= 20
范围内,有500点.假设xy平面具有 n -by- m 个分区,例如 4 -by- 4 ;我的意思是,在x
和y
方向上,我们有4个分区,每个分区的间隔为5
(以使其最大为20
.现在,这些单元格中的每一个都应具有求和的值,或者在定义的xy平面的相应列中的那些点的Z
值的最大差.
For example, in a range of 0 <= (x,y) <= 20
, there are 500 points. Let's say the xy-plane has n-by-m partitions, e.g. 4-by-4; by which I mean in both x
and y
directions we have 4 partitions with an interval of 5
(to make it 20
at maximum. Now, each of these cells should have a value of the summation, or maximum difference, of the Z
value of those points which are in the corresponding column in the defined xy-plane.
为进行如下测试,我制作了一个简单的XYZ数组,在这种情况下,Z
表示每个点的能量.
I made a simple array of XYZ just for a test as follows, where in this case, Z
denotes the energy of the each point.
n=1;
for i=1:2*round(random('Uniform',1,5))
for j=1:2*round(random('Uniform',1,5))
table(n,:)=[i,j,random('normal',1,1)];
n=n+1;
end
end
如何做到没有循环?
推荐答案
备注:
- 通过python熊猫和切割方法,所有这些几乎都是一线的.
- 我已经重写了您的随机云初始化
您可以做的是
What you can do is
- 通过
meshgrid
布局xy网格 - 将云投影在xy上(简单边缘化)
- 通过
kd-tree
搜索找到最近的网格点,即 label 将您的数据与每个云点相关联的网格节点 - 按标签分组数据并评估您的本地统计信息(通过
accumarray
).
- layout an xy grid via
meshgrid
, - project the cloud on xy (simple marginalization)
- find the nearest grid point via a
kd-tree
search, i.e. label your data associating to each cloud point a grid node - group data by label and evaluate your local statistic (via
accumarray
).
这是一个可行的示例:
samples = 500;
%data extrema
xl = 0; xr = 1; yl = 0; yr = 1;
% # grid points
sz = 20;
% # new random cloud
table = [random('Uniform',xl,xr,[samples,1]) , random('Uniform',yr,yl,[samples,1]), random('normal',1,1,[samples,1])];
figure; scatter3(table(:,1),table(:,2),table(:,3));
% # grid construction
xx = linspace(xl,xr,sz); yy = linspace(yl,yr,sz);
[X,Y] = meshgrid(xx,yy);
grid_centers = [X(:),Y(:)];
x = table(:,1); y = table(:,2);
% # kd-tree
kdtreeobj = KDTreeSearcher(grid_centers);
clss = kdtreeobj.knnsearch([x,y]); % # classification
% # defintion of local statistic
local_stat = @(x)sum(x) % # for total energy
% local_stat = @(x)max(x)-min(x) % # for position off-set
% # data_grouping
class_stat = accumarray(clss,table(:,3),[],local_stat );
class_stat_M = reshape(class_stat , size(X)); % # 2D reshaping
figure; contourf(xx,yy,class_stat_M,20);
这篇关于通过在2D曲面中投影来分析3D点云的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!