% Hassan Nahas
%This script finds and plots the datapoints for the repeatability vs number
%of corners for possibleTrees, which are loaded from the directory. 
possibleCorners = [50:500:2050];
[dataset,warps] = readDataset(mydirName);

dataForThisExperiment = cell(length(possibleTrees),2);
j = 1;
legendlabels = [];
hold on;
for treeIndex = possibleTrees
    load(sprintf('Tree35-%d.mat',treeIndex));
    numberOfCornersReal = zeros(size(possibleCorners));
    repeatabilityOfCorners = numberOfCornersReal;
    [~,cornerStrength_dt,~,~] = classifyDataSetAccordingToTree(dataset,Tree, 255,[]);
    i = 1;
    allT = ones(length(dataset),1)*120;
    for numberOfCorners = possibleCorners
        tic;
        sprintf('Now doing number of corners = %.3f',numberOfCorners)


        %[ cornerMap_dt_nms ] = nonmaximalsuppression( cornersAnd );
        allT = getTforDataset( cornerStrength_dt, numberOfCorners,allT,5 );


        [cornerMap_dt,~,~,cornerMap_dt_nms] = classifyDataSetAccordingToTree(dataset,Tree, allT,cornerStrength_dt);

        repeatabilityOfCorners(i) = evaluateDataset(cornerMap_dt_nms,warps,5);
        numberOfCornersReal(i) = averageNumberOfCorners(cornerMap_dt_nms);

        i = i + 1;

        timeForCycle = toc;
        sprintf('Cycle took  %.3f seconds',timeForCycle)
    end
    dataForThisExperiment{j,1} = numberOfCornersReal;
    dataForThisExperiment{j,2} = repeatabilityOfCorners;
    j = j + 1;
    legendlabels = [legendlabels, sprintf('N = %d', treeIndex)];
    plot(numberOfCornersReal,repeatabilityOfCorners,'o-');
    
end

% legend(legendlabels)
xlabel('Number Of Corners')
ylabel('Repeatability')
