forked from vedaldi/practical-object-category-detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
detectAtMultipleScales.m
44 lines (35 loc) · 1016 Bytes
/
detectAtMultipleScales.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
function detection = detectAtMultipleScales(im, w, hogCellSize, scales)
modelWidth = size(w, 2) ;
modelHeight = size(w, 1) ;
bestScore = -inf ;
minScore = +inf ;
maxScore = -inf ;
h = [] ;
for s = scales
% scale image
t = imresize(im, 1/s) ;
% extract HOG features
hog = vl_hog(t, hogCellSize) ;
% convolve model
scores = vl_nnconv(hog, w, []) ;
% pick best response
[score, index] = max(scores(:)) ;
if score > bestScore
bestScore = score ;
[hy, hx] = ind2sub(size(scores), index) ;
x = (hx - 1) * hogCellSize * s + 1 ;
y = (hy - 1) * hogCellSize * s + 1 ;
detection = [
x - 0.5 ;
y - 0.5 ;
x + hogCellSize * modelWidth * s - 0.5 ;
y + hogCellSize * modelHeight * s - 0.5 ;] ;
end
% plot score map
vl_tightsubplot(numel(scales),find(s==scales)) ;
imagesc(scores) ; axis off square ;
h(end+1) = gca;
minScore = min([minScore;scores(:)]) ;
maxScore = max([maxScore;scores(:)]) ;
end
set(h, 'clim', [minScore, maxScore]) ;