% ==================================================================================================
% Module:   dilation.m
%
% Usage:    Erode an image.
%
% Purpose: 
%     Perform grayscale dilation on an image.  The dilation operation 
%     is performed by using the local maximum operator.
%
%     
% Input Variables:
%     fxy     input image subset (grayscale data)
%     SE      the structing element for the operation
%     
% Returned Results:
%     The mathematical morphological dilation of a grayscale image.
%  
% Restrictions/Notes:
%     This function is geared for grayscale images.  The structuring
%     element is assumed to be the "flat top" structuring element (all
%     elements are zero).
%     
% See Also:
%       erosion()
%
% References:
%
% 
% Author:       Justin Ford
% Date:         3/22/04
% Revisions:    none
% ==================================================================================================

function dilated = dilation(fxy, SE)

% Initialize result variable
dilated = 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,2) - col_diff )) )
            
            dilated(i,j) = max(max( fxy((i-row_diff):(i+row_diff),(j-col_diff):(j+col_diff)) ));
                        
        end
        
    end
end
