% AVERAGEFILTER creates a two-dimensional averaging filter of a specific
% size with a specific size averaging rectangle in the middle.
%
% Usage: avfilt = averagefilter(imrow, imcol, rectrow, rectcol)
%
% Arguments:    imrow   - Row size of image
%               imcol   - Column size of image
%               rectrow - Row size of averaging rectangle
%               rectcol - Column size of averaging rectangle
%
% Returns:      avfilt  - Averaging filter image
%
% NOTE: imrow and imcol must be positive even ints
%       rectrow and rectcol must be positive odd ints
%
function avfilt = averagefilter(imrow, imcol, rectrow, rectcol)
    avfilt = zeros(imrow, imcol);            
    avfilt((imrow/2)-(rectrow-1)/2:(imrow/2)+(rectrow-1)/2, (imcol/2)-(rectcol-1)/2:(imcol/2)+(rectcol-1)/2) = ones(21);   
    avfilt = avfilt./(sum(sum(avfilt)));   