[英]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濾波器:
所以
例
%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.