1 clear; 2 clc; 3 width=3; 4 xwidth=(width-1)/2; 5 imgn=imread('1.bmp'); 6 imshow(imgn,[]); 7 imgn=double(imgn); 8 [m n]=size(imgn); 9 imgn1=imgn; 10 z=zeros(4,width); 11 tem=1; 12 for i=1+x1:m-xwidth 13 for j=1+x1:n-xwidth 14 15 for k=-x1:xwidth 16 z(1,tem)=imgn(i,j+k); 17 z(2,tem)=imgn(i+k,j); 18 z(3,tem)=imgn(i-k,j+k); 19 z(4,tem)=imgn(i+k,j+k); 20 tem=tem+1; 21 end 22 z1=mean(z(1,:)); 23 z2=mean(z(2,:)); 24 z3=mean(z(3,:)); 25 z4=mean(z(4,:)); 26 tem=1; 27 28 % z1=mean([imgn(i,j-1),imgn(i,j),imgn(i,j+1)]); 29 % z2=mean([imgn(i-1,j),imgn(i,j),imgn(i+1,j)]); 30 % z3=mean([imgn(i+1,j-1),imgn(i,j),imgn(i-1,j+1)]); 31 % z4=mean([imgn(i-1,j-1),imgn(i,j),imgn(i+1,j+1)]); 32 33 imgn1(i,j)=max([z1,z2,z3,z4]); 34 end 35 end 36 figure,imshow(imgn1,[]);