-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgetLabelGraph.m
More file actions
35 lines (26 loc) · 754 Bytes
/
getLabelGraph.m
File metadata and controls
35 lines (26 loc) · 754 Bytes
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
function [graphG] = getLabelGraph(labels,labelCount)
allMatrix = zeros(labelCount, labelCount);
[rowCount,columnCount] = size(labels);
for r=1:rowCount-1
for c=1:columnCount-1
tmpCurr = labels(r,c);
tmpNext = labels(r,c+1);
if tmpCurr ~= tmpNext
allMatrix(tmpCurr, tmpNext) = 1;
allMatrix(tmpNext, tmpCurr) = 1;
end
tmpCurr = labels(r,c);
tmpNext = labels(r+1,c);
if tmpCurr ~= tmpNext
allMatrix(tmpCurr, tmpNext) = 1;
allMatrix(tmpNext, tmpCurr) = 1;
end
end
end
names = cell(labelCount,1);
for i=1:labelCount
names{i} = int2str(i);
end
graphG = graph(allMatrix);
graphG.Nodes.Name = names;
end