频域滤波与图像恢复_第1页
频域滤波与图像恢复_第2页
频域滤波与图像恢复_第3页
频域滤波与图像恢复_第4页
频域滤波与图像恢复_第5页
已阅读5页,还剩10页未读, 继续免费阅读

下载本文档

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

文档简介

1、1、 实验目的1.1 学习如何根据观察使用一个启发式方法选择一个阈值。1.2 探究函数graythresh以进行自动阈值选取。1.3 学习如何实现自适应阈值化。二、实验内容2.1 使用prewitt算子进行边缘检测2.1.1 对lena.tif进行分别使用imfilter函数和edge函数进行三种算子的边缘检测Imfilter函数实现代码:clc,clear all,close allroberts1=1,0;0,-1;roberts2=0,1;-1,0;prewitt1=-1,0,1;-1,0,1;-1,0,1;prewitt2=1,1,1;0,0,0;-1,-1,-1;sobel1=-1,

2、0,1;-2,0,2;-1,0,1;sobel2=1,2,1;0,0,0;-1,-2,-1;g=imread('C:Documents and SettingsAdministrator桌面imagesLena.tif');f=double(g);f1=imfilter(f,roberts1);f2=imfilter(f,roberts2);roberts_f=max(abs(f1),abs(f2);f1=imfilter(f,prewitt1);f2=imfilter(f,prewitt2);prewitt_f=max(abs(f1),abs(f2);f1=imfilter(

3、f,sobel1);f2=imfilter(f,sobel2);sobel_f=max(abs(f1),abs(f2);figure,subplot(2,2,1),imshow(g),title('原图像');subplot(2,2,2),imshow(roberts_f,),title('Roberts 边缘检测图像');subplot(2,2,3),imshow(prewitt_f,),title('Prewitt 边缘检测图像');subplot(2,2,4),imshow(sobel_f,),title('Sobel 边缘检测图像

4、);Imfilter函数操作结果显示如下:Edge函数代码如下:clc,clear all,close all;f=imread('C:Documents and SettingsAdministrator桌面imageslena.tif');sobel_f=edge(f,'sobel');roberts_f=edge(f,'roberts');prewitt_f=edge(f,'prewitt');figure,subplot(2,2,1),imshow(f),title('原图像');subplot(2,2,2

5、),imshow(roberts_f),title('Roberts边缘图像');subplot(2,2,3),imshow(prewitt_f),title('Prewitt边缘图像');subplot(2,2,4),imshow(sobel_f),title('Sobel边缘图像');Edge函数实现结果如下:思考:I_prw1,t1=edge(I,prewitt);中t1表示什么? 答:t1表示阈值,可如下使用:I_prw1,t1=edge(I,prewitt);t1=prewitt边缘检测,阈值=num2str(t1);imshow(I_

6、prw1);title(t1);2.1.2加高斯噪声并提取边缘代码如下:prewitt1=-1,0,1;-1,0,1;-1,0,1;prewitt2=1,1,1;0,0,0;-1,-1,-1;f=imread('C:Documents and SettingsAdministrator桌面imageslena.tif');noisy=imnoise(f,'gaussian',0.07);noise=double(noisy);g=double(f);f1=imfilter(g,prewitt1);f2=imfilter(g,prewitt2);prewitt_g

7、=max(abs(f1),abs(f2);f1=imfilter(noise,prewitt1);f2=imfilter(noise,prewitt2);prewitt_f=max(abs(f1),abs(f2);figure,subplot(2,2,1),imshow(f),title('原图像');subplot(2,2,2),imshow(noisy),title('含高斯噪声图像');subplot(2,2,3),imshow(prewitt_g,),title('原图边缘检测图像');subplot(2,2,4),imshow(prew

8、itt_f,),title('含高斯噪声边缘检测图像');思考:Matlab对噪声图像使用同样的阈值吗? 答:不应使用同样的阈值。2.1.3 尝试使用不同的阈值prewitt1=-1,0,1;-1,0,1;-1,0,1;prewitt2=2,1,2;0,0,0;-2,-1,-2;prewitt1=-2,0,2;-2,0,2;-2,0,2;prewitt2=2,1,2;0,0,0;-2,-1,-2;prewitt1=-0.5,0,0.5;-0.5,0,0.5;-0.5,0,0.5;prewitt2=0.5,0.5,0.5;0,0,0;-0.5,-0.5,-0.5;prewitt1

9、=-0.1,0,0.1;-0.1,0,0.1;-0.1,0,0.1;prewitt2=0.1,0.1,0.1;0,0,0;-0.1,-0.1,-0.1;思考:阈值影响算子对噪声的响应吗? 如何影响目标的边缘? 答:阈值的选择直接影响分割效果。阈值影响算子对噪声的响应,2.2使用sobel算子、roberts算子进行边缘检测2.2.1 对cameraman.tif进行边缘检测 实现代码:clc,clear all,close allroberts1=1,0;0,-1;roberts2=0,1;-1,0;sobel1=-1,0,1;-2,0,2;-1,0,1;sobel2=1,2,1;0,0,0;

10、-1,-2,-1;prewitt1=-1,0,1;-1,0,1;-1,0,1;prewitt2=1,1,1;0,0,0;-1,-1,-1;g=imread('cameraman.tif');noisy=imnoise(g,'gaussian',0.07);noise=double(noisy);f=double(g); f1=imfilter(f,roberts1);f2=imfilter(f,roberts2);roberts_f=max(abs(f1),abs(f2);f1=imfilter(f,sobel1);f2=imfilter(f,sobel2);s

11、obel_f=max(abs(f1),abs(f2);f1=imfilter(f,prewitt1);f2=imfilter(f,prewitt2);prewitt_f=max(abs(f1),abs(f2); figure,subplot(2,2,1),imshow(g),title('原图像');subplot(2,2,2),imshow(roberts_f,),title('Roberts 边缘检测图像');subplot(2,2,3),imshow(sobel_f,),title('Sobel 边缘检测图像');subplot(2,2,4

12、),imshow(prewitt_f,),title('Prewitt 边缘检测图像');实现结果图:2.2.2 加高斯噪声并提取边缘 实现代码:clc,clear all,close allroberts1=1,0;0,-1;roberts2=0,1;-1,0;sobel1=-1,0,1;-2,0,2;-1,0,1;sobel2=1,2,1;0,0,0;-1,-2,-1;prewitt1=-1,0,1;-1,0,1;-1,0,1;prewitt2=1,1,1;0,0,0;-1,-1,-1;g=imread('cameraman.tif');noisy=imno

13、ise(g,'gaussian',0.07);noise=double(noisy);f=double(g); f1=imfilter(f,roberts1);f2=imfilter(f,roberts2);roberts_f=max(abs(f1),abs(f2);f1=imfilter(f,sobel1);f2=imfilter(f,sobel2);sobel_f=max(abs(f1),abs(f2);f1=imfilter(f,prewitt1);f2=imfilter(f,prewitt2);prewitt_f=max(abs(f1),abs(f2); g1=imfi

14、lter(noise,roberts1);g2=imfilter(noise,roberts2);roberts_g=max(abs(g1),abs(g2);g1=imfilter(noise,sobel1);g2=imfilter(noise,sobel2);sobel_g=max(abs(g1),abs(g2);g1=imfilter(noise,prewitt1);g2=imfilter(noise,prewitt2);prewitt_g=max(abs(g1),abs(g2); figure,subplot(4,2,1),imshow(g),title('原图像');s

15、ubplot(4,2,2),imshow(noisy),title('含高斯噪声图像');subplot(4,2,3),imshow(roberts_f,),title('Roberts 边缘检测图像');subplot(4,2,4),imshow(roberts_g,),title('含噪声Roberts边缘检测图像');subplot(4,2,5),imshow(sobel_f,),title('Sobel 边缘检测图像');subplot(4,2,6),imshow(sobel_g,),title('含噪声Sobel

16、边缘检测图像');subplot(4,2,7),imshow(prewitt_f,),title('Prewitt 边缘检测图像');subplot(4,2,8),imshow(prewitt_g,),title('含噪声prewitt边缘检测图像');实现结果:思考:在有噪声和无噪声的情况下,sobel算子和prewitt算子、roberts算子比较如何? 答:在上图中,为原图cameraman.tif叠加了高斯噪声,形成了一副含噪声的图像。通过运行的结果图可以清晰的看出,在对没有叠加噪声的图像进行处理的时候Prewitt边缘检测的效果最好,人物的轮廓

17、基本清晰,而Robert算子进行检测时,图像轮廓还不完整,部分边缘丢失。在对有噪声的图像进行处理时,prewitt算子和Sobel算子都能较清晰的提取出图像的轮廓,而robert算子提取得轮廓就较为模糊,人物边缘线都不能很好的提出,说明Robel算子不具备抑制噪声的效果。2.3实验内容32.3.1 观察分析coins.tif的直方图,以确定合适的阈值Tclc,clear all,close allf=imread('F:imagescoins.png');figure,subplot(1,2,1),imshow(f),title('原图像');subplot(1

18、,2,2),imhist(uint8(f),title('直方图');问题:直方图的哪个峰表示背景像素;哪个峰对应硬币的像素? 答:高峰为背景像素,低峰为硬币像素,选择双峰谷底处为阈值,观察直方图得到T大约为95.clc,clear all,close allf=imread('F:imagescoins.png');figure(1),subplot(2,2,1),imshow(f),title('原图像');subplot(2,2,2),imhist(uint8(f),title('直方图');s=input('目标物

19、为?','s'); T=input('请输入适当的阙值');m,n=size(f);for i=1:m for j=1:n g(i,j)=f(i,j)>T; endendsubplot(2,2,3),imshow(g,),title('阙值分割图');subplot(2,2,4), axis offtext(0,0.6,'阙值T=',num2str(T);text(0,0.8,'目标物为',s);figure(1);3.2设定阈值T=85并生成新图像。使用im2bw(I,T/255);clc,clea

20、r all,close allf=imread('F:imagescoins.png');figure(1),subplot(2,2,1),imshow(f),title('原图像');subplot(2,2,2),imhist(uint8(f),title('直方图');T=85;subplot(2,2,3),im2bw(f,T/255),title('阙值分割图');subplot(2,2,4), axis offtext(0,0.6,'阙值T=85');问题:问题:函数im2bw的作用是什么;为什么要除以25

21、5 答:函数im2bw的作用是使用阈值(threshold)变换法把灰度图像(grayscale image)转换成二值图像。除以255是为了把阈值化成0到1之间的数,对于图像上阈值大于该值的画成黑色,小于该值的就画成白色。3.3 调用graythresh()函数自动生成阙值clc,clear all,close allf=imread('F:imagescoins.png');figure(1),subplot(2,2,1),imshow(f),title('原图像');subplot(2,2,2),imhist(uint8(f),title('直方图

22、');T=graythresh(f);subplot(2,2,3),im2bw(f,T),title('阙值分割图');subplot(2,2,4), axis offtext(0,0.6,'阙值T=',num2str(T);问题:效果有什么不同, graythresh有什么优势? 答:(1)使用graythresh函数后产生的新图像更加圆了,边缘比较上两幅图更加平滑。(2)自己选择的阈值不一定是最佳的,需要不停地调整取值,才能选择合适的阈值。而greythresh函数会根据背景的不同,自动调整阈值,达到最佳的效果。3.4 采用不同的图像,并叠加不同程度的噪声,重复上述操作代码实现:clc,clear all,close allf=imread('F:imagesblood.tif');noisy=imnoise(f,'gaussian',0.5);noise=doub

温馨提示

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

最新文档

评论

0/150

提交评论