圖像處理實驗1234_第1頁
圖像處理實驗1234_第2頁
圖像處理實驗1234_第3頁
圖像處理實驗1234_第4頁
圖像處理實驗1234_第5頁
已閱讀5頁,還剩17頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、圖像處理實驗1234實驗一 Matlab基本運算1、 按水平和豎直方向分別合并下述兩個矩陣:>> A=1 0 0;1 1 0;0 0 1A = 1 0 0 1 1 0 0 0 1>> B=2 3 4;5 6 7;8 9 10B = 2 3 4 5 6 7 8 9 10>> C=A BC = 1 0 0 2 3 4 1 1 0 5 6 7 0 0 1 8 9 10>> D=A;BD = 1 0 0 1 1 0 0 0 1 2 3 4 5 6 7 8 9 10(1) 分別刪除上述兩個結(jié)果的第2行。>> C(2,:)=C = 1 0 0 2

2、 3 4 0 0 1 8 9 10>> D(2,:)=D = 1 0 0 0 0 1 2 3 4 5 6 7 8 9 10(2)分別將上述兩個結(jié)果的第2行最后3列的數(shù)值 改為11 12 13。>> C(2,4:6)=11 12 13C = 1 0 0 2 3 4 0 0 1 11 12 13>> D(2,:)=11 12 13D = 1 0 0 11 12 13 2 3 4 5 6 7 8 9 10(3) 分別查看上述兩個結(jié)果的各方向長度。>> C_SIZE=size(C)C_SIZE = 2 6>> D_SIZE=size(D)D_

3、SIZE = 5 3(4) 分別計算上述矩陣A和B的A+B、A.* B、A./B和 AB,分析結(jié)果。>> AB1=A+BAB1 = 3 3 4 6 7 7 8 9 11>> AB2=A.*BAB2 = 2 0 0 5 6 0 0 0 10>> AB3=A./BAB3 = 0.5000 0 0 0.2000 0.1667 0 0 0 0.1000>> AB4=ABAB4 = 2 3 4 3 3 3 8 9 10(5) 計算矩陣A和B的A&B 、 A|B、 A和B,分析結(jié)果。>> AB5=A&BAB5 = 1 0 0 1

4、1 0 0 0 1>> AB6=A|BAB6 = 1 1 1 1 1 1 1 1 1>> AB7=BAB7 = 0 0 0 0 0 0 0 0 0>> AB8=AAB8 = 0 1 1 0 0 1 1 1 0(6) 判斷上述矩陣A和B中哪些元素值不小于4。>> A.*(A>=4)ans = 0 0 0 0 0 0 0 0 0>> B.*(B>=4)ans = 0 0 4 5 6 7 8 9 102、下面是Matlab中有關(guān)圖像讀出、顯示和保存函數(shù)使用的一段代碼:f = imread ( filename); M, N =

5、size( f ); imshow ( f );imwrite (f, filename.jpg)>> f=imread('filename.jpg');>> M,N=size(f);>> imshow(f);Warning: Image is too big to fit on screen; displaying at 56% scale.> In truesize>Resize1 at 308 In truesize at 44 In imshow at 161>> imwrite(f,'filename

6、.jpg')各函數(shù)的詳細使用方法,請各位查看Matlab中的幫助,使用“help 函數(shù)名”即可以查看函數(shù)的使用方法。請完成以下內(nèi)容:(1) 讀取文件夾中的圖像“pollen.tif.tif”,用imshow(f)和imshow(f, )顯示,并將后一幅圖存為”pollen1.tif”。思考:為什么圖像變清楚了?>> f=imread('bubbles.tif');>> imshow(f);Warning: Image is too big to fit on screen; displaying at 75% scale.> In true

7、size>Resize1 at 308 In truesize at 44 In imshow at 161>> figure,imshow(f,);Warning: Image is too big to fit on screen; displaying at 75% scale.> In truesize>Resize1 at 308 In truesize at 44 In imshow at 161(2) 用不同的壓縮參數(shù)(80,50,10)將bubbles.tif 保存為jpeg圖像,比較壓縮參數(shù)的作用, 并通過imfinfo獲取文件信息了解圖像的壓縮

8、情況對圖像質(zhì)量的影響>> imwrite(f,'bubbles1.jpg','quality',80);>> g=imread('bubbles1.jpg');>> imshow(g);Warning: Image is too big to fit on screen; displaying at 75% scale.> In truesize>Resize1 at 308 In truesize at 44 In imshow at 161>> imwrite(f,'bubb

9、les2.jpg','quality',50);>> g1=imread('bubbles2.jpg');>> figure,imshow(g1);Warning: Image is too big to fit on screen; displaying at 75% scale.> In truesize>Resize1 at 308 In truesize at 44 In imshow at 161>> imwrite(f,'bubbles3.jpg','quality

10、9;,10);>> g2=imread('bubbles3.jpg');>> figure,imshow(g2);Warning: Image is too big to fit on screen; displaying at 75% scale.> In truesize>Resize1 at 308 In truesize at 44 In imshow at 161>> imfinfo('bubbles1.jpg')ans = Filename: 'bubbles1.jpg' FileMod

11、Date: '26-Sep-2014 00:01:44' FileSize: 39129 Format: 'jpg' FormatVersion: '' Width: 720 Height: 688 BitDepth: 8 ColorType: 'grayscale' FormatSignature: '' NumberOfSamples: 1 CodingMethod: 'Huffman' CodingProcess: 'Sequential' Comment: >>

12、imfinfo('bubbles2.jpg')ans = Filename: 'bubbles2.jpg' FileModDate: '26-Sep-2014 00:02:46' FileSize: 20068 Format: 'jpg' FormatVersion: '' Width: 720 Height: 688 BitDepth: 8 ColorType: 'grayscale' FormatSignature: '' NumberOfSamples: 1 CodingMet

13、hod: 'Huffman' CodingProcess: 'Sequential' Comment: >> imfinfo('bubbles3.jpg')ans = Filename: 'bubbles3.jpg' FileModDate: '26-Sep-2014 00:03:29' FileSize: 9498 Format: 'jpg' FormatVersion: '' Width: 720 Height: 688 BitDepth: 8 ColorType:

14、'grayscale' FormatSignature: '' NumberOfSamples: 1 CodingMethod: 'Huffman' CodingProcess: 'Sequential' Comment: 3、自己編寫M文件,并將其放在工作目錄中,然后在Matlab中使用命令行調(diào)用。X=1:0.1:10;Y=sin(x);Plot(x,y);(了解以上函數(shù)的意義,掌握編寫和使用m文件的技巧,熟悉基本的GUI編程技術(shù))>> X=1:0.1:10X = Columns 1 through 9 1.0000

15、 1.1000 1.2000 1.3000 1.4000 1.5000 1.6000 1.7000 1.800 Columns 10 through 18 1.9000 2.0000 2.1000 2.2000 2.3000 2.4000 2.5000 2.6000 2.7000 Columns 19 through 27 2.8000 2.9000 3.0000 3.1000 3.2000 3.3000 3.4000 3.5000 3.6000 Columns 28 through 36 3.7000 3.8000 3.9000 4.0000 4.1000 4.2000 4.3000 4.4

16、000 4.5000 Columns 37 through 45 4.6000 4.7000 4.8000 4.9000 5.0000 5.1000 5.2000 5.3000 5.4000 Columns 46 through 54 5.5000 5.6000 5.7000 5.8000 5.9000 6.0000 6.1000 6.2000 6.3000 Columns 55 through 63 6.4000 6.5000 6.6000 6.7000 6.8000 6.9000 7.0000 7.1000 7.2000 Columns 64 through 72 7.3000 7.400

17、0 7.5000 7.6000 7.7000 7.8000 7.9000 8.0000 8.1000 Columns 73 through 81 8.2000 8.3000 8.4000 8.5000 8.6000 8.7000 8.8000 8.9000 9.0000 Columns 82 through 90 9.1000 9.2000 9.3000 9.4000 9.5000 9.6000 9.7000 9.8000 9.9000 Column 91 10.0000>> Y=sin(X)Y = Columns 1 through 9 0.8415 0.8912 0.9320

18、0.9636 0.9854 0.9975 0.9996 0.9917 0.9738 Columns 10 through 18 0.9463 0.9093 0.8632 0.8085 0.7457 0.6755 0.5985 0.5155 0.4274 Columns 19 through 27 0.3350 0.2392 0.1411 0.0416 -0.0584 -0.1577 -0.2555 -0.3508 -0.4425 Columns 28 through 36 -0.5298 -0.6119 -0.6878 -0.7568 -0.8183 -0.8716 -0.9162 -0.95

19、16 -0.9775 Columns 37 through 45 -0.9937 -0.9999 -0.9962 -0.9825 -0.9589 -0.9258 -0.8835 -0.8323 -0.7728 Columns 46 through 54 -0.7055 -0.6313 -0.5507 -0.4646 -0.3739 -0.2794 -0.1822 -0.0831 0.0168 Columns 55 through 63 0.1165 0.2151 0.3115 0.4048 0.4941 0.5784 0.6570 0.7290 0.7937 Columns 64 throug

20、h 72 0.8504 0.8987 0.9380 0.9679 0.9882 0.9985 0.9989 0.9894 0.9699 Columns 73 through 81 0.9407 0.9022 0.8546 0.7985 0.7344 0.6630 0.5849 0.5010 0.4121 Columns 82 through 90 0.3191 0.2229 0.1245 0.0248 -0.0752 -0.1743 -0.2718 -0.3665 -0.4575 Column 91 -0.5440>> plot(X,Y);4、編寫一個M文件,完成以下功能:輸入?yún)?shù)

21、:文件名處理:(1)將圖像中每個點的灰度值除于2,(2)將灰度值為0的點換為灰度值為255,(3)計算圖像的最大、最小灰度值和平均值。輸出:將每次處理的結(jié)果顯示出來>> f=imread('bubbles.tif');>> imshow(f);Warning: Image is too big to fit on screen; displaying at 75% scale.> In truesize>Resize1 at 308 In truesize at 44 In imshow at 161>> g=f/2;>&g

22、t; figure,imshow(g);Warning: Image is too big to fit on screen; displaying at 75% scale.> In truesize>Resize1 at 308 In truesize at 44 In imshow at 161>> f(f=0)=255;>> figure,imshow(f);Warning: Image is too big to fit on screen; displaying at 75% scale.> In truesize>Resize1 a

23、t 308 In truesize at 44 In imshow at 161>> f=imread('bubbles.tif');>> min(f(:)ans = 17>> max(f(:)ans = 255>> mean(f(:)ans = 137.9148M文件中functionf=Fhanshu(str)g=imread(str);imshow(g/2);g(g=0)=255;figure,imshow(g);min(g(:)max(g(:)mean(g(:)>> Fhanshu('bubbles1.

24、jpg');Warning: Image is too big to fit on screen; displaying at 75% scale.> In truesize>Resize1 at 308 In truesize at 44 In imshow at 161 In Fhanshu at 3Warning: Image is too big to fit on screen; displaying at 75% scale.> In truesize>Resize1 at 308 In truesize at 44 In imshow at 161

25、 In Fhanshu at 5ans = 20ans = 255ans = 137.9177>> Fhanshu('bubbles1.jpg');Warning: Image is too big to fit on screen; displaying at 75% scale.> In truesize>Resize1 at 308 In truesize at 44 In imshow at 161 In Fhanshu at 3Warning: Image is too big to fit on screen; displaying at 7

26、5% scale.> In truesize>Resize1 at 308 In truesize at 44 In imshow at 161 In Fhanshu at 5ans = 20ans = 255ans = 137.9177實驗2 醫(yī)學(xué)圖像增強實驗?zāi)康模?. 掌握分段線性變換;2. 理解直方圖均衡的原理與作用3. 掌握直方圖均衡化的Matlab編程實驗內(nèi)容:1. 研究imadjust函數(shù)的使用方法,將圖片moon進行明暗反轉(zhuǎn)處理,寫出實現(xiàn)函數(shù);原圖顯示>> m=imread('moon.tif');>> m1=imadjust(

27、m);>> imshow(m1);Warning: Image is too big to fit on screen; displaying at 56% scale.> In truesize>Resize1 at 308 In truesize at 44 In imshow at 161明暗反轉(zhuǎn)>> m2=imadjust(m,0 1,1 0);>> figure,imshow(m2);Warning: Image is too big to fit on screen; displaying at 56% scale.> In t

28、ruesize>Resize1 at 308 In truesize at 44 In imshow at 161將0.5到0.7范圍的灰度擴展到整個【0 1】范圍>> m3=imadjust(m,0.5 0.7,0 1);>> figure,imshow(m3);Warning: Image is too big to fit on screen; displaying at 56% scale.> In truesize>Resize1 at 308 In truesize at 44 In imshow at 1612. 利用Matlab圖像處理

29、工具箱提供的直方圖均衡函數(shù)對醫(yī)學(xué)圖像“img_LineEnhance.bmp”進行均衡化處理,并顯示均衡化前后的直方圖。 提示:下面為直方圖均衡化相關(guān)的函數(shù)說明x=rgb2gray(I);轉(zhuǎn)換為二維圖像,imhist處理的是二維圖像(1)生成并繪制圖像的直方圖 語法:h=imhist(f, b) 說明:b是用于形成直方圖的灰度級的個數(shù)。>> a=imread('img_LineEnhance.bmp');>> a1=rgb2gray(a);>> imhist(a1);>> imhist(a1,25);>> h=imhi

30、st(a1,25);>> horz=linspace(0,255,25);>> bar(horz,h)(2)直方圖均衡化函數(shù)語法:g=histeq(f, n)說明:n是為輸出圖像制定的灰度級數(shù)。>> b=histeq(a1,255);>> imhist(b)>> b=histeq(a1,55);>> imhist(b)>> imshow(a);>> figure,imshow(a1);>> figure,imshow(h);>> figure,imshow(b);>&g

31、t; figure,imshow(b1);3. 對圖片pollen進行線性灰度變換(利用imadjust函數(shù))。對于輸入圖片,通過max和min函數(shù)求他們的最大最小值,然后將其擴充到0255的灰度空間,看看效果如何,并分析其直方圖。自己編寫m文件im2adjust,實現(xiàn)讀入一個圖片以后自動的將其灰度空間擴充到0-255。>> f=imread('pollen.tif');>> imshow(f);>> max(f(:)ans = 83>> min(f(:)ans = 13>> f2=imadjust(f,13/255

32、83/255,0 1);>> figure,imshow(f2);>> imhist(f);>> imhist(f2);M文件中functionf=im2adjust(str)g=imread(str);imshow(g);min(g(:)max(g(:)g2=imadjust(g,min(g(:)/255 max(g(:)/255,0 1);figure,imshow(g2);figure,imhist(g);figure,imhist(g2);>> im2adjust('pollen.tif');ans = 13ans = 8

33、3實驗3 醫(yī)學(xué)圖像增強(二)4. 熟悉領(lǐng)域濾波5. 掌握使用Matlab中的函數(shù)實現(xiàn)醫(yī)學(xué)圖像進行圖像銳化的方法;6. 熟悉醫(yī)學(xué)圖像離散傅里葉變化的原理和方法;7. 掌握醫(yī)學(xué)圖像頻域濾波的原理;8. 掌握使用Matlab中的函數(shù)實現(xiàn)醫(yī)學(xué)圖像進行頻域濾波的方法;1. 使用imnoise給圖像MRIBrain_10.bmp添加概率為0.2的椒鹽噪聲,然后分別使用fspecial產(chǎn)生3*3、5*5、7*7的方形模板,并使用imfilter對有噪聲的圖像進行空間濾波,觀察濾波效果并說明原因。再給圖像MRIBrain_10.bmp添加均值為0,方差為0.01的高斯噪聲,使用三種模板對其進行濾波,觀察其效果

34、并說明在兩種噪聲中使用模板進行濾波產(chǎn)生的差別及原因。對于椒鹽噪聲,中值濾波效果比均值濾波效果好。原因:椒鹽噪聲是幅值近似相等但隨機分布在不同位置上,圖像中有干凈點也有污染點。中值濾波是選擇適當?shù)狞c來替代污染點的值,所以處理效果好。因為噪聲的均值不為0,所以均值濾波不能很好地去除噪聲點。對于高斯噪聲,均值濾波效果比中值濾波效果好。原因:高斯噪聲是幅值近似正態(tài)分布,但分布在每點像素上。因為圖像中的每點都是污染點,所以中值濾波選不到合適的干凈點。因為正態(tài)分布的均值為0,所以均值濾波可以消除噪聲。>> g=imread('MRIBrain_10.bmp');>>

35、 imshow(g);>> g1=imnoise(g,'salt & pepper',0.2);>> figure,imshow(g1);>> a=fspecial('average',3);>> b=fspecial('average',5);>> c=fspecial('average',7);>> figure,imshow(a);>> figure,imshow(b);>> figure,imshow(c);>&g

36、t; g2=imfilter(g1,a);>> g3=imfilter(g1,b);>> g4=imfilter(g1,c);>> figure,imshow(g2);>> figure,imshow(g3);>> figure,imshow(g4);>> f=imnoise(g,'gaussian',0,0.01);>> figure,imshow(f);>> f1=imfilter(f,a);>> f2=imfilter(f,b);>> f3=imfilt

37、er(f,c);>> figure,imshow(f1);>> figure,imshow(f2);>> figure,imshow(f3);2. 使用edge函數(shù),分別采用robertssobellog(拉普拉斯算子)算子,對圖像MRIBrain_10.bmp進行銳化,比較各個算子的效果并說明其原因。3. 提示:Matlab圖像處理工具箱提供的圖像銳化函數(shù)語法:g,t=edge(f,method,parameters);說明:此函數(shù)按照指定梯度算子對圖像f進行銳化,g為銳化后的圖像,參數(shù)t是可選的,它給出函數(shù)所使用的閾值。method可以選取roberts

38、sobellog等值,parameters可以選取方向或標準差的值,對于robertssobel算子可以選取horizontalvertical兩個值中的一個,對于log算子,值為其對應(yīng)的標準差的值(默認值為2)>> f=imread('MRIBrain_10.bmp');>> imshow(f);>> g=rgb2gray(f);>> r,t=edge(g,'roberts');>> rh,t=edge(g,'roberts','horizontal');>>

39、; rv,t=edge(g,'roberts','vertical');>> figure,imshow(r);>> figure,imshow(rh);>> figure,imshow(rv);>> f=imread('MRIBrain_10.bmp');>> imshow(f);>> g=rgb2gray(f);>> s,t=edge(g,'sobel');>> sh,t=edge(g,'sobel','ho

40、rizontal');>> sv,t=edge(g,'sobel','vertical');>> figure,imshow(s);>> figure,imshow(sh);>> figure,imshow(sv);>> f=imread('MRIBrain_10.bmp');>> imshow(f);>> g=rgb2gray(f);>> l,t=edge(g,'log');>> l1,t=edge(g,'

41、log',0.02);>> l2,t=edge(g,'log',0.002);>> figure,imshow(l);>> figure,imshow(l1);>> figure,imshow(l2);4. 對圖片“MRIBrain_10.bmp”進行頻域變換處理。(1)頻域變換(2)移動頻域到中心位置(3)log非線性變換頻譜圖讓其能更清晰顯示>> f=imread('MRIBrain_10.bmp');>> imshow(f);>> g=rgb2gray(f);>

42、;> g=double(g);>> gf=fft2(g);>> gf=abs(gf);>> gsft=fftshift(gf);>> gl=log(1+gsft);>> figure,imshow(gf,);>> figure,imshow(gsft,);>> figure,imshow(gl,);5. 實現(xiàn)ppt182頁理想低通濾波器對“MRIBrain_10.bmp”圖片進行處理,并顯示D0為5,10,20,40時的濾波效果圖。M文件中functioni=LiXiangLB(str) f=imread

43、(str);f=rgb2gray(f);figure,imshow(f); fd=double(f); g=fftshift(fft2(fd); M,N=size(g); n1=floor(M/2); n2=floor(N/2); d0=40; for i=1:M for j=1:N d=sqrt(i-n1)2+(j-n2)2); if d<=d0 h=1; else h=0; end g(i,j)=h*g(i,j); end end g1=ifftshift(g); g2=real(ifft2(g1); g3=unit8(g2); figure,imshow(g3,); title(&

44、#39;ILPF濾波(d0=40)');實驗4 圖像分割實驗?zāi)康模?. 了解圖像分割的基本理論和方法;10. 掌握對圖像進行點、線和邊緣檢測的方法;11. 掌握閾值分割的方法和閾值的選擇;12. 熟悉區(qū)域生長法和分水嶺分割算法實驗內(nèi)容:4. 對圖片lung2.bmp和加噪聲的lung3.bmp分別用3*3的sobel算子、prewitt算子、log算子、canny算子進行處理,根據(jù)處理結(jié)果分析上述算子,分別是什么類型的?有何作用?思考一下如何設(shè)計算子。lung3.bmp為g = imnoise(f,”salt & pepper”,0.02)(0.02表示發(fā)生概率)>>

45、; f=imread('lung2.bmp');>> g=imnoise(f,'salt & pepper',0.02);>> r,t=edge(f,'roberts');>> r1,t=edge(g,'roberts');>> s,t=edge(f,'sobel');>> s1,t=edge(g,'sobel');>> p,t=edge(f,'prewitt');>> p1,t=edge(g

46、,'prewitt');>> c,t=edge(f,'canny');>> c1,t=edge(g,'canny'); >> l,t=edge(f,'log');>> l1,t=edge(g,'log');>> imshow(f);title('原圖');>> figure,imshow(g);title('加噪音');>> figure,imshow(r);title('roberts

47、9;);>> figure,imshow(r1);title('roberts');>> figure,imshow(s);title('sobel');>> figure,imshow(s1);title('sobel');>> figure,imshow(p);title('prewitt');>> figure,imshow(p1);title('prewitt');>> figure,imshow(c);title('conny');>> figure,imshow(c1);title('conny');>> figure,imshow(l);title('log');>> figure,imshow(l1);title('log');5. (1)對圖片lung.bmp用im2bw進行處理,其

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論