繁体   English   中英

如何在MATLAB中插值和平滑3D点云?

[英]How can I interpolate and smooth 3D point clouds in MATLAB?

我希望在遇到点云数据处理问题时获得一些帮助。 基本上,我有很多点云数据,它们零散且杂乱无章。 因此,我的目标是对“修补区域”中丢失的数据进行近似估计,并应用某种形式的光平滑来过滤噪声。

解决这个问题的第一个尝试是在MATLAB中进行插值方法。 这是按以下方式执行的,并提供了良好的结果,因为跨工作XY网格插入的Z点看起来像我期望的形状。

% Load Point Cloud:
Point_Cloud  = importdata(‘Point_Cloud_1.txt')
x            = Point_Cloud(1,:)';
y            = Point_Cloud(2,:)';
z            = Point_Cloud(3,:)';

% Interpolate inspection points:
Density = 300;
[X,Y]   = meshgrid(linspace(min(x), max(x), Density), linspace(min(y), max(y), Density));
F       = scatteredInterpolant(x, y, z, 'natural','linear');
Z       = F(X,Y);
Int_PC  = [reshape(X,Density^2,1) reshape(Y,Density^2,1) reshape(Z,Density^2,1)];
Int_PC(any(isnan(Int_PC{i}),2),:) = [];  

% Plot results:
scatter3(x, y, z, 20, 'r', 'fill'); % Original data
hold on;
scatter3(Int_PC(:,1), Int_PC(:,2), Int_PC(:,3), 20, 'r', 'fill'); % Interpolated data

这样做的问题是噪声数据用于计算插值F,因此上面的代码仅解决了斑驳的数据问题。

然后,我考虑了使用“曲线拟合工具箱”进行样条曲线拟合。 薄板平滑样条线似乎很有意义,因为它接受分散的(非网格化)数据,并且不对所有点进行插值,从而平滑了噪声。 下面的代码。 执行时,结果令人失望,因为原始点与计算出的曲面之间的拟合度非常差(超出了消除噪声所需的水平)。

Spline = tpaps([x;y],z);
fnplt(Spline)

薄板花键示例

有人可以提出任何解决方案吗?

谢谢。

一个建议,使用Savitzky-Golay滤波器:

所以

  1. 使用这个过滤器
  2. 使用您的代码来完成缺少的部分。

%We build the noisy 3D point cloud

[X,Y] = meshgrid(0:0.1:4.9,0:0.1:4.9);
Z = sin(X)+cos(Y)+0.5*rand(50,50);

% The smoothing (with sgolayfilt(Z,order,length of the moving windows))
t1 = sgolayfilt(Z.',2,25); %smoothing over the x-axis
t2 = sgolayfilt(Z,2,25); %smoothing over the y-axis
t  = (t1.'+t2)/2; %smoothing in booth directions

surf(X,Y,t)

抹平之前

之前

平滑后

后

编辑

相同的操作,但数据分散:

%random X and Y

X = rand(100,1)*5;
Y = rand(100,1)*5;

Z = sin(X)+cos(Y);

%Calculate the interpolant
F =  scatteredInterpolant(X,Y,Z);

%Fix the grid size
gs = 0.1; %grid size

tx = min(X(:)):gs:max(X(:));
tz = min(Y(:)):gs:max(Y(:));

%Scattered X,Y to gridded x,y
[x,y] = meshgrid(tx,ty);

%Interpolation over z-axis
z = F(x,y);

t1 = sgolayfilt(z.',2,5);
t2 = sgolayfilt(z,2,5);

t  = (t1.'+t2)/2;

surf(X,Y,t)
colormap winter

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM