【三维点云滤波】对三维点云空间数据进行滤波的matlab仿真

1.软件版本

MATLAB2021a

2.部分核心代码

clc;
clear;
close all;
warning off;


Im    = 120;
In    = 401;
%加载保存好的点云数据
load p.mat
%%
%步骤一:NAN点的去除
[R,C]                    = size(p);
x1                       = p(:,1);
y1                       = p(:,2);
z1                       = p(:,3);

x_ini                    = reshape(x1,[Im,In]);
y_ini                    = reshape(y1,[Im,In]);
z_ini                    = reshape(z1,[Im,In]);

figure(1);
subplot(121);
surf(x_ini,y_ini,z_ini);
axis equal
camlight right;
lighting phong;
shading interp
title('滤波前');

x1(find(isnan(x1) == 1)) = 0;
y1(find(isnan(y1) == 1)) = 0;
z1(find(isnan(z1) == 1)) = 0;
x1 = smooth(x1,2,'moving');
y1 = smooth(y1,2,'moving');
z1 = smooth(z1,2,'moving');

x0                       = reshape(x1,[Im,In]);
y0                       = reshape(y1,[Im,In]);
z0                       = reshape(z1,[Im,In]);
 

%%
%步骤二:去掉大面积的0像素点区域
for i = 1:In
    tmpx(i) = length(find(x0(:,i) == 0));
end
ind = find(tmpx > 0);
x0(:,ind) = [];
y0(:,ind) = [];
z0(:,ind) = [];
 

%%
%步骤三:数据中,中空的区域的修补,使得曲面平滑
[Im,In] = size(x0);
%矩阵滤波及中值滤波
x0 = func_bu(x0,Im,In);
y0 = func_bu(y0,Im,In);
z0 = func_bu(z0,Im,In);
for i = 1:In
    tmpx2(i) = length(find(x0(:,i) == 0));
end
ind2 = find(tmpx2 > 0);
x0(:,ind2) = [];
y0(:,ind2) = [];
z0(:,ind2) = [];
 
%%
%步骤四:高斯平滑
[Im,In] = size(x0);
x0      = func_smooth(x0,Im,In);
y0      = func_smooth(y0,Im,In);
z0      = func_smooth(z0,Im,In);


%%
%步骤五:三角重建
[Im,In] = size(x0);




figure(1);
subplot(122);
surf(x0,y0,z0);
axis equal
camlight right;
lighting phong;
shading interp
title('滤波后');

3.仿真结论

4.参考文献

A25-10

5.完整源码获得方式

方式1:微信或者QQ联系博主

方式2:订阅MATLAB/FPGA教程,免费获得教程案例以及任意2份完整源码

猜你喜欢

转载自blog.csdn.net/ccsss22/article/details/124263920