% ==================================================================================================
% Module:   erode.m
%
% Usage:    Erode an image.
%
% Purpose: 
%     Erodes an image by a structuring element.
%
%     
% Input Variables:
%     fxy     input image (binary data)
%     B       structuring element
%     
% Returned Results:
%     The eroded image, fxy and a flag to indicate the result of the
%     operation. fxy is passed by reference.
%  
%     Produces return value as follows:
%       -1 if there is an error
%       0 if B is not contained in fxy
%       1 if B is contained in fxy
%     
% Restrictions/Notes:
%     This function is geared for binary images. It is assumed that B and fxy are the same size.
%     If the image to be eroded is larger than B then a subsection of the size of B should
%     be chosen and passed to erode().
%     
% See Also:
%       erosion()
%
% References:
%
% 
% Author:       Justin Ford
% Date:         2/1/04
% Revisions:    none
% ==================================================================================================


function contain = erode( fxy, B )

B_row_dim = size(B,1);
B_col_dim = size(B,2);

fxy_row_dim = size(fxy,1);
fxy_col_dim = size(fxy,2);

if ( (B_row_dim ~= fxy_row_dim) | (B_col_dim ~= fxy_col_dim) )
    contain = -1;
    error('Structuring element "B" must be of the equal dimension as image section "fxy"')
    return
end

row_dim = B_row_dim;
col_dim = B_col_dim;

for i = (1:B_row_dim)
    for j = (1:B_col_dim)
        if ( B(i,j) == 1 ) & ( fxy(i,j) == 0 )
            contain = 0;
            return
        end
    end
end

contain = 1;