forked from cvondrick/ihog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualizeHOG.m
64 lines (53 loc) · 1.32 KB
/
visualizeHOG.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
% visualizeHOG(feat)
%
% This function provides a diagnostic visualization of a HOG feature. This is
% meant to be a drop-in replacement for the voc-release5 framework.
%
% Usage is simple:
% >> feat = features(im, 8);
% >> visualizeHOG(feat);
%
% and the current figure will contain both the standard HOG glyph visualization as well
% as the inverse.
%
% If 'feat' has negative values, a second row will appear of the negatives.
function out = visualizeHOG(feat, neg),
if ~exist('neg', 'var'),
neg = true;
end
if neg,
posfeat = max(feat, 0);
negfeat = max(-feat, 0);
else,
posfeat = feat;
negfeat = zeros(size(feat));
end
s = [size(feat,1)*8+16 size(feat,2)*8+16];
im = invertHOG(posfeat);
hog = showHOG(max(0, posfeat));
hog = imresize(hog, s);
hog(hog > 1) = 1;
hog(hog < 0) = 0;
buff = 5;
im = padarray(im, [buff buff], 0.5, 'both');
hog = padarray(hog, [buff buff], 0.5, 'both');
if any(negfeat(:) > 0),
hogneg = showHOG(max(0, negfeat));
hogneg = imresize(hogneg, s);
hogneg(hogneg > 1) = 1;
hogneg(hogneg < 0) = 0;
hogneg = padarray(hogneg, [buff buff], 0.5, 'both');
neg = invertHOG(max(-feat, 0));
neg = padarray(neg, [buff buff], 0.5, 'both');
im = [im; neg];
hog = [hog; hogneg];
end
im = [im hog];
if nargout == 0,
imagesc(im);
axis image;
axis off;
colormap gray;
else,
out = im;
end