-
Notifications
You must be signed in to change notification settings - Fork 2
/
plotClusters.m
153 lines (109 loc) · 3.51 KB
/
plotClusters.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
function plotClusters(image,coords,M,args)
%% Processing args
if ~isfield(args,'printGroupId')
args.printGroupId=false;
end
if ~isfield(args,'printCenter')
args.printCenter=false;
end
if ~isfield(args,'fillAlpha')
args.fillAlpha=.25;
end
if ~isfield(args,'lineWidth')
args.lineWidth=4;
end
if ~isfield(args,'lineAlpha')
args.lineAlpha=.5;
end
if ~isfield(args,'useBlackLine')
args.useBlackLine=true;
end
if ~isfield(args,'plotPoints')
args.plotPoints=false;
end
if ~isfield(args,'plotDelaunay')
args.plotDelaunay=false;
end
if ~isfield(args,'plotVoronoi')
args.plotVoronoi=false;
end
if ~isfield(args,'plotCenterGrouping')
args.plotCenterGrouping=false;
end
printGroupId=args.printGroupId;
fillAlpha=args.fillAlpha;
lineWidth=args.lineWidth;
lineAlpha=args.lineAlpha;
useBlackLine=args.useBlackLine;
plotPoints=args.plotPoints;
printCenter=args.printCenter;
plotVoronoi=args.plotVoronoi;
plotDelaunay=args.plotDelaunay;
plotCenterGrouping=args.plotCenterGrouping;
%%
colors={'b','y','g','r','c','m','w'};
numGroups=length(coords);
imshow(image);
hold on;
for k = 1:numGroups
matrix=M{k};
nodes=coords{k};
[~,~,clusters] = networkComponents(matrix);
clusters(cellfun(@length,clusters)<=2)=[];
numClusters=length(clusters);
cent=[];
for i = 1:numClusters
member = clusters{i};
col = nodes(member,1);
row = nodes(member,2);
[pol,a] = convhull(col,row);
%if a>30000
x=col(pol);
y=row(pol);
cent=[cent;[mean(x) mean(y)]];
s=plot(x,y,colors{k},'LineWidth',lineWidth);
s.Color(4)=lineAlpha;
if fillAlpha>0
f=fill(x,y,colors{k},'LineStyle','none');
set(f,'facealpha',fillAlpha)
end
if useBlackLine
plot(x,y,'k','LineWidth',1);
end
%end
end
if ~isempty(cent)
if printGroupId
text(cent(:,1),cent(:,2),num2str(k),'Color','black','FontSize',20);
end
if printCenter
scatter(cent(:,1),cent(:,2),100,[colors{k} 'o'],'filled');
end
if plotPoints
scatter(nodes(:,1),nodes(:,2),100,[colors{k+1} 'o'],'filled');
end
if plotDelaunay
DT=delaunay(cent(:,1),cent(:,2));
triplot(DT,cent(:,1),cent(:,2),'c-','LineWidth',3);
end
if plotVoronoi
[vx,vy]=voronoi(cent(:,1),cent(:,2));
plot(cent(:,1),cent(:,2),'g*',vx,vy,'g-','LineWidth',5);
end
if plotCenterGrouping
vect=getSumNodeWeightsThreshold( cent,'euclidean',.0005);
vect=normalizeVector(vect);
for i=1:size(cent,1)
hsl=getColorHeatMap(vect(i));
rgb=hsl2rgb(hsl);
plot(cent(i,1),cent(i,2),'or',...
'MarkerSize',15,...
'MarkerEdgeColor',[0,0,0],...
'MarkerFaceColor',[rgb(1,1,1),rgb(1,1,2),rgb(1,1,3)]);%,...
%text(nucleiCentroids(i,1),nucleiCentroids(i,2), sprintf('%d',i), 'Color', 'b')
end
end
end
end
hold off;
end