forked from vlfeat/vlbenchmarks
/
eval_mh.m
208 lines (171 loc) · 6.88 KB
/
eval_mh.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
function eval_mh()
import datasets.*;
import benchmarks.*;
import localFeatures.*;
set(0,'DefaultFigureVisible','off');
%dataset_name = 'oxford';
dataset_name = 'dtu';
if strcmp(dataset_name, 'oxford')
categories = datasets.VggAffineDataset.AllCategories;
elseif strcmp(dataset_name, 'dtu')
categories = datasets.DTURobotDataset.AllCategories;
else
error('invalid dataset name')
end
for category_idx = 1:numel(categories)
category_name = categories{category_idx};
if strcmp(dataset_name, 'oxford')
dataset = datasets.VggAffineDataset('Category', category_name);
else strcmp(dataset_name, 'dtu')
dataset = datasets.DTURobotDataset('Category','arc2');
end
% --------------------------------------------------------------------
% PART 1: Detector repeatability
% --------------------------------------------------------------------
vlcovdetDetector = VlFeatCovdet()
siftDetector = VlFeatSift();
mhDetector = MultiscaleHarris();
mhDetector.Opts.localization = 1;
mh_woDetector = MultiscaleHarris();
mh_woDetector.Opts.localization = 0;
lcDetector = LindebergCorners();
lcDetector.Opts.localization = 1;
lc_woDetector = LindebergCorners();
lc_woDetector.Opts.localization = 0;
mser = VlFeatMser();
repBenchmark = RepeatabilityBenchmark('Mode','Repeatability');
featExtractors = {vlcovdetDetector, siftDetector, mser, lcDetector, lc_woDetector, mhDetector, mh_woDetector};
detectorNames = {'VLCovDet', 'VLSIFT', 'MSER', 'LC w. localization', 'LC w.o. localization', 'MH w. localization', 'MH w.o. localization'};
% featExtractors = {mh_woDetector};
% detectorNames = {'MH w.o. localization'};
repeatability = [];
numCorresp = [];
for d = 1:numel(featExtractors)
% use a maximum of three scenes for this demo.
scenes = dataset.NumScenes;
for sceneNo = 1:scenes
for labelNo = 1:dataset.NumLabels
img_ref_id = dataset.getReferenceImageId(labelNo, sceneNo);
img_id = dataset.getImageId(labelNo, sceneNo);
[repeatability(d, labelNo, sceneNo) numCorresp(d, labelNo, sceneNo)] = ...
repBenchmark.testFeatureExtractor(featExtractors{d}, dataset, ...
img_ref_id, img_id);
end
end
end
printScores(detectorNames, 100 * repeatability, 'Repeatability');
printScores(detectorNames, numCorresp, 'Number of correspondences');
figure(2); clf;
plotScores(detectorNames, dataset, 100 * repeatability, 'Repeatability');
printFigure(['results_' dataset_name], [category_name '_repeatability']);
figure(3); clf;
plotScores(detectorNames, dataset, numCorresp, 'Number of correspondences');
printFigure(['results_' dataset_name], [category_name '_num-correspondences']);
% --------------------------------------------------------------------
% PART 2: Detector matching score
% --------------------------------------------------------------------
vlcovdetWithSift = DescriptorAdapter(vlcovdetDetector, siftDetector);
mserWithSift = DescriptorAdapter(mser, siftDetector);
mhWithSift = DescriptorAdapter(mhDetector, siftDetector);
mh_woWithSift = DescriptorAdapter(mh_woDetector, siftDetector);
lcWithSift = DescriptorAdapter(lcDetector, siftDetector);
lc_woWithSift = DescriptorAdapter(lc_woDetector, siftDetector);
featExtractors = {vlcovdetWithSift, siftDetector, mserWithSift, mhWithSift, mh_woWithSift, lcWithSift, lc_woWithSift};
detectorNames = {'VLCovDet', 'SIFT', 'MSER', 'LC w. localization', 'LC w.o. localization', 'MH w. localization', 'MH w.o. localization'};
matchingBenchmark = RepeatabilityBenchmark('Mode','MatchingScore');
matchScore = [];
numMatches = [];
for d = 1:numel(featExtractors)
% use a maximum of three scenes for this demo.
scenes = dataset.NumScenes;
for sceneNo = 1:scenes
for labelNo = 1:dataset.NumLabels
img_ref_id = dataset.getReferenceImageId(labelNo, sceneNo);
img_id = dataset.getImageId(labelNo, sceneNo);
[matchScore(d, labelNo, sceneNo) numMatches(d, labelNo, sceneNo)] = ...
matchingBenchmark.testFeatureExtractor(featExtractors{d}, ...
dataset, img_ref_id, img_id);
end
end
end
printScores(detectorNames, matchScore*100, 'Match Score');
printScores(detectorNames, numMatches, 'Number of matches') ;
figure(5); clf;
plotScores(detectorNames, dataset, matchScore*100,'Matching Score (with SIFT description)');
printFigure(['results_' dataset_name], [category_name '_matching_score']);
figure(6); clf;
plotScores(detectorNames, dataset, numMatches,'Number of matches (with SIFT description)');
printFigure(['results_' dataset_name], [category_name '_num-matches']);
end % dataset category
% --------------------------------------------------------------------
% Helper functions
% --------------------------------------------------------------------
function printScores(detectorNames, scores, name)
numDetectors = numel(detectorNames);
maxNameLen = length('Method name');
for k = 1:numDetectors
maxNameLen = max(maxNameLen,length(detectorNames{k}));
end
fprintf(['\n', name,':\n']);
formatString = ['%' sprintf('%d',maxNameLen) 's:'];
fprintf(formatString,'Method name');
for k = 2:size(scores,2)
fprintf('\tImg#%02d',k);
end
fprintf('\n');
for k = 1:numDetectors
fprintf(formatString,detectorNames{k});
for l = 2:size(scores,2)
fprintf('\t%6s',sprintf('%.2f',scores(k,l)));
end
fprintf('\n');
end
end
function plotScores(detectorNames, dataset, score, titleText)
xstart = 1;
xend = size(score,2);
if ndims(score) == 2
plot(xstart:xend,score(:,xstart:xend)','+-','linewidth', 2); hold on ;
else
score_std = std(score,0,3);
score = mean(score,3);
X = repmat(xstart:xend,[size(score, 1) 1])';
Y = score(:,xstart:xend)';
E = score_std(:,xstart:xend)';
errorbar(X,Y,E,'+-','linewidth', 2); hold on ;
end
xLabel = dataset.ImageNamesLabel;
xTicks = dataset.ImageNames;
plot(xstart:xend,score(:,xstart:xend)','+-','linewidth', 2); hold on ;
ylabel(titleText) ;
xlabel(xLabel);
set(gca,'XTick',xstart:1:xend);
set(gca,'XTickLabel',xTicks);
title(titleText);
set(gca,'xtick',1:size(score,2));
maxScore = max([max(max(score)) 1]);
meanEndValue = mean(score(:,xend));
legendLocation = 'SouthEast';
if meanEndValue < maxScore/2
legendLocation = 'NorthEast';
end
legend(detectorNames,'Location',legendLocation);
grid on ;
axis([xstart xend 0 maxScore]);
end
end
function printFigure(path, fileName, R, ext)
if isempty(path), return; end;
if ~exist(path, 'dir')
mkdir(path) ;
end
if ~exist('R','var')
R = 0.75;
end
vl_printsize(gcf, R) ;
if ~exist('ext','var')
ext = 'pdf';
end
filePath = fullfile(path, [fileName '.' ext]) ;
saveas(gcf, filePath, ext)
end