资源描述:
《《滤波源程序代码》word版》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、例8-2clearall;I=imread('circuit.tif');figure;subplot(221);imshow(I);subplot(222);imhist(I);I1=histeq(I);subplot(223);imshow(I1);subplot(224);imhist(I1);例8-4I=imread('circuit.tif');[M,N]=size(I);fori=1:8:257counts(i)=i;endQ=imread('circuit.tif');N=histeq(Q,counts);figure;subplot(22
2、1);imshow(N);subplot(222);imhist(N);axis([025605000]);例8-5clear;a=imread('coins.png');%读取图像anoised=imnoise(a,'gaussian',0.1,0.005);%对图像进行高斯加噪%制定卷积核h=ones(3,3)/5;h(1,1)=0;h(1,3)=0;h(3,1)=0;h(1,3)=0;%平滑运算a2=imfilter(anoised,h);subplot(131);imshow(a);%显示原始图像subplot(132);imshow(anois
3、ed);%加有高斯噪声的图像subplot(133);imshow(a2);%经过平滑后的图像例8-6clearall;I=imread('eight.tif');J=imnoise(I,'salt&pepper',0.02);subplot(231);imshow(I);subplot(232);imshow(J);K1=filter2(fspecial('average',3),J);%进行3×3模板平滑滤波K2=filter2(fspecial('average',5),J);%%进行5×5模板平滑滤波K3=filter2(fspecial('av
4、erage',7),J);%%进行7×7模板平滑滤波K4=filter2(fspecial('average',9),J);%%进行9×9模板平滑滤波subplot(233);imshow(uint8(K1));subplot(234);imshow(uint8(K2));subplot(235);imshow(uint8(K3));subplot(236);imshow(uint8(K4));例8-7a=imread('coins.png');%读取图像b=imnoise(a,'salt&pepper',0.02);%对图像增加椒盐噪声k=medfil
5、t2(b);%中值滤波去噪subplot(131);imshow(a);xlabel('原始图像');subplot(132);imshow(b);xlabel('含有椒盐噪声图像');subplot(133);imshow(k);xlabel('中值滤波去噪图像');例8-9I=imread('lena.bmp');J=im2double(I);subplot(2,2,1),imshow(J,[])h1=[0-10,-15-1,0-10];h2=[-1-1-1,-19-1,-1-1-1];h3=[1-20,-25-2,1-21];A=conv2(J,
6、h1,'same');subplot(2,2,2),imshow(A,[])B=conv2(J,h2,'same');subplot(2,2,3),imshow(B,[])C=conv2(J,h3,'same');subplot(2,2,4),imshow(C,[])例8-10clearall;[I,map]=imread('lena.bmp');figure(1),imshow(I,map);I=double(I);[IX,IY]=gradient(I);GM=sqrt(IX.*IX+IY.*IY);meth1=GM;figure(2),imshow(
7、meth1,map);meth2=I;J=find(GM>10);meth2(J)=GM(J);figure(3),imshow(meth2,map);meth3=I;J=find(GM>10);meth3(J)=255;figure(4),imshow(meth3,map);meth4=I;J=find(GM<10);meth4(J)=255;figure(5),imshow(meth4,map);meth5=I;J=find(GM>10);meth5(J)=255;Q=find(GM<10);OUTS(Q)=0;figure(6),imshow(me
8、th5,map);例8-11I=imread('cat.jpg');h1=[0,