1 cl; 2 img_gray=imread('fupeng.jpg'); 3 img_erzhi=imread('erzhi_fupeng.jpg'); 4 imshow(img_gray) 5 figure,imshow(img_erzhi) 6 [m n]=size(img_gray); 7 img_gray_fu=zeros(m,n); 8 img_gray_peng=zeros(m,n); 9 img_erzhi_fu=zeros(m,n); 10 img_erzhi_peng=zeros(m,n); 11 12 for i=2:m-1 13 for j=2:n-1 14 img_gray_fu(i,j)=min(min(img_gray(i-1:i+1,j-1:j+1))); 15 img_gray_peng(i,j)=max(max(img_gray(i-1:i+1,j-1:j+1))); 16 end 17 end 18 19 figure,imshow(uint8(img_gray_fu)); 20 figure,imshow(uint8(img_gray_peng)); 21 22 23 for i=2:m-1 24 for j=2:n-1 25 img_erzhi_fu(i,j)=min(min(img_erzhi(i-1:i+1,j-1:j+1))); 26 img_erzhi_peng(i,j)=max(max(img_erzhi(i-1:i+1,j-1:j+1))); 27 end 28 end 29 30 figure,imshow(uint8(img_erzhi_fu)); 31 figure,imshow(uint8(img_erzhi_peng));