%
% erosion filter
%

close all;
clear all;

%load image
i=imread('noise_2.gif');

% create second image
im = i;

% show original image
figure;imshow(i);

% get image size
siz=size(i);

%do erosion
for j=[2:siz(2)-1]
    for k=[2:siz(1)-1]
        mat = [i(j-1,k-1),i(j-1,k),i(j-1,k+1), i(j,k-1),i(j,k),i(j,k+1),i(j+1,k-1),i(j+1,k),i(j+1,k+1)];
        im(j,k) = min(mat);
    end
end

% show image after erosion
figure;imshow(im);