-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlearnclassthresh.m
68 lines (56 loc) · 2.23 KB
/
learnclassthresh.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
function [Hthreshholds, Vthreshholds] = learnclassthresh(examples, fulltemplates, numfilters)
Hthreshholds = ones(1,numfilters)*bitmax;
Vthreshholds = ones(1,numfilters)*bitmax;
stdv=50;
templatedim=300;
[Hfilters,Vfilters] = parsing.genfilterssimple(fulltemplates,numfilters);
[iO,jO,sO] = find(sparse(ones(templatedim,templatedim)));
templatedimensions = [iO,jO];
numrotations = 18;
index=1;
%fill the rest
for i=1:length(examples)
i
rawstrokes=examples{i};
bestHThresh = zeros(1,numfilters);
bestVThresh = zeros(1,numfilters);
for rotation=1:numrotations
%rotation
example = zeros(templatedim,templatedim,3);
%for all angles
angle = 2*pi/numrotations;
Rotate = [cos(angle), -sin(angle); sin(angle),cos(angle)];
for j = 1: length(rawstrokes)
rawstroke = rawstrokes{j};
rawstroke = Rotate * rawstroke;
rawstrokes{j} = rawstroke;
end
temp = parsing.fill(rawstrokes);
xfilled = temp(1,:);
yfilled = temp(2,:);
standevx = std(double(xfilled));
standevy = std(double(yfilled));
for j = 1: length(rawstrokes)
rawstroke = rawstrokes{j};
rawstroke(1,:) = rawstroke(1,:)*stdv/standevx;
rawstroke(2,:) = rawstroke(2,:)*stdv/standevy;
rawstrokes{j} = rawstroke;
end
temp = parsing.fill(rawstrokes);
xfilled = temp(1,:)+templatedim/2;
yfilled = temp(2,:)+templatedim/2;
for j=1:length(xfilled)
example(yfilled(j),xfilled(j), 1) = 1;
end
%end
tempthreshH = getFilterThreshH(example(:,:,1), Hfilters);
tempthreshV = getFilterThreshV(example(:,:,1), Vfilters);
if(sum(tempthreshH) + sum(tempthreshV)> sum(bestHThresh) + sum(bestVThresh))
bestHThresh=tempthreshH;
bestVThresh = tempthreshV;
end
end
Hthreshholds = min(Hthreshholds, bestHThresh);
Vthreshholds = min(Vthreshholds, bestVThresh);
end
end