% A simple script file which loops detector and descriptor benchmarks 
% with different parameters
 
clear;
close all;

%SET FIRST THESE PARAMATERS TO TRUE FROM FILE mvpr_feature_extract_new.m
%conf.enforceFeatures = true;
%conf.enforceMatching = true;
timeFunction = 0;
timeFunction = tic;
global confParameter
global r q w t y;


confParameter = 1;

while confParameter < 10
% change global variables values which are then used in the loadConfigure.m
% file
%     w = 0.05 + (0.04-0.05).*rand(1,1)
%     r = floor(25 + (5-25).*rand(1,1))
%     q = floor(9 + (1-9).*rand(1,1))
%     t = 1.9 + (1.7-1.9).*rand(1,1)
%     y = 0.6 + (0.4-0.6).*rand(1,1)
    detectors_benchmark1;
    descriptors_benchmark1;
    confParameter = confParameter+1;
    close all;
end
confParameter = 1;

elapsed = toc(timeFunction);
display(['Elapsed time to compute file plotResults.m is ',...
    num2str(elapsed),' seconds.']);


%% Load data
% vlSift_vlSiftTemp = load('DetectorResults_vl_sift.mat');
% vlSift_vlSift = cell2mat(vlSift_vlSiftTemp.values);
% 
% vlSift_vlSiftTemp = load('DescriptorResults_vl_sift+vl_sift.mat');
% Desc_vlSift_vlSift = cell2mat(vlSift_vlSiftTemp.values);
% 
% 
% fsHesaff_fsSiftTemp = load('DetectorResults_fs_hesaff.mat');
% fsHesaff_fsSift = cell2mat(fsHesaff_fsSiftTemp.values);
% 
% fsHesaff_fsSiftTemp = load('DescriptorResults_fs_hesaff+fs_sift');
% Desc_fsHesaff_fsSift = cell2mat(fsHesaff_fsSiftTemp.values);
% 
% 
% vlDense_vlSiftTemp = load('DetectorResults_vl_dense.mat');
% vlDense_vlSift = cell2mat(vlDense_vlSiftTemp.values);
% 
% vlDense_vlSiftTemp = load('DescriptorResults_vl_dense+vl_sift.mat');
% Desc_vlDense_vlSift = cell2mat(vlDense_vlSiftTemp.values);
% 
% vlDense_GaborTemp = load('DescriptorResults_vl_dense+mvpr_sg.mat');
% Desc_vlDense_Gabor = cell2mat(vlDense_GaborTemp.values);
% 
% cvOrb_cvSiftTemp = load('DetectorResults_cv_orb.mat');
% cvOrb_cvSift = cell2mat(cvOrb_cvSiftTemp.values);
% 
% cvOrb_cvSiftTemp = load('DescriptorResults_cv_orb+cv_sift.mat');
% Desc_cvOrb_cvSift = cell2mat(cvOrb_cvSiftTemp.values);


%% DETECTOR PLOTTING
% Repeat Avg. Plot
% figure,
% hold on
% 
% repeatAvg = [vlSift_vlSift(:).repeat_avg]/100;
% numOfRegions = [vlSift_vlSift(:).corresp_avg]./repeatAvg;
% m = [repeatAvg; numOfRegions]';
% defaultVal = m(1,:);
% mnew = sortrows(m,2);
% h1 = plot(mnew(:,2),mnew(:,1),'r');
% defdot = plot(defaultVal(:,2), defaultVal(:,1),'-k.','markersize',20);
% 
% repeatAvg = [cvOrb_cvSift(:).repeat_avg]/100;
% numOfRegions = [cvOrb_cvSift(:).corresp_avg]./repeatAvg;
% m = [repeatAvg; numOfRegions]';
% defaultVal = m(6,:);
% mnew = sortrows(m,2);
% h4 = plot(mnew(:,2),mnew(:,1),'y');
% plot(defaultVal(:,2), defaultVal(:,1),'-k.','markersize',20);
% 
% repeatAvg = [fsHesaff_fsSift(:).repeat_avg]/100;
% numOfRegions = [fsHesaff_fsSift(:).corresp_avg]./repeatAvg;
% m = [repeatAvg; numOfRegions]';
% defaultVal = m(1,:);
% mnew = sortrows(m,2);
% h2 = plot(mnew(:,2),mnew(:,1),'b');
% plot(defaultVal(:,2), defaultVal(:,1),'-k.','markersize',20);
% 
% repeatAvg = [vlDense_vlSift(:).repeat_avg]/100;
% numOfRegions = [vlDense_vlSift(:).corresp_avg]./repeatAvg;
% m = [repeatAvg; numOfRegions]';
% defaultVal = m(1,:);
% mnew = sortrows(m,2);
% h3 = plot(mnew(:,2),mnew(:,1),'g');
% plot(defaultVal(:,2), defaultVal(:,1),'-k.','markersize',20);
% legend([h1,h2,h3,h4,defdot],'vl\_sift+vl\_sift','fs\_hesaff+fs\_sift','vl\_dense+vl\_sift', ...
%     'cv\_orb+cv\_sift','Default values');
% hleg1 = legend('vlSift+vlSift','fsHesaff+fsSift','vlDense+vlSift','cvOrb+cvSift');
% 
% xlabel('Number of detected features')
% ylabel('Average repeatability [%]: #(correspondences)/#(regions)')
% hold off

%% DETECTOR PLOTTING
% CORRESP. AVG. PLOT
% figure,
% hold on
% 
% repeatAvg = [vlSift_vlSift(:).repeat_avg]/100;
% numOfRegions = [vlSift_vlSift(:).corresp_avg]./repeatAvg;
% m = [vlSift_vlSift(:).corresp_avg; numOfRegions]';
% defaultVal = m(1,:);
% mnew = sortrows(m,2);
% h1 = plot(mnew(:,2),mnew(:,1),'r');
% defdot = plot(defaultVal(:,2), defaultVal(:,1),'-k.','markersize',20);
% 
% repeatAvg = [fsHesaff_fsSift(:).repeat_avg]/100;
% numOfRegions = [fsHesaff_fsSift(:).corresp_avg]./repeatAvg;
% m = [fsHesaff_fsSift(:).corresp_avg; numOfRegions]';
% defaultVal = m(1,:);
% mnew = sortrows(m,2);
% h2 = plot(mnew(:,2),mnew(:,1),'b');
% plot(defaultVal(:,2), defaultVal(:,1),'-k.','markersize',20);
% 
% repeatAvg = [vlDense_vlSift(:).repeat_avg]/100;
% numOfRegions = [vlDense_vlSift(:).corresp_avg]./repeatAvg;
% m = [vlDense_vlSift(:).corresp_avg; numOfRegions]';
% defaultVal = m(1,:);
% mnew = sortrows(m,2);
% h3 = plot(mnew(:,2),mnew(:,1),'g');
% plot(defaultVal(:,2), defaultVal(:,1),'-k.','markersize',20);
% legend([h1,h2,h3,defdot],'vlSift+vlSift','fsHesaff+fsSift','vlDense+vlSift', ...
%     'Default values');
% 
% xlabel('numOfFeatures')
% ylabel('corresp_avg')
% hold off
% 
figure,
hold on

%% DESCRIPTOR PLOTTING
% Mean value
% m = [Desc_vlSift_vlSift.means; Desc_vlSift_vlSift.numOfRegions]';
% defaultVal = m(1,:);
% defplot = plot(defaultVal(:,2), defaultVal(:,1),'-k.','markersize',20);
% mnew = sortrows(m,2);
% d1 = plot(mnew(:,2),mnew(:,1),'r');
% 
% m = [Desc_fsHesaff_fsSift.means; Desc_fsHesaff_fsSift.numOfRegions]';
% defaultVal = m(1,:);
% plot(defaultVal(:,2), defaultVal(:,1),'-k.','markersize',20);
% mnew = sortrows(m,2);
% d2 = plot(mnew(:,2),mnew(:,1),'b');
% 
% m = [Desc_vlDense_vlSift.means; Desc_vlDense_vlSift.numOfRegions]';
% defaultVal = m(1,:);
% plot(defaultVal(:,2), defaultVal(:,1),'-k.','markersize',20);
% mnew = sortrows(m,2);
% d3 = plot(mnew(:,2),mnew(:,1),'g');
% 
% m = [Desc_cvOrb_cvSift.means; Desc_cvOrb_cvSift.numOfRegions]';
% defaultVal = m(1,:);
% plot(defaultVal(:,2), defaultVal(:,1),'-k.','markersize',20);
% mnew = sortrows(m,2);
% d4 = plot(mnew(:,2),mnew(:,1),'y');
% 
% 
% xlabel('Number of detected features')
% ylabel('Mean #(correct matches) (K=1)')
% legend([d1,d2,d3,d4,defplot],'vlSift+vlSift','fsHesaff+fsSift','vlDense+vlSift', ...
%     'cv\_orb+cv\_sift','Default values');
% hold off


%% DESCRIPTOR PLOTTING
% dsift_means = [Desc_vlDense_vlSift.means];
% dsift_medians = [Desc_vlDense_vlSift.medians];
% 
% dgabor_means = [Desc_vlDense_Gabor.means];
% dgabor_medians = [Desc_vlDense_Gabor.medians];
% 
% figure,
% hold on
% h1 = plot([2 4 8 16 32], dsift_means,'r');
% h2 = plot([2 4 8 16 32], dgabor_means,'g');
% legend([h1,h2],'vlDense+vlSift','vlDense+Gabor');
% hold off
% 
% figure,
% hold on
% h1 = plot([2 4 8 16 32], dsift_medians,'r');
% h2 = plot([2 4 8 16 32], dgabor_medians,'g');
% legend([h1,h2],'vlDense+vlSift','vlDense+Gabor');
% hold off




