简体   繁体   English

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

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

I am hoping to get some help with a point cloud data processing problem I am faced with. 我希望在遇到点云数据处理问题时获得一些帮助。 Basically, I have lots of point cloud data that is patchy and noisey. 基本上,我有很多点云数据,它们零散且杂乱无章。 My aim is therefore to approximate data where it is missing in the “patchy areas” and apply some form of light smoothing to filter the noise. 因此,我的目标是对“修补区域”中丢失的数据进行近似估计,并应用某种形式的光平滑来过滤噪声。

My first attempt to solve this was the interpolation methods in MATLAB. 解决这个问题的第一个尝试是在MATLAB中进行插值方法。 This was executed as follows and provided good results, in that the interpolated Z points across the working XY grid looks like the shape I am expecting. 这是按以下方式执行的,并提供了良好的结果,因为跨工作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

The problem with this is that noisey data is used to compute the interpolant, F, so the above code only solves the patchy data problem. 这样做的问题是噪声数据用于计算插值F,因此上面的代码仅解决了斑驳的数据问题。

I then considered spline fitting using the Curve Fitting Toolbox. 然后,我考虑了使用“曲线拟合工具箱”进行样条曲线拟合。 The thin-plate smoothing spline seems to make sense as it accepts scattered (non-gridded) data and it does not interpolate all points, thereby smoothing noise. 薄板平滑样条线似乎很有意义,因为它接受分散的(非网格化)数据,并且不对所有点进行插值,从而平滑了噪声。 The code for this is below. 下面的代码。 When executed, the results are disappointing because the fit between the original points and the computed surface is very poor (beyond what is needed to smooth noise). 执行时,结果令人失望,因为原始点与计算出的曲面之间的拟合度非常差(超出了消除噪声所需的水平)。

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

Thin plate spline example 薄板花键示例

Could anybody suggest any solutions? 有人可以提出任何解决方案吗?

Thanks. 谢谢。

One proposition, using the Savitzky-Golay Filter: 一个建议,使用Savitzky-Golay滤波器:

So 所以

  1. Use this filter 使用这个过滤器
  2. Use your code to complete the missing part. 使用您的代码来完成缺少的部分。

EXAMPLE

%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)

Before smoothing 抹平之前

之前

After smoothing 平滑后

后

EDIT 编辑

The same operation but with scattered data: 相同的操作,但数据分散:

%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