-
Notifications
You must be signed in to change notification settings - Fork 0
/
klPreprocee.m
71 lines (59 loc) · 1.44 KB
/
klPreprocee.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
function KLpre = klPreprocee(inPatt, G)
%
%by Yaoyi Li
%Feb 2015
constr21 = [0;0];
constr22 = [0;0];
for cntAnc = 1:numel(G{1}{1})
for cntTiles = 1:numel(G{1}{1}{cntAnc})
tmpConstr = G{1}{1}{cntAnc}{cntTiles};
if tmpConstr(1) ~= 0 && tmpConstr(2) ~= 0
constr21 = [constr21, tmpConstr'];
end
end
end
for cntAnc = 1:numel(G{1}{2})
for cntTiles = 1:numel(G{1}{2}{cntAnc})
tmpConstr = G{1}{2}{cntAnc}{cntTiles};
if tmpConstr(1) ~= 0 && tmpConstr(2) ~= 0
constr22 = [constr22, tmpConstr];
end
end
end
numCons21 = size(constr21, 2)-1;
numCons22 = size(constr22, 2)-1;
KLpre = [numCons21;numCons22];
KLpre = [KLpre, constr21(:,2:end), constr22(:,2:end)];
hist = zeros(1,numCons21+numCons22);
for cntFac = 1:numCons21
tmpFac = constr21(:, cntFac);
tmpFac = tmpFac';
for cntPatt = 1:numel(inPatt)
tmpPatt = inPatt{cntPatt};
[M, N] = size(tmpPatt);
for cntM = 2:M-1
for cntN = 2:N-2
if tmpPatt(cntM, cntN) == tmpFac(1) && tmpPatt(cntM, cntN+1) == tmpFac(2)
hist(cntFac) = hist(cntFac)+1;
end
end
end
end
end
for cntFac = 1:numCons22
tmpFac = constr22(:, cntFac);
for cntPatt = 1:numel(inPatt)
tmpPatt = inPatt{cntPatt};
[M, N] = size(tmpPatt);
for cntM = 2:M-2
for cntN = 2:N-1
if tmpPatt(cntM, cntN) == tmpFac(1) && tmpPatt(cntM+1, cntN) == tmpFac(2)
hist(cntFac+numCons21) = hist(cntFac+numCons21)+1;
end
end
end
end
end
hist = hist./sum(hist);
hist = [0, hist];
KLpre = [KLpre; hist];