-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhovwEncodingCustom.m
74 lines (52 loc) · 2.32 KB
/
hovwEncodingCustom.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
function [] = hovwEncodingCustom(params, training_set, query_set)
% HOVWENCODINGCUSTOM Histogram of Visual Words encoding. Creates histograms
% with codebook entries (visual words) frequencies by leaving one of the
% passes out.
% Authors: Jose Rivera-Rubio and Ioannis Alexiou
% {jose.rivera,ia2109}@imperial.ac.uk
%
% Initial version: April, 2014
% Last Modified: Otober, 2015
% CONSTANT PARAMETERS
selector = params.passes; % Leave one out strategy pass selector.
% Path strings, modify if NOT using the default suggested paths.
desc_str = 'C%dP%d_Descriptors.mat';
dict_str = 'dictionary_C%d_P%s.mat';
dict_path = fullfile(params.dictPath,num2str(params.dictionarySize));
% Construct dictionary path and load vocabulary.
c = ['C' num2str(params.corridors)];
dictionaries_path = fullfile(dict_path,params.descriptor,c);
training_set_str = sprintf('%d',training_set);
dict_fname_str = sprintf(dict_str,params.corridors,training_set_str);
load(fullfile(dictionaries_path,dict_fname_str)); % Load VWords
% Load query descriptors
for pass = query_set
p = ['P' num2str(pass)]; % pass string
descriptors_path = fullfile(params.descrDir,params.descriptor,c,p);
descriptors_fname_str = sprintf(desc_str,params.corridors,pass);
write_path = fullfile(dictionaries_path,...
['hovw_' params.encoding '_' c '_P' training_set_str '_' num2str(pass) '.mat']);
if (~exist(write_path, 'file'))
while true
try
load(fullfile(descriptors_path,descriptors_fname_str)); % Load DescriptorStack
break
catch
fail_msg = ['Failed to load descriptor ' c p];
disp(fail_msg);
end % end try/catch
end
% Encode descriptors with dictionary: vector quantisation
if strcmpi(params.descriptor,'SIFT')
fun_str = ['encode_hovw_' params.encoding '_sparse(VWords,DescriptorStack)'];
HoVW = eval(fun_str);
else
fun_str = ['encode_hovw_' params.encoding '(VWords,DescriptorStack)'];
HoVW = eval(fun_str);
end
save(write_path,'HoVW');
disp( ['Pass ' p]);
end
end % end pass for loop
disp(['All passes encoded for dictionary ' training_set_str ' and corridor ' c]);
end % end hovw_encoding