-
Notifications
You must be signed in to change notification settings - Fork 0
/
lmExtractorDHOGVL.m
executable file
·76 lines (63 loc) · 2.67 KB
/
lmExtractorDHOGVL.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
classdef lmExtractorDHOGVL < lmAExtractorLocalDescriptor
%LMEXTRACTORHOG Summary of this class goes here
% Detailed explanation goes here
properties
mCellSize;
mNumBin;
mWinSize;
mMaxSize;
end
methods
function obj = lmExtractorDHOGVL(windowSize,cellSize,bins,maxsize)
name = 'HOG';
description = 'Histogram of Oriented Gradients using vl library';
obj = obj@lmAExtractorLocalDescriptor(name,description);
obj.mNumBin = bins;
obj.mCellSize = cellSize;
obj.mWinSize = windowSize;
if exist('maxsize','var') && ~isempty(maxsize)
obj.mMaxSize = maxsize;
else
obj.mMaxSize = 0;
end
end
function [descriptors,locations,obj] = extractFromMat(obj,img,varargin)
maxs = max(size(img));
if obj.mMaxSize > 0 && maxs > obj.mMaxSize
img = imresize(img, obj.mMaxSize / maxs);
end
hd = vl_hog(im2single(img),obj.mCellSize,'NumOrientations',obj.mNumBin);
flen = size(hd,3);
fflen = flen * obj.mWinSize * obj.mWinSize;
descriptors = zeros(fflen,size(hd,1)*size(hd,2));
locations = zeros(2,size(hd,1)*size(hd,2));
cellLen = floor(obj.mCellSize/2);
winLen = floor(obj.mWinSize/2);
cellSize = obj.mCellSize;
di = 1;
for hy=1:size(hd,1)
for hx=1:size(hd,2)
fvec = zeros(fflen,1);
fi = 1;
for yy=hy-winLen:hy+winLen
for xx=hx-winLen:hx+winLen
if (xx < 1) || (xx>size(hd,2)) || (yy<1) || (yy>size(hd,1))
tmp = 0 * ones(flen,1);
else
tmp = hd(yy,xx,:);
end
%tmp = hd(iy,ix,:);
fvec(fi:fi+flen-1) = tmp(:);
fi = fi + flen;
end
end
py=min(size(img,1),(hy-1)*cellSize + 1 + cellLen);
px=min(size(img,2),(hx-1)*cellSize + 1 + cellLen);
descriptors(:,di) = fvec;
locations(:,di) = [px;py];
di = di + 1;
end
end
end
end
end