% file: task16.m
% moving average for 2D signals == images
I = imread('cameraman.tif');
figure(5); clf;
imshow(I);

I  = double(I);
J  = zeros(size(I));
for r = 2 : size(I,1)-1
    for c = 2 : size(I,2)-1
        J(r,c) = (1/9) * ...
            (I(r-1,c-1) + I(r-1, c) + I(r-1, c+1) + ...
            I(r, c-1) + I(r, c) + I(r, c+1) + ...
            I(r+1, c-1) + I(r+1, c) + I(r+1, c+1));
    end;
end;
figure(6); clf;
imshow(J, [0 255]);
% DEMO OF NOISE REDUCTION: nrfiltdemo
