-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisualizemodel.m
93 lines (82 loc) · 1.94 KB
/
visualizemodel.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
function visualizemodel(model, components)
% visualizemodel(model)
% Visualize a model.
clf;
if nargin < 2
components = 1:model.numcomponents;
end
k = 1;
for i = components
visualizecomponent(model, i, length(components), k);
k = k+1;
end
function visualizecomponent(model, c, nc, k)
% make picture of root filter
pad = 2;
bs = 20;
w = foldHOG(model.rootfilters{model.components{c}.rootindex}.w);
scale = max(w(:));
im = HOGpicture(w, bs);
im = imresize(im, 2);
im = padarray(im, [pad pad], 0);
im = uint8(im * (255/scale));
% draw root
numparts = length(model.components{c}.parts);
if numparts > 0
subplot(nc,3,1+3*(k-1));
else
subplot(nc,1,k);
end
imagesc(im)
colormap gray;
axis equal;
axis off;
% draw parts and deformation model
if numparts > 0
def_im = zeros(size(im));
def_scale = 500;
for i = 1:numparts
% part filter
w = model.partfilters{model.components{c}.parts{i}.partindex}.w;
p = HOGpicture(foldHOG(w), bs);
p = padarray(p, [pad pad], 0);
p = uint8(p * (255/scale));
% border
p(:,1:2*pad) = 128;
p(:,end-2*pad+1:end) = 128;
p(1:2*pad,:) = 128;
p(end-2*pad+1:end,:) = 128;
% paste into root
def = model.defs{model.components{c}.parts{i}.defindex};
x1 = (def.anchor(1)-1)*bs+1;
y1 = (def.anchor(2)-1)*bs+1;
x2 = x1 + size(p, 2)-1;
y2 = y1 + size(p, 1)-1;
im(y1:y2, x1:x2) = p;
% deformation model
probex = size(p,2)/2;
probey = size(p,1)/2;
for y = 2*pad+1:size(p,1)-2*pad
for x = 2*pad+1:size(p,2)-2*pad
px = ((probex-x)/bs);
py = ((probey-y)/bs);
v = [px^2; px; py^2; py];
p(y, x) = def.w * v * def_scale;
end
end
def_im(y1:y2, x1:x2) = p;
end
% plot parts
subplot(nc,3,2+3*(k-1));
imagesc(im);
colormap gray;
axis equal;
axis off;
% plot deformation model
subplot(nc,3,3+3*(k-1));
imagesc(def_im);
colormap gray;
axis equal;
axis off;
end
% set(gcf, 'Color', 'white')