% ==================================================================================================
% Module:   erosion.m
%
% Usage:    Erode an image.
%
% Purpose: 
%     Erodes an image by a structuring element.
%
%     
% Input Variables:
%     fxy     input image (binary data)
%     SE      structuring element
%     
% Returned Results:
%    The image fxy eroded by SE. The returned image has the same dimensions
%    as fxy.
%     
% Restrictions/Notes:
%     This function is geared for binary images. fxy and SE can be of
%     different dimensions
%     
% See Also:
%       erode()
%
% References:
%
% 
% Author:       Justin Ford
% Date:         2/1/04
% Revisions:    none
% ==================================================================================================

function eroded = erosion(fxy, SE)

% Initialize result variable
eroded = zeros(size(fxy,1),size(fxy,2));

SE_row_dim=size(SE,1);
SE_col_dim=size(SE,2);

row_diff=(SE_row_dim - 1)/2;
col_diff=(SE_col_dim - 1)/2;

for i=1:1:size(fxy,1)
    for j=1:1:size(fxy,2)
        if ( (i > row_diff) & (i < ( size(fxy,1) - row_diff )) & (j > col_diff) & (j < ( size(fxy,1) - col_diff )) )
            
            eroded(i,j) = erode( fxy((i-row_diff):(i+row_diff),(j-col_diff):(j+col_diff)), SE );
                        
        end
        
    end
end
