%
% out = rpeak(in)
%
% This function takes an input matrix, scans over the entire image in
% 1x3 blocks, and returns only local peaks into the output matrix while
% zeroing out everything else.
%
% Developed by  Andy Doran
%               Rice University
% 		April, 1999
%

function out = rpeak(in)

% Get dimensions of input image
[x,y] = size(in);

% Initialize output image
out = zeros(x,y);

% Pad input image to handle edges
pad = zeros(x+2,y+2);
pad(2:x+1,2:y+1) = in;

% Perform peak finding operation across rows
for m = 1:x
  for n = 1:y
    mini = pad(m+1,n:n+2);
    biggest = max(mini);
    if (pad(m+1,n+1) == biggest)
      out(m,n) = biggest;
    end
  end
end

