forked from gercop2000/SpaTIL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getSpaTILFeatures_v2.m
81 lines (59 loc) · 2.47 KB
/
getSpaTILFeatures_v2.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
73
74
75
76
77
78
79
80
81
function [ features,featureNames ] = getSpaTILFeatures_v2(coords,neigborhoodSize,alpha,r,groupingThreshold)
%% Parameter management
if nargin<2
neigborhoodSize=5;
end
if nargin<3
alpha=.42;
end
if nargin<4
r=.185;
end
if nargin<5
groupingThreshold=.0005;
end
%% Variable initialization
% This value defines the maximum number of close neighbors used to compute
% the intersection between clusters. It was set to 5 for performance.
maxNeigborsInters=5;
numGroups=length(coords);
featureNames=cell(1,numGroups);
clustPerGroup=zeros(1,numGroups);
%% Building clusters
groups=struct;
for i=1:numGroups
groups(i).nodes=coords{i};
edges = getCCGEdges(struct('centroid_r',coords{i}(:,2)','centroid_c',coords{i}(:,1)'), alpha, r);
[~,~,groups(i).clusters] = networkComponents(edges);
% Discarding clusters with less than 3 nodes
groups(i).clusters(cellfun(@length,groups(i).clusters)<=2)=[];
% Getting cluster properties (centroids, polygons, areas, and densities)
[groups(i).clusterCentroids,groups(i).clusterPolygons,...
groups(i).areas,groups(i).densities]=getClusterProperties(groups(i).clusters,groups(i).nodes);
% Getting clusters by group
clustPerGroup(i)=length(groups(i).clusters);
featureNames{i}=['NumClusters_G' num2str(i)];
end
%% Identifying closest neighbors per group
for i=1:numGroups
groups(i).neighborsPerGroup=getClosestNeighborsByGroup(groups,i);
end
%% Identifying absolute closest neighbors
maxNumClust=max(clustPerGroup);
for i=1:numGroups
groups(i).absoluteClosest=getAbsoluteClosestNeighbors(groups,i,maxNumClust);
end
%% Extracting cluster-related features
[densFeat,densFeatNames]=getClusterDensityMeasures_v2(groups);
[intersClustFeat,intersClustFeatNames]=getClusterIntersectionMeasures(groups,maxNeigborsInters);
[richFeat,richFeatNames]=getNeighborhoodMeasures(groups,neigborhoodSize,maxNumClust);
%% Extracting group-related features
[graphFeat,graphFeatNames]=getGraphFeatures(groups);
[intersGroupFeat,intersGroupFeatNames]=getIntersectionGroups(groups);
[groupingFeat,groupingFeatNames]=getGroupingFactorByGroup(groups,groupingThreshold);
%% Compiling features%
features=[clustPerGroup,densFeat,intersClustFeat,richFeat,graphFeat,...
intersGroupFeat,groupingFeat];
featureNames=[featureNames,densFeatNames,intersClustFeatNames,...
richFeatNames,graphFeatNames,intersGroupFeatNames,groupingFeatNames];
end