% Hassan Nahas
%This script finds and plots the datapoints for the noise trend of FAST
%detectors, images in the dataset are corrupted with noise. Number of
%corners in every image is controlled at 500.
possibleSTDS = [0:5:25, 30:10:50];
[dataset,warps] = readDataset(mydirName);

noises = zeros(size(possibleSTDS));
repeatabilityOfCorners = noises;
% [~,cornerStrength_dt,~,~] = classifyDataSetAccordingToTree(dataset,Tree, 255,[]);
i = 1;
allT = ones(length(dataset),1)*200;
% possibleTrees = [9,12];
dataForThisExperiment = cell(length(possibleTrees),1);
j = 1;
legendlabels = [];
hold on;
for treeIndex = possibleTrees
    load(sprintf('Tree35-%d.mat',treeIndex));
%     numberOfCornersReal = zeros(size(possibleCorners));
    repeatabilityOfCorners = zeros(size(possibleSTDS));
%     [~,cornerStrength_dt,~,~] = classifyDataSetAccordingToTree(dataset,Tree, 255,[]);
    i = 1;
    allT = ones(length(dataset),1)*120;
for std = possibleSTDS
    tic;
    sprintf('Now doing std = %.3f',std)
    
    noisydataset = addNoiseToDataset(dataset,std);
    [~,cornerStrength_dt,~,~] = classifyDataSetAccordingToTree(noisydataset,Tree, 255,[]);
    %[ cornerMap_dt_nms ] = nonmaximalsuppression( cornersAnd );
    allT1 = getTforDataset( cornerStrength_dt, 500,allT ,5);
    
    
    [~,~,~,cornerMap_dt_nms] = classifyDataSetAccordingToTree(noisydataset,Tree, allT1,cornerStrength_dt);
    
    repeatabilityOfCorners(i) = evaluateDataset(cornerMap_dt_nms,warps,5);
%     numberOfCorners(i) = averageNumberOfCorners(cornerMap_dt_nms);
    
    i = i + 1;
    
    timeForCycle = toc;
    sprintf('Cycle took  %.3f seconds',timeForCycle)
end
%     dataForThisExperiment{j,1} = numberOfCornersReal;
    dataForThisExperiment{j,1} = repeatabilityOfCorners;
    j = j + 1;
    legendlabels = [legendlabels, sprintf('N = %d', treeIndex)];
    plot(possibleSTDS,repeatabilityOfCorners,'o-');
    
end

% legend(legendlabels)
xlabel('Noise Standard Deviation')
ylabel('Repeatability')
