function out = nms2(f,K)
%
% nms2: 2D non-maxima suppression
% On input:
%     f: 2D image
%     K: window size
% On output:
%     out: local maxima (in K by K window)
% Call:
%     out = nms2(f,K)
%

[m,n] = size(f);
out = zeros(n,m);
Kradius = (K-1)/2;
for i1 = Kradius+1:m-Kradius
  for j1 = Kradius+1:n-Kradius
     win = f(i1-Kradius:i1+Kradius,j1-Kradius:j1+Kradius);
     maxw = max(max(win));
     if f(i1,j1) >= maxw
	out(i1,j1) = f(i1,j1);
     end;
  end;
end;

