forked from gercop2000/SpaTIL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getIntersectionGroups.m
72 lines (53 loc) · 2.06 KB
/
getIntersectionGroups.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 [features,featureNames] = getIntersectionGroups(groups)
%GETGROUPINTERSECTION Summary of this function goes here
% Detailed explanation goes here
features=[];
featureNames={};
numGroups=length(groups);
comb = combnk(1:numGroups,2);
numComb=size(comb,1);
polygons=struct;
for i=1:numGroups
col = groups(i).clusterCentroids(:,1);
row = groups(i).clusterCentroids(:,2);
if length(col)>2
[ch,a] = convhull(col,row);
polygons(i).coords=[col(ch) row(ch)];
polygons(i).area=a;
else
polygons(i).coords=[];
polygons(i).area=0;
end
%plot(col(ch),row(ch),'yellow','LineWidth',5);
end
for i=1:numComb
gr1=comb(i,1);
gr2=comb(i,2);
pol1=polygons(gr1).coords;
pol2=polygons(gr2).coords;
if ~isempty(pol1) && ~isempty(pol2)
polyout = intersect([polyshape(pol1) polyshape(pol2)]);
int=polyarea(polyout.Vertices(:,1),polyout.Vertices(:,2));
in1=inpolygon(groups(gr1).clusterCentroids(:,1),...
groups(gr1).clusterCentroids(:,2),pol2(:,1),pol2(:,2));
in2=inpolygon(groups(gr2).clusterCentroids(:,1),...
groups(gr2).clusterCentroids(:,2),pol1(:,1),pol1(:,2));
avgArea=(polygons(gr1).area+polygons(gr2).area)/2;
features=[features...
int int/polygons(gr1).area int/polygons(gr2).area...
int/avgArea sum(in1) sum(in2)];
else
features=[features 0 0 0 0 0 0];
end
strGr1=num2str(gr1);
strGr2=num2str(gr2);
featureNames=horzcat(featureNames,{...
['IntersectionArea_G' strGr1 '&' strGr2],...
['RatioIntersectedArea_G' strGr1 '&' strGr2 '_ToArea_G' strGr1],...
['RatioIntersectedArea_G' strGr1 '&' strGr2 '_ToArea_G' strGr2],...
['RatioIntersectedArea_G' strGr1 '&' strGr2 '_ToAvgArea_G' strGr1 '&' strGr2],...
['NumCentroidsClusters_G' strGr1 '_InConvHull_G' strGr2],...
['NumCentroidsClusters_G' strGr2 '_InConvHull_G' strGr1]...
});
end
end