function LPM_BenchmarkTest(benchmarkSequence, frameDetector, showMatches,... showImBIdx, resultsPath, covDetMethod) % LPM_BENCHMARKTEST Runs the VL benchmark test for LPM comparison with % other descriptors. % % Input parameters: % benchmarkSequence % Name of the image sequence in the VGG Affine Testbed dataset % Allowed values: 'wall' | 'boat' | 'bark' | 'bikes' | 'trees' | % 'leuven' | 'ubc' | ('graf') % See http://www.vlfeat.org/benchmarks/doc.html#doc.datasets for more % info % % frameDetector % Name of the detector used in the benchmark test. % Supported detecors: ('SIFT') | 'MSER' | 'Covdet' % % showMatches % Boolean flag for displaying the matches found in the first image % and the image specified in showImPair. % Allowed values: true |(false) % % showImBIdx % Specifies for which image pair should the results be shown. % Allowed values: an integer from range [2,6] (2) % % resultsPath % Path to directory where the results should be stored. % % covDetMethod % Detector method used in Covdet. % Allowed values: % DoG:: % The Difference of Gaussians is an approximate version of the % multiscale trace of Laplacian operator [1]. % % Hessian:: % Determinant Hessian operator [2]. % % HessianLaplace:: % Determinant of Hessian for space localisation, trace of % Laplacian for scale detection [2]. % % HarrisLaplace:: % Harris cornerness measure for space localisation, trace % of Laplacian for scale detection [2]. % % MultiscaleHessian:: % Same as HessianLaplace, but Laplacian scale detection is not % performend (features are simply detected at multiple scales) % [2]. % % % REFERENCES:: % [1] D. G. Lowe, Distinctive image features from scale-invariant % keypoints. IJCV, vol. 2, no. 60, pp. 91-110, 2004. % % [2] K. Mikolajcyk and C. Schmid, An affine invariant interest % point detector. ICCV, vol. 2350, pp. 128-142, 2002. % % Author: Damian Matuszewski adapted the code by Karel Lenc and Andrea Vedaldi % if nargin < 6, covDetMethod = 'DoG'; end; if nargin < 5, resultsPath = ''; end; if nargin < 4, showImBIdx = '2'; end if nargin < 3, showMatches = false; end if nargin < 2, frameDetector = 'SIFT'; end if nargin < 1, benchmarkSequence = 'graf'; end; import localFeatures.*; import datasets.*; import benchmarks.*; % You can modify the parameters of the detectors/descriptors in the % constructor methods below siftDetector = VlFeatSift(); lpmDescriptor32 = LPMDescriptor('Sampling', 32); lpmDescriptor16 = LPMDescriptor('Sampling', 16); mserDetector = VlFeatMser('MinDiversity',0.5); covdetDetector = VlFeatCovdet('Method', covDetMethod); % Create an instance of the VGG Affine Testbed dataset = VggAffineDataset('category',benchmarkSequence); % define the detectors to be used in the comparison if strcmp(frameDetector, 'SIFT') detectors{1} = siftDetector; detectors{2} = DescriptorAdapter(siftDetector, lpmDescriptor32); detectors{3} = DescriptorAdapter(siftDetector, lpmDescriptor16); detectorNames = {'SIFT', ... 'SIFT frames + LPMx32', ... 'SIFT frames + LPMx16'}; elseif strcmp(frameDetector, 'MSER') detectors{1} = DescriptorAdapter(mserDetector, siftDetector); detectors{2} = DescriptorAdapter(mserDetector, lpmDescriptor32); detectors{3} = DescriptorAdapter(mserDetector, lpmDescriptor16); detectorNames = {'MSER frames + SIFT', ... 'MSER frames + LPMx32', ... 'MSER frames + LPMx16'}; elseif strcmp(frameDetector, 'Covdet') detectors{1} = DescriptorAdapter(covdetDetector, siftDetector); detectors{2} = DescriptorAdapter(covdetDetector, lpmDescriptor32); detectors{3} = DescriptorAdapter(covdetDetector, lpmDescriptor16); detectorNames = {[covDetMethod,' frames + SIFT'], ... [covDetMethod,' frames + LPMx32'], ... [covDetMethod,' frames + LPMx16'] }; else error('Invalid frame detector for testing!'); end % create a benchmark object matchBenchmark = RepeatabilityBenchmark('Mode','MatchingScore'); % run the benchmark matchScore = [] ; numMatches = [] ; for d = 1:numel(detectors) for i = 2:dataset.NumImages [matchScore(d,i), numMatches(d,i)] = ... matchBenchmark.testFeatureExtractor(detectors{d}, ... dataset.getTransformation(i), ... dataset.getImagePath(1), ... dataset.getImagePath(i)) ; end end % Print and plot the results printScores(detectorNames, matchScore*100, 'Match Score'); printScores(detectorNames, numMatches, 'Number of matches'); figure; subplot(1,2,1); plotScores(detectorNames, dataset, matchScore*100,'Matching Score'); subplot(1,2,2); plotScores(detectorNames, dataset, numMatches,'Number of matches'); helpers.printFigure(resultsPath,'matchingScore',0.6); % Show matches on the image B if showMatches [drop, drop, siftMatches, siftReprojFrames] = ... repBenchmark.testFeatureExtractor(siftDetector, ... dataset.getTransformation(showImBIdx), ... dataset.getImagePath(1), ... dataset.getImagePath(showImBIdx)) ; [drop, drop, lpm32Matches, lpm32ReprojFrames] = ... repBenchmark.testFeatureExtractor(lpmDescriptor32, ... dataset.getTransformation(showImBIdx), ... dataset.getImagePath(1), ... dataset.getImagePath(showImBIdx)) ; figure; image = imread(dataset.getImagePath(showImBIdx)); subplot(1,2,1); imshow(image); benchmarks.helpers.plotFrameMatches(siftMatches, siftReprojFrames,... 'IsReferenceImage',false); title(sprintf('SIFT matches with %d image (%s dataset).',... showImBIdx,dataset.DatasetName)); subplot(1,2,2); imshow(image); benchmarks.helpers.plotFrameMatches(lpm32Matches, lpm32ReprojFrames,... 'IsReferenceImage',false); % 'PlotMatchLine',false,... % 'PlotUnmatched',false); title(sprintf('LPM (32x32 sampling) matches with %d image (%s dataset).',... showImBIdx,dataset.DatasetName)); helpers.printFigure(resultsPath,'matches',0.75); end % -------------------------------------------------------------------- % 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 = max([find(sum(score,1) == 0, 1) + 1 1]); xend = size(score,2); 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