基于matlab的数字图像处理

上传人:宝路 文档编号:23010382 上传时间:2017-11-29 格式:DOC 页数:16 大小:1.24MB
返回 下载 相关 举报
基于matlab的数字图像处理_第1页
第1页 / 共16页
基于matlab的数字图像处理_第2页
第2页 / 共16页
基于matlab的数字图像处理_第3页
第3页 / 共16页
基于matlab的数字图像处理_第4页
第4页 / 共16页
基于matlab的数字图像处理_第5页
第5页 / 共16页
点击查看更多>>
资源描述

《基于matlab的数字图像处理》由会员分享,可在线阅读,更多相关《基于matlab的数字图像处理(16页珍藏版)》请在金锄头文库上搜索。

1、数字图像处理作业:1.数字图像的基本操作联系,如 MATLAB 读入、显示等2.灰度直方图的使用3.图像增强的练习4.图像的几何变换 一数字图像的基本操作练习1.matlab 读入图像1.1 函数 imreadImread 函数可以将指定位置的图像文件读入工作区。对于除索引图像以外的情况,其原型如下。A=imread(FILENAME,FMT);对于索引图像,情况有所不同,此时 imread 的调用形式如下。X,MAP=imread(FILENAME,FMT);1.2 函数 imwriteInwrite 将指定的图像数据写入文件中,通过指定不同的保存文件扩展名可以起到图像格式转换的作用。其调用

2、格式如下。Imwrite(A,FILENAME,FMT);2.matlab 图像显示2.1 函数 imshowImshow 函数用于显示工作区或图像文件中的图像,在显示的同时可控制部分效果,常用的调用形式如下。Imshow(I,low high,param1,value1,param2,value2,.);Imshow(I,MAP);Imshow(filename);二.灰度直方图的使用Matlab 中的 imhist 函数可以进行图像的灰度直方图运算,调用语法如下。imhist(I) ;imhist(I,n) ;counts,s=imhist(.);4.一般直方图下面使用了 Matlab 中

3、的一张内置示例图片演示灰度直方图的生成与显示,程序如下。I=imread(pout.tif);figure;imshow(I);title(Source);figure;imhist(I);title(Histogram);上述程序的运行结果如图所示。5.归一化直方图在 imhist 函数的返回值中,counts 保存了落入每个区间的像素个数,通过计算 counts 与图像中像素总数的商可以得到归一化直方图。绘制有 32 个灰度区间的归一化直方图的 Matlab 程序如下。 I=imread(pout.tif);figure;M,N=size(I);counts,x=imhist(I,32);

4、counts=counts/M/N;stem(x,counts);3图像增强的练习:3.1 空间域图像增强3.1.1 线性平滑滤波器例题:对一个图像进行不同大小模板的均值滤波,并比较结果。I=imread(eight.tif);J=imnoise(I,salt & pepper,0.02);subplot(2,2,1)imshow(J);title(噪声图像);K1=filter2(fspecial(average,3),J)/255;K2=filter2(fspecial(average,5),J)/255;K3=filter2(fspecial(average,7),J)/255;subp

5、lot(2,2,2)imshow(K1);title(3x3模板均 值滤波);subplot(2,2,3)imshow(K2);title(5x5模板均 值滤波);subplot(2,2,4)imshow(K3);title(7x7模板均 值滤波);其显示结果如图所示。3.1.2 非线性平滑滤波器例题:对一个图像实现不同模板的中值滤波,并比较结果。I=imread(eight.tif);J=imnoise(I,salt & pepper,0.02);subplot(2,2,1)imshow(J);title(噪声图像);K1=medfilt2(J,3 3);K2=medfilt2(J,5 5)

6、;K3=medfilt2(J,7 7);subplot(2,2,2)imshow(K1);title(3x3模板中 值滤波);subplot(2,2,3)imshow(K2);title(5x5模板中 值滤波);subplot(2,2,4)imshow(K3);title(7x7模板中 值滤波);其显示结果如图所示。3.1.3 线性锐化滤波器例题:对图像 pout.tif 进行线性高通滤波。I=imread(pout.tif);h=fspecial(laplacian);I2=filter2(h,I);subplot(1,2,1);imshow(I);title(原始图像);subplot(1

7、,2,2);imshow(I2);title(滤波后图像);其显示结果如图所示。3.1.4 非线性锐化滤波器例题:sobel 算子,prewitt 算子,log 算子对图像滤波。I=imread(cameraman.tif);subplot(2,2,1);imshow(I);title(原始图像);h1=fspecial(sobel);I1=filter2(h1,I);subplot(2,2,2);imshow(I1);title(sobel算子滤波);h1=fspecial(prewitt);I1=filter2(h1,I);subplot(2,2,3);imshow(I1);title(p

8、rewitt算子滤波 );h1=fspecial(log);I1=filter2(h1,I);subplot(2,2,4);imshow(I1);title(log算子滤波 );其显示结果如图所示。3.2 频域图像增强3.2.1 低通滤波例题:对图像 eight.tif 加入椒盐噪声后,实现 Butterworth 低通滤波。clearI1=imread(eight.tif);subplot(2,2,1);imshow(I1);title(原始图像);I2=imnoise(I1,salt & pepper);subplot(2,2,2);imshow(I2);title(噪声图像);f=dou

9、ble(I2);g=fft2(f);g=fftshift(g);N1,N2=size(g);n=2;d0=50;n1=fix(N1/2);n2=fix(N2/2);for i=1:N1for j=2:N2d=sqrt(i-n1)2+(j-n2)2);h=1/(1+0.414*(d/d0)(2*n);result1(i,j)=h*g(i,j);if(g(i,j)50)result2(i,j)=0;elseresult2(i,j)=g(i,j);endendendresult1=ifftshift(result1);result2=ifftshift(result2);X2=ifft2(resul

10、t1);X3=uint8(real(X2);subplot(2,2,3);imshow(X3);title(Btterworth滤波图像 );X4=ifft2(result2);X5=uint8(real(X4);subplot(2,2,4);imshow(X5);title(理想低通滤波图像);其显示结果如图所示。3.2.2 高通滤波例题:对图像 eight.tif 实现 Butterworth 高通滤波。clearI1=imread(eight.tif);subplot(2,2,1);imshow(I1);title(原始图像);I2=imnoise(I1,salt & pepper);s

11、ubplot(2,2,2);imshow(I2);title(噪声图像);f=double(I2);g=fft2(f);g=fftshift(g);N1,N2=size(g);n=2;d0=50;n1=fix(N1/2);n2=fix(N2/2);for i=1:N1for j=2:N2d=sqrt(i-n1)2+(j-n2)2);if d=0h=0;elseh=1/(1+(d0/d)(2*n);endresult1(i,j)=h*g(i,j);if(g(i,j)50)result2(i,j)=0;elseresult2(i,j)=g(i,j);endendendresult1=ifftshi

12、ft(result1);result2=ifftshift(result2);X2=ifft2(result1);X3=uint8(real(X2);subplot(2,2,3);imshow(X3);title(Btterworth滤波图像 );X4=ifft2(result2);X5=uint8(real(X4);subplot(2,2,4);imshow(X5);title(理想高通滤波图像);其显示结果如图所示。四 图像的几何变换4.1 图像平移程序:function I_out=imMove(I,Tx,Ty)tform=maketform(affine,1 0 0;0 1 0;Tx

13、Ty 1);I_out=imtransform(I,tform,XData,1 size(I,2),YData,1 size(I,1) );subplot(1,2,1),imshow(I);title(原图 像 );subplot(1,2,2),imshow(I_out);title(平移 图像 );其中 I=imread(pout.tif);其显示结果如图所示。4.2 图像镜像程序:A=imread(pout.tif);height,width,dim=size(A);tform=maketform(affine,-1 0 0;0 1 0;width 0 1);B=imtransform(A

14、,tform,nearest);tform2=maketform(affine,1 0 0;0 -1 0;0 height 1);C=imtransform(A,tform2,nearest);subplot(1,3,1),imshow(A);title(原图 像 );subplot(1,3,2),imshow(B);title(水平 镜像 );subplot(1,3,3),imshow(C);title(竖直 镜像 );其显示结果如图所示。4.3 图像转置程序:clearA=imread(pout.tif);tform=maketform(affine,0 1 0;1 0 0;0 0 1);

15、B=imtransform(A,tform,nearest);subplot(1,2,1),imshow(A);title(原图 像 );subplot(1,2,2),imshow(B);title(图像 转置 );其显示结果如图所示。4.4 图像缩放程序:clearA=imread(pout.tif);B=imresize(A,1.2,nearest);figure,imshow(A);title(原图 像 );figure,imshow(B);title(图像 缩放 );其显示结果如图所示。4.5 图像旋转程序:clearA=imread(pout.tif);B=imrotate(A,30,nearest,crop);subplot(1,2,1),imshow(A);title(原图 像 );subplot(1,2,2),imshow(B);title(逆时针 旋转30度);其显示结果如图所示。

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号