f=imread('fig5.jpg');
f=double(f);
[m,n]=size(f);
g=zeros(m,n);
for x=2: m-1
for y=2: n-1
subimage=f(x-1:x+1,y-1:y+1);
g(x,y)=median(subimage(:));
h(x,y)=max(subimage(:));
i(x,y)=min(subimage(:));
end
end
f=mat2gray(f);
g=mat2gray(g);
h=mat2gray(h);
i=mat2gray(i);
%imshow(f);
%figure,imshow(g);
subplot(2,2,1),imshow(f),title('input image');
subplot(2,2,2),imshow(g),title('median filter');
subplot(2,2,3),imshow(h),title('max filter');
subplot(2,2,4),imshow(i),title('min filter');