頻域?yàn)V波及圖像恢復(fù)_第1頁
頻域?yàn)V波及圖像恢復(fù)_第2頁
頻域?yàn)V波及圖像恢復(fù)_第3頁
頻域?yàn)V波及圖像恢復(fù)_第4頁
頻域?yàn)V波及圖像恢復(fù)_第5頁
已閱讀5頁,還剩10頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、1、 實(shí)驗(yàn)?zāi)康?.1 學(xué)習(xí)如何根據(jù)觀察使用一個(gè)啟發(fā)式方法選擇一個(gè)閾值。1.2 探究函數(shù)graythresh以進(jìn)行自動(dòng)閾值選取。1.3 學(xué)習(xí)如何實(shí)現(xiàn)自適應(yīng)閾值化。二、實(shí)驗(yàn)內(nèi)容2.1 使用prewitt算子進(jìn)行邊緣檢測2.1.1 對lena.tif進(jìn)行分別使用imfilter函數(shù)和edge函數(shù)進(jìn)行三種算子的邊緣檢測Imfilter函數(shù)實(shí)現(xiàn)代碼: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函數(shù)操作結(jié)果顯示如下:Edge函數(shù)代碼如下: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函數(shù)實(shí)現(xiàn)結(jié)果如下:思考: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對噪聲圖像使用同樣的閾值嗎? 答:不應(yīng)使用同樣的閾值。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;思考:閾值影響算子對噪聲的響應(yīng)嗎? 如何影響目標(biāo)的邊緣? 答:閾值的選擇直接影響分割效果。閾值影響算子對噪聲的響應(yīng),2.2使用sobel算子、roberts算子進(jìn)行邊緣檢測2.2.1 對cameraman.tif進(jìn)行邊緣檢測 實(shí)現(xiàn)代碼: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 邊緣檢測圖像');實(shí)現(xiàn)結(jié)果圖:2.2.2 加高斯噪聲并提取邊緣 實(shí)現(xiàn)代碼: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邊緣檢測圖像');實(shí)現(xiàn)結(jié)果:思考:在有噪聲和無噪聲的情況下,sobel算子和prewitt算子、roberts算子比較如何? 答:在上圖中,為原圖cameraman.tif疊加了高斯噪聲,形成了一副含噪聲的圖像。通過運(yùn)行的結(jié)果圖可以清晰的看出,在對沒有疊加噪聲的圖像進(jìn)行處理的時(shí)候Prewitt邊緣檢測的效果最好,人物的輪廓

17、基本清晰,而Robert算子進(jìn)行檢測時(shí),圖像輪廓還不完整,部分邊緣丟失。在對有噪聲的圖像進(jìn)行處理時(shí),prewitt算子和Sobel算子都能較清晰的提取出圖像的輪廓,而robert算子提取得輪廓就較為模糊,人物邊緣線都不能很好的提出,說明Robel算子不具備抑制噪聲的效果。2.3實(shí)驗(yàn)內(nèi)容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('直方圖');問題:直方圖的哪個(gè)峰表示背景像素;哪個(gè)峰對應(yīng)硬幣的像素? 答:高峰為背景像素,低峰為硬幣像素,選擇雙峰谷底處為閾值,觀察直方圖得到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('目標(biāo)物

19、為?','s'); T=input('請輸入適當(dāng)?shù)年I值');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,'目標(biāo)物為',s);figure(1);3.2設(shè)定閾值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');問題:問題:函數(shù)im2bw的作用是什么;為什么要除以25

21、5 答:函數(shù)im2bw的作用是使用閾值(threshold)變換法把灰度圖像(grayscale image)轉(zhuǎn)換成二值圖像。除以255是為了把閾值化成0到1之間的數(shù),對于圖像上閾值大于該值的畫成黑色,小于該值的就畫成白色。3.3 調(diào)用graythresh()函數(shù)自動(dòng)生成闕值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有什么優(yōu)勢? 答:(1)使用graythresh函數(shù)后產(chǎn)生的新圖像更加圓了,邊緣比較上兩幅圖更加平滑。(2)自己選擇的閾值不一定是最佳的,需要不停地調(diào)整取值,才能選擇合適的閾值。而greythresh函數(shù)會(huì)根據(jù)背景的不同,自動(dòng)調(diào)整閾值,達(dá)到最佳的效果。3.4 采用不同的圖像,并疊加不同程度的噪聲,重復(fù)上述操作代碼實(shí)現(xiàn):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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論