function [ T ] = determineTfromN( strengthMap,N, startingT,stepsize )
% Hassan Nahas
%This function varies the threshold for the image until the desired number
%of corners is reached, takes a strength map so can be generalized to any
%detector.
    thresholds = startingT:-stepsize:0;
    
%     i = 1;
    T = startingT;

%     previousThreshold = -1;
    
    corners = 0;
    for threshold = thresholds
        
        if (corners > N )
           continue 
        end
        strengthForThisT = strengthMap;
        strengthForThisT(strengthForThisT < threshold ) = 0;
%         strengthForThisT(strengthForThisT >= threshold ) = 1;
%         cornerMapForThisT = strengthMap >= threshold;
        cornerMapForThisT = nonmaximalsuppression(strengthForThisT);
        
        
        corners = sum(sum(cornerMapForThisT));
        T = threshold;

%         i = i + 1;
%         imagesc(cornerMap);
    end

end

