1 cl; 2 3 img=imread(\'3.17.tif\'); 4 imgn=imnoise(img,\'salt & pepper\',0.02); 5 [m n]=size(img); 6 7 %h=fspecial(\'average\',[3 3]); % 3*3的均值滤波 8 %imgn1=imfilter(imgn,h,\'replicate\'); 9 10 %imgn=medfilt2(imgn,[3 3]); % 3*3的中值滤波 11 12 %%%%自己编写3*3均值滤波 13 %{ 14 tem=0; 15 for i=2:1:m-1 16 for j=2:1:n-1 17 18 for p=i-1:1:i+1 19 for q=j-1:1:j+1 20 tem=tem+double(imgn(p,q)); 21 end 22 end 23 24 tem=tem/9; 25 imgn(i,j)=tem; 26 tem=0; 27 end 28 end 29 %} 30 31 %%%%自己编写3*3中值滤波 32 %{ 33 s=zeros(1,9); 34 for i=2:1:m-1 35 for j=2:1:n-1 36 37 he=1; 38 for p=i-1:1:i+1 39 for q=j-1:1:j+1 40 s(he)=imgn(p,q); 41 he=he+1; 42 end 43 end 44 45 s=sort(s); 46 imgn(i,j)=s(5); 47 48 end 49 end 50 %} 51 imshow(imgn)