我在Matlab中合并了两个pointCloud对象,比如说pc1和pc2。 pc1是参考云,也就是说,在合并云之前,需要删除pc2中所有与pc1中的点相等或非常接近的点。
说明:
我知道函数pcmerge
几乎可以满足我的要求-但我绝对需要删除多余的点,并且对这些点取平均值是不可行的
每个点云的大小约为500,000,我必须比较其中的许多(100)。这就是为什么速度很重要。
我希望能够在pc1的每个点周围定义一个半径,以提供“冗余”的标准。但是为了提高速度,可以进行一些简化(请参阅我的第二个解决方法)。
解决方法:
一个有效但很慢的解决方案是在pc2中为其最近的邻居寻找每个点:
function [ pc ] = pcaddcloud( pc1, pc2, res )
limits = overlapRange(pc2, pc1);
pc1idx = findPointsInROI(pc2, limits);
pc2Overlap = select(pc2, pc1idx);
idx = findPointsInROI(pc1, limits);
pc1Overlap = select(pc1, idx);
endi = pc2Overlap.Count;
pc2Overlap = pc2Overlap.Location;
for i=1:endi
[idx, ~] = findNeighborsInRadius(pc1Overlap, pc2Overlap(i,:), res);
% keep only indices of redundant points to delete them later
if isempty(idx)
pc1idx(i) = 0;
end
end
pc1idx(pc1idx==0) = [];
pc2 = pc2.Location;
pc2(pc1idx,:) = [];
pc = pointCloud([pc1.Location; pc2]);
end
% Compute the bounding box of overlapped region (from pcmerge)
function rangeLimits = overlapRange(pcA, pcB)
xlimA = pcA.XLimits;
ylimA = pcA.YLimits;
zlimA = pcA.ZLimits;
xlimB = pcB.XLimits;
ylimB = pcB.YLimits;
zlimB = pcB.ZLimits;
if (xlimA(1) > xlimB(2) || xlimA(2) < xlimB(1) || ...
ylimA(1) > ylimB(2) || ylimA(2) < ylimB(1) || ...
zlimA(1) > zlimB(2) || zlimA(2) < zlimB(1))
% No overlap
rangeLimits = [];
else
rangeLimits = [ min(xlimA(1),xlimB(1)), max(xlimA(2),xlimB(2)); ...
min(ylimA(1),ylimB(1)), max(ylimA(2),ylimB(2)); ...
min(zlimA(1),zlimB(1)), max(zlimA(2),zlimB(2))];
end
end
我有一个使用alpha形状的更快的解决方案(仍然慢,但比解决方案1更快):我在pc1周围定义了一个船体,并确定pc2的点是否在内部。缺点:仅“稍微位于外部”(即靠近pc1的点但不在alpha形状之内)的点不会被检测为多余。
function [ pc ] = pcaddcloud( pc1, pc2 )
limits = overlapRange(pc2, pc1);
pc2 = pc2.Location;
pc1 = pc1.Location;
%seems to be faster than findPointsInROI:
pc2Overlap = pc2(pc2(:,1)>=limits(1,1)&pc2(:,1)<=limits(1,2) ...
&pc2(:,2)>=limits(2,1)&pc2(:,2)<=limits(2,2)...
&pc2(:,3)>=limits(3,1)&pc2(:,3)<=limits(3,2),:);
pc2idx = find(pc2(:,1)>=limits(1,1)&pc2(:,1)<=limits(1,2) ...
&pc2(:,2)>=limits(2,1)&pc2(:,2)<=limits(2,2)...
&pc2(:,3)>=limits(3,1)&pc2(:,3)<=limits(3,2));
pc1Overlap = pc1(pc1(:,1)>=limits(1,1)&pc1(:,1)<=limits(1,2) ...
&pc1(:,2)>=limits(2,1)&pc1(:,2)<=limits(2,2)...
&pc1(:,3)>=limits(3,1)&pc1(:,3)<=limits(3,2),:);
shape = alphaShape(double(pc1Overlap));
in = inShape(shape, double(pc2Overlap));
pc2idx(~in) = [];
pc2(pc2idx,:) = [];
pc = pointCloud([pc1; pc2]);
end
% Compute the bounding box of overlapped region (from pcmerge)
function rangeLimits = overlapRange(pcA, pcB)
xlimA = pcA.XLimits;
ylimA = pcA.YLimits;
zlimA = pcA.ZLimits;
xlimB = pcB.XLimits;
ylimB = pcB.YLimits;
zlimB = pcB.ZLimits;
if (xlimA(1) > xlimB(2) || xlimA(2) < xlimB(1) || ...
ylimA(1) > ylimB(2) || ylimA(2) < ylimB(1) || ...
zlimA(1) > zlimB(2) || zlimA(2) < zlimB(1))
% No overlap
rangeLimits = [];
else
rangeLimits = [ min(xlimA(1),xlimB(1)), max(xlimA(2),xlimB(2)); ...
min(ylimA(1),ylimB(1)), max(ylimA(2),ylimB(2)); ...
min(zlimA(1),zlimB(1)), max(zlimA(2),zlimB(2))];
end
end
我期待您的想法!如果需要,请随时询问更多信息-我是这个平台的新手。谢谢!
答案 0 :(得分:2)
您可以将ismembertol
与ByRows
选项一起使用来检测冗余点。但是请考虑使用立方邻域代替球形邻域。
假设您有两个矩阵pc1
,pc2
每个矩阵都有3列,公差为tol
:
idx = ismembertol(pc2, pc1, tol,'ByRows', true, 'DataScale' , 1);
result = [pc1; pc2(~idx,:)];