|
| 1 | +%% Create currupt version of the model |
| 2 | +% Takes a shape filename (assumed to be of the name XXX_GT.mat), and |
| 3 | +% creates noisy versions of it. |
| 4 | +% options is a structure with the following optional fields: |
| 5 | +% 'GaussianNoise' - a list of standard deviations for Gaussian additive corrupted versions of the surface. The standard deviation is expressed as a fraction of the surface' diameter |
| 6 | +% 'ShotNoiseProbability','ShotNoiseNumber','ShotNoiseMagnitude' - parameter lists for shot noise (i.e point are replaced by arbitrary 3D values. Parameter lists should be of equal size |
| 7 | +% 'DepthShotNoiseProbability','DepthShotNoiseMagnitude','DepthShotNoiseNumber' - for depth shot noise (i.e point are perturbed in the direction of the ray leading from the range scanner to the object |
| 8 | +% 'CameraCenter' - assumed camera location, for depth noise |
| 9 | + |
| 10 | +function X = addnoise(X_gt, shapename, options) |
| 11 | +if (exist('options','var')==0) |
| 12 | + options=[]; |
| 13 | +end |
| 14 | +% defaults=struct('GaussianNoise',[0.00125 0.0025 0.005 0.01 ],... |
| 15 | +% 'ShotNoiseProbability',[0 0],... |
| 16 | +% 'ShotNoiseNumber',[10 100],... |
| 17 | +% 'ShotNoiseMagnitude',[1 1]*0.2,... |
| 18 | +% 'DepthShotNoiseProbability',0,... |
| 19 | +% 'DepthShotNoiseMagnitude',0.2,... |
| 20 | +% 'DepthShotNoiseNumber',100,... |
| 21 | +% 'CameraCenter',[ 0 0 -6]); % optical center for GIP camera |
| 22 | +% options=incorporate_defaults(options,defaults); |
| 23 | + |
| 24 | +SAMPLING_SET=200; |
| 25 | +srf=struct('X',X_gt(:,1),'Y',X_gt(:,2),'Z',X_gt(:,3)); |
| 26 | +% estimate diameter |
| 27 | +ifps=fps_euc(srf,SAMPLING_SET); |
| 28 | +Dfps=pdist2(X_gt(ifps,:),X_gt(ifps,:)); |
| 29 | +diam=sqrt(max(Dfps(:))) |
| 30 | + |
| 31 | +% % Create surface with holes |
| 32 | +% for i=1:length(options.DepthShotNoiseProbability) |
| 33 | +% prb=options.DepthShotNoiseProbability(i); |
| 34 | +% X=X_gt; |
| 35 | +% if (prb>0) |
| 36 | +% idx=find(rand(size(X_gt(:,1)))<prb); |
| 37 | +% prb_name=num2str(prb); |
| 38 | +% else |
| 39 | +% idx=randperm(size(X_gt,1),options.DepthShotNoiseNumber(i)); |
| 40 | +% prb_name=num2str(options.DepthShotNoiseNumber(i)); |
| 41 | +% end |
| 42 | +% dr=(X_gt(idx,:)-repmat(options.CameraCenter(:)',[numel(idx),1])); |
| 43 | +% ndr=sqrt(sum(dr.^2,2)+1e-6); |
| 44 | +% X(idx,:)=X_gt(idx,:)+(repmat(randn(size(X_gt(idx,1))),[1 3]).*bsxfun(@rdivide,dr,ndr)*diam*options.DepthShotNoiseMagnitude(i)); |
| 45 | +% mat_filename=[shapename,'_depth_shot_noise_',prb_name,'.mat']; |
| 46 | +% save(mat_filename,'X'); |
| 47 | +% ply_filename=[shapename,'_depth_shot_noise_',prb_name,'.ply']; |
| 48 | +% write_ply_only_points(X,ply_filename); |
| 49 | +% end |
| 50 | + |
| 51 | +% Create a Gaussian noised version of the surface |
| 52 | +%for i=1:length(options.GaussianNoise) |
| 53 | + sig=diam*options.GaussianNoise |
| 54 | + X=X_gt+randn(size(X_gt))*sig; |
| 55 | + %mat_filename=[shapename,'_gaussian_noise_',num2str(sig),'.mat']; |
| 56 | + %save(mat_filename,'X'); |
| 57 | + ply_filename=[shapename,'_gaussian_noise_',num2str(options.GaussianNoise)]; |
| 58 | + %ply_filename=[shapename,'_gaussian_noise_',num2str(sig),'.ply']; |
| 59 | + %##################################### |
| 60 | + pcwrite(pointCloud(X), ['models/noise/' ply_filename '.ply']); |
| 61 | + %#################################### |
| 62 | +%end |
| 63 | + |
| 64 | +% % Create a 3D shot noise version of the surface |
| 65 | +% for i=1:length(options.ShotNoiseProbability) |
| 66 | +% prb=options.ShotNoiseProbability(i); |
| 67 | +% X=X_gt; |
| 68 | +% if (prb>0) |
| 69 | +% idx=find(rand(size(X_gt(:,1)))<prb); |
| 70 | +% prb_name=num2str(prb); |
| 71 | +% else |
| 72 | +% idx=randperm(size(X_gt,1),options.ShotNoiseNumber(i)); |
| 73 | +% prb_name=num2str(options.ShotNoiseNumber(i)); |
| 74 | +% end |
| 75 | +% X(idx,:)=X_gt(idx,:)+randn(size(X_gt(idx,:)))*diam*options.ShotNoiseMagnitude(i); |
| 76 | +% mat_filename=[shapename,'_shot_noise_',prb_name,'.mat']; |
| 77 | +% save(mat_filename,'X'); |
| 78 | +% ply_filename=[shapename,'_shot_noise_',prb_name,'.ply']; |
| 79 | +% write_ply_only_points(X,ply_filename); |
| 80 | +% end |
| 81 | + |
| 82 | +end |
0 commit comments