-
Notifications
You must be signed in to change notification settings - Fork 14
/
initmodel.m
63 lines (50 loc) · 1.37 KB
/
initmodel.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
function model = initmodel(cls, pos, note, symmetry, sbin, sz)
% model = initmodel(cls, pos, note, symmetry, sbin, sz)
% Initialize model structure.
%
% If not supplied the dimensions of the model template are computed
% from statistics in the postive examples.
% pick mode of aspect ratios
h = [pos(:).y2]' - [pos(:).y1]' + 1;
w = [pos(:).x2]' - [pos(:).x1]' + 1;
xx = -2:.02:2;
filter = exp(-[-100:100].^2/400);
aspects = hist(log(h./w), xx);
aspects = convn(aspects, filter, 'same');
[peak, I] = max(aspects);
aspect = exp(xx(I));
% pick 20 percentile area
areas = sort(h.*w);
area = areas(floor(length(areas) * 0.2));
area = max(min(area, 5000), 3000);
% pick dimensions
w = sqrt(area/aspect);
h = w*aspect;
if nargin < 3
note = '';
end
% get an empty model
model = model_create(cls, note);
model.interval = 10;
if nargin < 4
symmetry = 'N';
end
% size of HOG features
if nargin < 5
model.sbin = 8;
else
model.sbin = sbin;
end
% size of root filter
if nargin < 6
sz = [round(h/model.sbin) round(w/model.sbin)];
end
% add root filter
[model, symbol, filter] = model_addfilter(model, zeros([sz 32]), symmetry);
% start non-terminal
[model, Q] = model_addnonterminal(model);
model.start = Q;
% add structure rule deriving only a root filter placement
model = model_addrule(model, 'S', Q, symbol, 0, {[0 0 0]});
% set detection window
model = model_setdetwindow(model, Q, 1, sz);