function f = ispeak(I,index_x, index_y, mask_size)
%I is the image
%index_x and index_y is the center of the mask
%mask_size is the size of the mask. should be odd number.

%boundary test
im_size = size(I);

if (index_x -1 < (mask_size - 1)/2) || (index_y -1 < (mask_size - 1)/2) || (im_size(1) - index_x < (mask_size-1)/2) || (im_size(2) - index_y < (mask_size-1)/2) 
    f = -1;
    return
end
    
step_size = (mask_size -1)/2;

%y-y-1
for k = 1:step_size
   if I(index_x, index_y - (k-1) )<= I(index_x, index_y - k)
       f = -1;
       return
   end
end
%y-y+1
for k = 1:step_size
   if I(index_x, index_y + (k-1) )<= I(index_x, index_y + k)
       f = -1;
       return
   end
end

%x-x-1
for k = 1:step_size
   if I(index_x - (k-1), index_y)<= I(index_x - k, index_y)
       f = -1;
       return
   end
end

%x-x+1
for k = 1:step_size
   if I(index_x + (k-1), index_y)<= I(index_x + k, index_y)
       f = -1;
       return
   end
end

%up-left diagonal
for k = 1:step_size
   if I(index_x - (k-1), index_y - (k-1))<= I(index_x - k, index_y - k)
       f = -1;
       return
   end
end

%lower-right diagonal
for k = 1:step_size
   if I(index_x + (k-1), index_y + (k-1))<= I(index_x + k, index_y + k)
       f = -1;
       return
   end
end

%up-right diagonal
for k = 1:step_size
   if I(index_x + (k-1), index_y - (k-1))<= I(index_x + k, index_y - k)
       f = -1;
       return
   end
end

%lower-left diagonal
for k = 1:step_size
   if I(index_x - (k-1), index_y + (k-1))<= I(index_x - k, index_y + k)
       f = -1;
       return
   end
end

f = 1;


end