1. 程式人生 > >3D人臉點雲降噪 matlabk近鄰

3D人臉點雲降噪 matlabk近鄰

% ptCloud = pointCloud(1000*rand(100,3,'single'));
%'double';
pointdata=importdata('C:\myfiles\xyz\mdq_face_1.xyz'); %載入點雲資料
ptCloud = pointCloud(pointdata);
% figure;
% pcshow(ptCloud); %顯示點雲資料
[pointdata_rows,pointdata_list] = size(pointdata);
max_dists = 1.5; %設定閾值
final_face = [];
for ii = 1:pointdata_rows
    point = pointdata(ii,:);
    k = 8;
    [indices,dists] = findNearestNeighbors(ptCloud,point,k);
    mean_dists = mean(dists); %求均值
    ss = std(dists,0,1); %求標準差
    dt = mean_dists+(0.6*ss); %定義距離
    indices_list = []; 
    if dt < max_dists
        final_face = [final_face;point];

    end
end
figure;
pcshow(final_face); %顯示降噪後的點雲圖
%後面的是把降噪後的點雲重輸出到檔案
% output_file = 'C:\myfiles\xyz\mdq_face_2.xyz';
% fid = fopen(output_file,'a');
%[face_row_e,face_list_e] = size(final_face);
% for i = 1:face_row_e
%     for j = 1:face_list_e
%         fprintf(fid,'%f\t',final_face(i,j));
%     end
%     fprintf(fid,'\r\n');
% end
% fclose(fid);