function [ corners ] = segmentCriterion( img, threshold,n )
% Hassan Nahas
%This function is an optimal segment test that utilizes matrix efficiency.
    numOfConsequitiveBrightPixels = ones(size(img,1),size(img,2));
%     previousnumOfConsequitiveBrightPixels = zeros(size(img,1),size(img,2));
    allF = extractFeatureVector(img,threshold);
%     onlyBrighter = allF > 0;
%     cleanSlate = zeros(size(img,1),size(img,2));
    for x = [1:16,1:n]
        
        previous = x -1;
        if (previous == 0)
           previous = 16; 
        end
        thisframe = allF(:,:,x);
%         numOfConsequitiveBrightPixels = previousnumOfConsequitiveBrightPixels + thisframe;
%         numOfConsequitiveBrightPixels(numOfConsequitiveBrightPixels == previousnumOfConsequitiveBrightPixels) = 0;
        numOfConsequitiveBrightPixels(allF(:,:,previous) == allF(:,:,x)) = numOfConsequitiveBrightPixels(allF(:,:,previous) == allF(:,:,x)) + abs(thisframe(allF(:,:,previous) == allF(:,:,x)));
        numOfConsequitiveBrightPixels(allF(:,:,previous) ~= allF(:,:,x)) = 0;
%         previousnumOfConsequitiveBrightPixels = numOfConsequitiveBrightPixels;
    end
    
    corners = numOfConsequitiveBrightPixels > n;

end

