-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathclustering.m
72 lines (67 loc) · 2.14 KB
/
clustering.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
function [Clusters,stdummy] = clustering(labels,pointcloud,inlierNb)
% CLUSTERING
%
% Function to create individual point clouds in Matlab
% structure from an original point cloud segmented using the
% pcsegdist function
%
% Input :
% - labels array (output from pcsegdist)
% - the original pre-segmented point cloud
% - threshold number of inliers. Below this threshold will be considered as
% outliers
%
% Outputs:
% - Clusters: a struct with the inlier clusters as fields
% - stdummy: a list of the names of the clusters
%
% (c) Arnadi Murtiyoso (INSA Strasbourg - ICube-TRIO UMR 7357)
clear Clusters
% tic
%Look for unique labels
a = unique(labels);
[numClusters,~] =size (a);
%...create a table with name of label and frequency
table = [a,histc(labels(:),a)];
%filtering for outliers
for i=1:numClusters
numPts = table (i,2);
if numPts < inlierNb
%If it's outlier, fill with zeros
table(i,:)=[0,0];
end
end
%Delete the zeros rows
table( ~any(table,2), : ) = [];
[numrowTable,~] =size (table);
% disp('Lookup table created successfully');
% toc
% tic
f = waitbar(0,'Creating individual point cloud clusters...');
%create dummy for struct field names
stdummy=strings(numrowTable,1);
for i=1:numrowTable
waitbar(i/numrowTable,f)
%create dummy for point cloud data
pcdummy=zeros(table(i,2),3);
%find row indexes for label in table(i,1)
rows = find(labels(:,1)==table(i,1));
%transfer the point cloud coordinates to the dummy
[numPts2,~]=size(pcdummy);
for j=1:numPts2
pcdummy(j,:)=pointcloud.Location(rows(j,1),:);
end
%convert pcdummy to point cloud class
PtCloud=pointCloud(pcdummy);
%Fill the string dummy with struct field names
stdummy(i,1) = strcat('PtCloud',num2str(table(i,1)));
%Plot the cluster individually
% figure('Name',strcat('PtCloud',num2str(i)))
% pcshow(PtCloud);
% title(strcat('Cluster',{' '}, num2str(table(i,1))));
%Create the struct containing inlier clusters
Clusters.(stdummy{i}) = PtCloud;
end
close(f);
disp('[DING!]Clusters created successfully');
% toc