function [ response ] = classifyImageAccordingToSUSAN( image, radius, t , g)
% Hassan Nahas
%This function provides a 'slow' implementation of the SUSAN detector on a
%pixel by pixel basis similar to the only feasible implementation of FAST
%so a valid comparison in time can be made.

    imageSizeX = 2*radius+1;
    imageSizeY = 2*radius+1;
    [columnsInImage, rowsInImage] = meshgrid(1:imageSizeX, 1:imageSizeY);
    centerX = radius+1;
    centerY = radius+1;
    

    circlePixels = (rowsInImage - centerY).^2 ...
        + (columnsInImage - centerX).^2 <= radius.^2;
    circlePixels = double(circlePixels);
    if g < 1
        g = g* sum(sum(circlePixels));
    end
    circlePixels(circlePixels == 0) = NaN;
%     image(circlePixels) ;
    image = image(:,:,1);
    response = zeros(size(image));
    for x = 1+radius:size(image,1)-radius
        for y = 1+radius:size(image,2)-radius
            centerValue = image(x, y);
            rectneighborhood = image(x - radius:x + radius, y - radius: y + radius);
            circleNeighbourhood = circlePixels .*rectneighborhood;
%             circleNeighbourhood(circleNeighbourhood == 0 ) = NaN;
            diffPixels = abs(circleNeighbourhood - centerValue);
            similarPixels = zeros(size(rectneighborhood));
            similarPixels(diffPixels < t) = 1;
            n = 0;
            
            for i = 1: size(similarPixels,1)
               for j = 1:size(similarPixels,2)
                   n = n + similarPixels(i,j);
               
                   
            end
%             n = sum(sum(similarPixels));
            
            if (n < g ) 
                response(x,y) = g - n;
            else
                response(x,y) = 0;
            end
            
            
            
            %             neighborhoodup = image(x - window_halfsize:x + window_halfsize, y - window_halfsize: y + window_halfsize);
            
%             
            end
    end
    response =  response* 200/max(response(:));
%     response(response < 0) = 0;
end

