-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_features.m
73 lines (66 loc) · 2.38 KB
/
get_features.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
function x = get_features(im, features, cell_size, cos_window,w2c)
%GET_FEATURES
% Extracts dense features from image.
%
% X = GET_FEATURES(IM, FEATURES, CELL_SIZE)
% Extracts features specified in struct FEATURES, from image IM. The
% features should be densely sampled, in cells or intervals of CELL_SIZE.
% The output has size [height in cells, width in cells, features].
%
% To specify HOG features, set field 'hog' to true, and
% 'hog_orientations' to the number of bins.
%
% To experiment with other features simply add them to this function
% and include any needed parameters in the FEATURES struct. To allow
% combinations of features, stack them with x = cat(3, x, new_feat).
%
% Joao F. Henriques, 2014
% http://www.isr.uc.pt/~henriques/
%
% revised by: Yang Li, August, 2014
% http://ihpdep.github.io
if ~isstruct(features)
if strcmp(features,'hog')
feature.hog = true;
feature.hogcolor = false;
feature.gray = false;
feature.hog_orientations = 9;
elseif strcmp(features,'hogcolor')
feature.hog = false;
feature.hogcolor = true;
feature.gray = false;
feature.hog_orientations = 9;
elseif strcmp(features,'gray')
feature.hog = false;
feature.hogcolor = false;
feature.gray = true;
end
features = feature;
end
if features.hog
%HOG features, from Piotr's Toolbox
x = double(fhog(single(im) / 255, cell_size, features.hog_orientations));
x(:,:,end) = []; %remove all-zeros channel ("truncation feature")
end
if features.hogcolor
%HOG features, from Piotr's Toolbox
x = double(fhog(single(im) / 255, cell_size, features.hog_orientations));
x(:,:,end) = []; %remove all-zeros channel ("truncation feature")
sz = size(x);
im_patch = imresize(im, [sz(1) sz(2)]);
out_npca = get_feature_map(im_patch, 'gray', w2c);
out_pca = get_feature_map(im_patch, 'cn', w2c);
% out_pca = reshape(temp_pca, [prod(sz), size(temp_pca, 3)]);
x = cat(3,x,out_npca);
x = cat(3,x,out_pca);
end
if features.gray
%gray-level (scalar feature)
x = double(im) / 255;
x = x - mean(x(:));
end
%process with cosine window if needed
if ~isempty(cos_window)
x = bsxfun(@times, x, cos_window);
end
end