function [ response ] = classifyImageAccordingToHarris( image, window_halfsize, alpha )
% Hassan Nahas
%This function provides a 'slow' implementation of the harris detector on a
%pixel by pixel basis similar to the only feasible implementation of FAST
%so a valid comparison in time can be made.
    window = gausswin(window_halfsize*2+1);
    window = repmat(window,1,window_halfsize*2 + 1).*repmat(window',window_halfsize*2 + 1,1);
    window = window / sum(sum(window));
    image = image(:,:,1);
    response = zeros(size(image));
    Iy = -[image(2:end,:);zeros(1,size(image,2))] + image;
    Ix = [image(:,2:end),zeros(size(image,1),1)] - image;
    for x = 1+window_halfsize:size(image,1)-window_halfsize
        for y = 1+window_halfsize:size(image,2)-window_halfsize
%             neighborhood = image(x - window_halfsize:x + window_halfsize, y - window_halfsize: y + window_halfsize);
%             neighborhoodup = image(x - window_halfsize:x + window_halfsize, y - window_halfsize: y + window_halfsize);
            playground = zeros(window_halfsize*2+1,window_halfsize*2+1,4);
            
            playground(:,:,1) = Ix(x - window_halfsize:x + window_halfsize, y - window_halfsize: y + window_halfsize).^2;
            playground(:,:,2) = Ix(x - window_halfsize:x + window_halfsize, y - window_halfsize: y + window_halfsize).*Iy(x - window_halfsize:x + window_halfsize, y - window_halfsize: y + window_halfsize);
            playground(:,:,3) = playground(:,:,2);
            playground(:,:,4) = Iy(x - window_halfsize:x + window_halfsize, y - window_halfsize: y + window_halfsize).^2;
            playground = playground.*repmat(window,1,1,4);
            A = zeros(2,2);
            A(1,1) = sum(sum(playground(:,:,1)));
            A(1,2) = sum(sum(playground(:,:,2)));
            A(2,1) = sum(sum(playground(:,:,3)));
            A(2,2) = sum(sum(playground(:,:,4)));
            response(x,y) = det(A) - alpha*trace(A)^2;
        end
    end
    response = 120*response/max(response(:));
    response(response < 0) = 0;
end

