数字图像课程设计_第1页
数字图像课程设计_第2页
数字图像课程设计_第3页
数字图像课程设计_第4页
数字图像课程设计_第5页
已阅读5页,还剩9页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、均衡化: 图像一直方图集中在低灰度区,图像偏暗;图像二直方图集中在高灰度区,图像偏亮;图像三直方图集中在中部,图像效反差小。a=imread('fig1_1_1.bmp');b=imread('fig1_1_2.bmp');c=imread('fig1_1_3.bmp');a1=histeq(a);b1=histeq(b);c1=histeq(c);subplot(3,3,1),imshow(a),title('原始图像1');subplot(3,3,2),imshow(b),title('原始图像2');subp

2、lot(3,3,3),imshow(c),title('原始图像3');subplot(3,3,4),imhist(a),title('图1直方图');subplot(3,3,5),imhist(b),title('图2直方图');subplot(3,3,6),imhist(c),title('图3直方图');subplot(3,3,7),imshow(a1),title('均衡化后图像1');subplot(3,3,8),imshow(b1),title('均衡化后图像2');subplot(3,

3、3,9),imshow(c1),title('均衡化后图像3');平滑滤波:a=imread('fig1_2.bmp ');a1=imnoise(a,'salt & pepper',0.02);l1=filter2(fspecial('average',3),a1)/255; l2=filter2(fspecial('average',5),a1)/255; l3=filter2(fspecial('average',7),a1)/255; l4=filter2(fspecial('

4、average',9),a1)/255; figure (1)subplot(2,3,1),imshow(a),title('原始图像');subplot(2,3,2),imshow(l1);title('3*3 模板平滑滤波');subplot(2,3,3),imshow(l2);title('5*5 模板平滑滤波');subplot(2,3,4),imshow(l3);title('7*7 模板平滑滤波');subplot(2,3,5),imshow(l4);title('9*9 模板平滑滤波');l1

5、1=filter2(fspecial('average',3),a)/255; l22=filter2(fspecial('average',5),a)/255; l33=filter2(fspecial('average',7),a)/255; l44=filter2(fspecial('average',9),a)/255; figure (2)subplot(2,3,1),imshow(a),title('原始图像');subplot(2,3,2),imshow(a1),title(' 添加椒盐噪声的

6、图像');subplot(2,3,3),imshow(l11);title('3*3 模板平滑滤波');subplot(2,3,4),imshow(l22);title('5*5 模板平滑滤波');subplot(2,3,5),imshow(l33);title('7*7 模板平滑滤波');subplot(2,3,6),imshow(l44);title('9*9 模板平滑滤波¨');平滑滤波是低频增强的空间域滤波技术。它的目的有两类:一类是模糊;另一类是消除噪音。空间域的平滑滤波一般采用简单平均法进行,就是求邻

7、近像元点的平均亮度值。在噪声均匀分布在边缘时,使用平滑滤波会有较大的误差,如果噪声不是均匀分布,可有效去除噪声。邻域的大小与平滑的效果直接相关,邻域越大平滑的效果越好,但邻域过大,平滑会使边缘信息损失的越大,从而使输出的图像变得模糊,因此需合理选择邻域的大小。锐化滤波:i=imread('fig1_2.bmp'); f= 8 ;g=-1 -1 -1; -1 8 -1; -1 -1 -1; m=-1 -1 -1 -1 -1; -1 -1 8 -1 -1;-1 -1 -1 -1 -1;n=-1 -1 -1 -1 -1 -1 -1; -1 -1 -1 8 -1 -1 -1;-1 -1

8、 -1 -1 -1 -1 -1;p=-1 -1 -1 -1 -1 -1 -1 -1 -1;-1 -1 -1 -1 8 -1 -1 -1 -1;-1 -1 -1 -1 -1 -1 -1 -1 -1;h=double(i);e=conv2(h,f,'same');j=conv2(h,g,'same');x=conv2(h,m,'same');y=conv2(h,n,'same');z=conv2(h,n,'same');subplot(2,3,1);imshow(h);title('原始图像');sub

9、plot(2,3,2);imshow(e);title('滤波后图像1');subplot(2,3,3);imshow(j);title('滤波后图像2');subplot(2,3,4);imshow(x);title('滤波后图像3');subplot(2,3,5);imshow(y);title('滤波后图像4'); subplot(2,3,6);imshow(z);title('滤波后图像5');图像锐化处理的目的是为了使图像的边缘、轮廓线以及图像的细节变的清晰。一般情况下,在计算机图像处理中可用微分运算和高

10、通滤波器来实现图像的锐化。空间域图像的锐化常用的是拉普拉斯运算,它不仅是偏导数的线性组合,而且是各向同性的,这样可以使图像中间任何方向伸展的边缘和轮廓线变得清晰低通滤波:I=imread('fig1_2.bmp'); m n p=size(I);I=double(I);subplot(2,2,1);image(I);colormap(gray),title('原始图');Noise=wgn(m,n,25);New = Noise + I;subplot(2,2,2);image(New),title('噪声图');g=fft2(New); g=f

11、ftshift(g);M,N=size(g);nn=2; d0=20; m=fix(M/2); n=fix(N/2);for i=1:M for j=1:N d=sqrt(i-m)2+(j-n)2); h=1/(1+0.414*(d/d0)(2*nn); result(i,j)=h*g(i,j); endendresult=ifftshift(result);J2=ifft2(result); J3=uint8(real(J2);subplot(2,2,3);image(J3),title('截止频率20 '); nn=2; d0=100; m=fix(M/2); n=fix(

12、N/2);for i=1:M for j=1:N d=sqrt(i-m)2+(j-n)2); h=1/(1+0.414*(d/d0)(2*nn); result(i,j)=h*g(i,j); endendresult=ifftshift(result);J2=ifft2(result);J3=uint8(real(J2);subplot(2,2,4);image(J3),title('截止频率100 ')去掉信号中不必要的高频成分,降低采样频率,避免频率混淆,去掉高频干扰高通滤波:I=imread('fig1_2.bmp');m n p=size(I);I=do

13、uble(I);subplot(2,2,1),image(I),colormap(gray);,title('原始图');Noise=wgn(m,n,25);New = Noise + I;subplot(2,2,2);image(New),title('噪声图');g=fft2(New); g=fftshift(g);M,N=size(g);d0=15; m=fix(M/2); n=fix(N/2);for i=1:M for j=1:N d=sqrt(i-m)2+(j-n)2); if(d<=d0) h=0; else h=1; end result(

14、i,j)=h*g(i,j); endendresult=ifftshift(result);J1=ifft2(result);J2=uint8(real(J1);subplot(2,2,3),imshow(J2),title('IHPF滤波(d0=15)') ;M,N=size(g);d0=100; m=fix(M/2); n=fix(N/2);for i=1:M for j=1:N d=sqrt(i-m)2+(j-n)2); if(d<=d0) h=0; else h=1; end result(i,j)=h*g(i,j); endendresult=ifftshift

15、(result);J1=ifft2(result);J2=uint8(real(J1);subplot(2,2,4),imshow(J2),title('IHPF滤波(d0=100)') ;高通滤波器衰减或抑制低频分量而通过高频分量。图像的边缘、细节主要在高频部分得到反映。而图像的模糊是高频部分较弱造成的。为了消除模糊,突出图像的边缘信息,则采用高通滤波器让高频部分通过,消弱图像的低频成分,再经过傅里叶逆变换得到边缘锐化的图像。图像还原:I=imread('fig1_3_1.bmp');subplot(2,2,1);imshow(I);title('模糊

16、图像'); m,n=size(I); F=fftshift(fft2(I); k=0.0025; for u=1:m for v=1:n H(u,v)=exp(-k)*(u-m/2)2+(v-n/2)2)(5/6); end end G=F.*H; I0=real(ifft2(fftshift(G); I1=imnoise(uint8(I0),'gaussian',0,0.001) subplot(2,2,2),imshow(uint8(I1),title('模糊退化且添加高斯噪声的图像'); F0=fftshift(fft2(I1); F1=F0./H

17、; I2=ifft2(fftshift(F1); subplot(2,2,3),imshow(uint8(I2),title('全逆滤波复原图'); K=0.1; for u=1:m for v=1:n H(u,v)=exp(-k*(u-m/2)2+(v-n/2)2)(5/6); H0(u,v)=(abs(H(u,v)2; H1(u,v)=H0(u,v)/(H(u,v)*(H0(u,v)+K); end end F2=H1.*F0; I3=ifft2(fftshift(F2); subplot(2,2,4),imshow(uint8(I3),title('维纳滤波复原图

18、');形态学图像处理:I1=imread('fig1_4_1.bmp'); I3=im2bw(I1); Subplot(221),imshow(I1) Subplot(222),imshow(I3) I4=bwmorph(I3,'open'); Subplot(223),imshow(I4) I5=bwmorph(I4,'close'); I=imread('fig1_4_2.bmp');B=strel('diamond',1);J1=imopen(I,B);J2=imclose(J1,B);subplot

19、(1,2,1);imshow(I);title('原始图像');subplot(1,2,2);imshow(J2);title('滤噪结果');rgb=imread('fig1_5.bmp');rgb=im2double(rgb);r=rgb(:,:,1);g=rgb(:,:,2);b=rgb(:,:,3);subplot(3,3,1),imshow(rgb),title('原始图像');subplot(3,3,4),imshow(r),title('原始图像红色分量');subplot(3,3,5),imshow

20、(g),title('原始图像绿色分量');subplot(3,3,6),imshow(b),title('原始图像蓝色分量');num=0.5*(r-g)+(r-b);sym den;fen=sqrt(r-g).2+(r-g).*(g-b);theta=acos(num./(fen+eps);H=theta;H(b>g)=2*pi-H(b>g);H=H/(2*pi);num=min(min(r,g),b);fen=r+g+b;fen(fen=0)=eps;S=1-3.*num./fen;H(S=0)=0;I=(r+g+b)/3;hsi=cat(3,

21、H,S,I);subplot(3,3,7),imshow(H),title('H');subplot(3,3,8),imshow(S),title('S');subplot(3,3,9),imshow(I),title('I');I1=rgb2gray(rgb);subplot(3,3,2),imshow(I1);title('灰度图像');k1=filter2(fspecial('average',3),I1)/255; subplot(3,3,3),imshow(k1);title('平滑滤波图像

22、9;);图像的校正:A=imread('fig3_1.bmp'); se=strel('ball',12,0);BW=imdilate(A,se);´BW2 = bwmorph(BW, 'thin',Inf);H,T,R = hough(BW2);P = houghpeaks(H,5); lines = houghlines(BW2,T,R,P);for k = 1:length(lines) xy = lines(k).point1; lines(k).point2;endm=(xy(2,2)- xy(1,2)/(xy(2,1)-xy

23、(1,1);M=atan(m);M=M*180/3.14;C=imrotate(A,M); subplot(1,2,1);imshow(A);title('原图像');subplot(1,2,2);imshow(C);title('校正后的图像');图像融合:X1=imread('fig4_1_a.jpg');X2=imread('fig4_1_b.jpg');X3=imread('fig4_1_c.jpg');X4=imread('fig4_1_d.jpg');X5=imread('fig

24、4_1_e.jpg');X6=imread('fig4_1_f.jpg');subplot(3,2,1);imshow(X1);title('序列图像1');subplot(3,2,2);imshow(X2);title('序列图像2');subplot(3,2,3);imshow(X3);title('序列图像3');subplot(3,2,4);imshow(X4);title('序列图像4');subplot(3,2,5);imshow(X5);title('序列图像5');subplot(3,2,6);imshow(X6);title('序列图像');X1=double(X1);X2=double(X2);X3=double(X3);X4=double(X4);X5=double(X5);X6=double(X6);c1,I1=wavedec2(X1,3,'sym4');c2,I2=wavedec2(X2,3,'sym4');c3,I3=wavedec2(X3,3,'sym4');c4,I4=wavedec2(X4,3,'sym4

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论