1.对于点云,首先要归一化,即将点云最大值归一化为1,matlab代码如下:
path = which('normalization');
path = [path(1:end - size('normalization.m',2)) './'];
fpath = fullfile(path, '*.ply');
im_dir = dir(fpath);
im_num = length(im_dir);
for i=1:im_num
ptr = pcread(fullfile(path, im_dir(i).name));
center_x = ptr.XLimits(1) + (ptr.XLimits(2) -ptr.XLimits(1))/2;
center_y = ptr.YLimits(1) + (ptr.YLimits(2) -ptr.YLimits(1))/2;
center_z = ptr.ZLimits(1) + (ptr.ZLimits(2) -ptr.ZLimits(1))/2;
center = [center_x center_y center_z];
location = bsxfun(@minus,ptr.Location, center);%(0,0,0)中心在最中间
new_ptr = pointCloud(location);
max_XYZ = max([new_ptr.XLimits new_ptr.YLimits new_ptr.ZLimits]);%除以XYZ中最大值,保证不变形
new_ptr = pointCloud(location./max_XYZ,'Normal',ptr.Normal);
% pcshow(new_ptr);
pcwrite(new_ptr,[im_dir(i).name(1:end - size('.pcd',2)) '.ply']);
end
2.归一化后即可添加不同类型(如高斯,指数,伽马等类型)的噪声,matlab代码如下:
%给模型添加标准高斯噪声
% path = './gd_test/ply_normal';
% path = 'C:\Users\Administrator\Desktop\pointCloudGMM-all\point-cloud-GMM v0_relese\Test_model\20_PLY_GT';
path = './';
noise_level_all = [0.01];
fpath = fullfile(path, '*.ply');
im_dir = dir(fpath);
im_num = length(im_dir);
% r2 = random('Normal',0,2);
n