數(shù)字圖象處理課程設(shè)計報告_第1頁
數(shù)字圖象處理課程設(shè)計報告_第2頁
數(shù)字圖象處理課程設(shè)計報告_第3頁
數(shù)字圖象處理課程設(shè)計報告_第4頁
數(shù)字圖象處理課程設(shè)計報告_第5頁
已閱讀5頁,還剩11頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、4各個功能模塊的主要實現(xiàn)程序4.1 guide創(chuàng)建圖形界面在matlab命令行中,運行指令guide,出現(xiàn)圖2所示窗口。左邊為控制面板,選擇blank gui (default),點擊ok,創(chuàng)建空白界面如圖3所示:圖2 圖3在tools中選擇menu editor.,創(chuàng)建菜單為要實現(xiàn)的功能,結(jié)果如圖4所示:圖4在上圖menu editor,右面的tag中為相應(yīng)的子程序函數(shù)名,實現(xiàn)功能的相應(yīng)程序在此函數(shù)下編寫。在gui編輯窗口添加txt文本“xxx”和“xx工作室制作 版本:1.0.0”。到此,用戶界面創(chuàng)建完成,運行結(jié)果如圖5所示:圖54.2 主要的功能實現(xiàn)和函數(shù)4.2.1 圖像文件(bmp、

2、jpg、 tiff、 gif等)進(jìn)行打開、保存、另存、打印、退出等功能操作,程序如下:function open_image_callback(hobject, eventdata, handles)%*打開圖象*filename,pathname = uigetfile('*.jpg''*.bmp''*.tiff''*.gif','pick a file','multiselect','on');%彈出對話框得到打開的路徑global file;%全局變量file=imread(s

3、trcat(pathname,filename);%打開得到的路徑下的文件image(file); % -function save_callback(hobject, eventdata, handles)%*保存*global file;imwrite(file);% -function untitled_5_callback(hobject, eventdata, handles)%*另存為*global file;%這個是要保存的東西,一般是global的filename,pathname = uiputfile('*.jpg''*.bmp''*

4、.tiff''*.gif','save as');%彈出對話框的到保存的路徑imwrite(uint8(file),strcat(pathname,filename);%存儲到該路徑下% -function print_image_callback(hobject, eventdata, handles)%*打印*global file;printdlg% -function exit_callback(hobject, eventdata, handles)%*退出*pos_size = get(handles.figure1,'positio

5、n');user_response = modaldlg('title','exit');switch user_responsecase 'no' % 沒變化case 'yes' delete(handles.figure1)end其中退出調(diào)用了另一個界面,如圖6所示,程序和部分描述如下:圖6function modaldlg_openingfcn(hobject, eventdata, handles, varargin)handles.output = 'yes' guidata(hobject, h

6、andles); if(nargin > 3) for index = 1:2:(nargin-3), switch lower(vararginindex) case 'title' set(hobject, 'name', vararginindex+1); case 'string' set(handles.string, 'string', vararginindex+1); otherwise error('invalid input arguments'); end endendfigpos=ge

7、t(0,'defaultfigureposition');figwidth=215;figheight=88;if isempty(gcbf) screenunits=get(0,'units'); set(0,'units','points'); screensize=get(0,'screensize'); set(0,'units',screenunits); figpos(1)=1/2*(screensize(3)-figwidth); figpos(2)=2/3*(screensize(4

8、)-figheight);else gcbfoldunits = get(gcbf,'units'); set(gcbf,'units','points'); gcbfpos = get(gcbf,'position'); set(gcbf,'units',gcbfoldunits); figpos(1:2) = (gcbfpos(1) + gcbfpos(3) / 2) - figwidth / 2, . (gcbfpos(2) + gcbfpos(4) / 2) - figheight / 2;endfigpo

9、s(3:4)=figwidth figheight;set(hobject, 'position', figpos);load dialogicons.maticondata=questicondata;questiconmap(256,:)=get(handles.figure1,'color');iconcmap=questiconmap;axes(handles.axes1);img=image(icondata);set(handles.figure1, 'colormap', iconcmap);set(gca, . 'visi

10、ble', 'off', . 'ydir' ,'reverse' , . 'xlim' ,get(img,'xdata'), . 'ylim' ,get(img,'ydata') . ); uiwait(handles.figure1);function varargout = modaldlg_outputfcn(hobject, eventdata, handles) varargout1 = handles.output; delete(handles.figure1)

11、; function yes_button_callback(hobject, eventdata, handles)handles.output = get(hobject,'string');guidata(hobject, handles);uiresume(handles.figure1);function no_button_callback(hobject, eventdata, handles)handles.output = get(hobject,'string');guidata(hobject, handles);uiresume(hand

12、les.figure1);function figure1_closerequestfcn(hobject, eventdata, handles)if isequal(get(handles.figure1, 'waitstatus'), 'waiting') uiresume(handles.figure1);else delete(handles.figure1);endfunction figure1_keypressfcn(hobject, eventdata, handles)if isequal(get(hobject,'currentke

13、y'),'return') uiresume(handles.figure1);end 4.2.2 數(shù)字圖像的統(tǒng)計信息功能包括直方圖的統(tǒng)計及繪制、區(qū)域圖的面積、輪廓的統(tǒng)計、圖象的幾何變換等.(1) 直方圖的統(tǒng)計及繪制程序function verticl_star_callback(hobject, eventdata, handles)global file;figure,imshow(file);j=imadjust(file,70/255 160/255,); j1 = rgb2gray(j);imhist(j1,64);title('直方圖');(

14、2) 區(qū)域圖的面積程序function area_area_callback(hobject, eventdata, handles)global file;bw=im2bw(file,0.2);total = bwarea(bw);msgbox('區(qū)域面積 :',num2str(total),'像素');(3) 輪廓的統(tǒng)計function area_girth_callback(hobject, eventdata, handles)global file;bw=im2bw(file,0.4);total = bwperim(bw);figure,imshow

15、(total);title('輪廓統(tǒng)計');(4) 圖象的幾何變換圖象插值縮放function untitled_68_callback(hobject, eventdata, handles)global file;file1=imresize(file,0.5);%最近鄰插值figure,imshow(file1);title('最近鄰插值');file2=imresize(file,0.5,'bilinear');%雙線行插值figure,imshow(file2);title('雙線行插值');file3=imresize

16、(file,0.5,'bicubic');%雙三次插值figure,imshow(file3);title('雙三次插值');圖象的旋轉(zhuǎn)function untitled_84_callback(hobject, eventdata, handles)global file;j = mat2gray(file);j=imrotate(j,30,'bilinear','crop');%旋轉(zhuǎn)30度,'crop'是返回圖象與原圖大小相同figure,imshow(j);title('旋轉(zhuǎn)30度');% -

17、function untitled_85_callback(hobject, eventdata, handles)global file;j = mat2gray(file);j=imrotate(j,45,'bilinear','crop');%旋轉(zhuǎn)30度,'crop'是返回圖象與原圖大小相同figure,imshow(j);title('旋轉(zhuǎn)45度');% -function untitled_86_callback(hobject, eventdata, handles)global file;j = mat2gray(f

18、ile);j=imrotate(j,60,'bilinear','crop');%旋轉(zhuǎn)30度,'crop'是返回圖象與原圖大小相同figure,imshow(j);title('旋轉(zhuǎn)60度');% -function untitled_87_callback(hobject, eventdata, handles)global file;j = mat2gray(file);j=imrotate(j,90,'bilinear','crop');%旋轉(zhuǎn)30度,'crop'是返回圖象與原

19、圖大小相同figure,imshow(j);title('旋轉(zhuǎn)90度');% -function untitled_88_callback(hobject, eventdata, handles)global file;j = mat2gray(file);j=imrotate(j,180,'bilinear','crop');%旋轉(zhuǎn)30度,'crop'是返回圖象與原圖大小相同figure,imshow(j);title('旋轉(zhuǎn)180度');圖象的剪切function untitled_71_callback(ho

20、bject, eventdata, handles)global file;f=imcrop(file,40,50,200,200);figure,imshow(f);title('圖象的剪切');4.2.3 數(shù)字圖像的增強(qiáng)處理功能空域中的點運算、直方圖的均衡化、各種空間域平滑算法(如局部平滑濾波法、中值濾波等)、銳化算法(如梯度銳化法、高通濾波等)頻域的各種增強(qiáng)方法:頻域平滑、頻域銳化、低通濾波、同態(tài)濾波等。function untitled_16_callback(hobject, eventdata, handles)global file;file=imadjust(f

21、ile,70/255 160/255,); %matlab還提供了histeq函數(shù)(自動直方圖均衡化) h = rgb2gray(file);k=histeq(h); figure,imshow(k),title('經(jīng)直方圖均衡化后的圖') figure,imhist(k),title('直方圖均衡化后的直方圖') % -function untitled_80_callback(hobject, eventdata, handles)global file;j=imadjust(file,70/255 160/255,); j = rgb2gray(j);j=

22、imnoise(j,'salt & pepper',0.05);figure,imshow(j);title('灰度圖象')k1=filter2(fspecial('average',3),j)/255;k2=filter2(fspecial('average',5),j)/255;k3=filter2(fspecial('average',7),j)/255;figure,imshow(k1);title('3x3')figure,imshow(k2);title('5x5'

23、;)figure,imshow(k3);title('7x7')% -function untitled_81_callback(hobject, eventdata, handles)global file;j=imadjust(file,70/255 160/255,); j = rgb2gray(j);k=imnoise(j,'salt & pepper',0.0007);figure,imshow(k);title('原圖象')k1=wiener2(k);figure,imshow(k1);title('維納濾波'

24、)% -function untitled_82_callback(hobject, eventdata, handles)global file;j=imadjust(file,70/255 160/255,); j = rgb2gray(file);k=imnoise(j,'gaussian',0.0007);figure,imshow(k);title('高斯噪聲圖象')h=fspecial('gaussian');i=filter2(h,k)/255;figure,imshow(i);title('高斯濾波')% -fun

25、ction untitled_21_callback(hobject, eventdata, handles)global file;j = rgb2gray(file);j=imnoise(j,'salt & pepper',0.05);figure,imshow(j);title('灰度圖象')k=ordfilt2(j,5,ones(3,3);figure,imshow(k);title('中值濾波')% -function untitled_22_callback(hobject, eventdata, handles)global

26、 file;j = rgb2gray(file);figure,imshow(j);title('原圖象')h1=fspecial('sobel');i1=filter2(h1,j);figure,imshow(i1);title('sobel卷積')i2=conv2(j,h1);figure,imshow(i2);title('sobel濾波')h2=fspecial('prewirt');i3=filter2(h2,j);figure,imshow(i3);title('prewirt濾波')h

27、2=fspecial('log');i4=filter2(h3,j);figure,imshow(i4);title('log濾波')% -function untitled_23_callback(hobject, eventdata, handles)global file;k = rgb2gray(file);j=imnoise(k,'salt & pepper');figure,imshow(j);title('原圖象')f=double(j);%傅立葉變換g=fft2(f);%轉(zhuǎn)換數(shù)據(jù)矩陣g=fftshift(g

28、);n1,n2=size(g);n=2;d0=50;n1=fix(n1/2);n2=fix(n2/2);for i=1:n1 for j=1:n2 d=sqrt(i-n1)2+(j-n2)2); if d=0 h=0; else h=1/(1+(d/d0)(2*n); end result(i,j)=h*g(i,j); endendresult=ifftshift(result);x2=ifft2(result);x3=uint8(real(x2);figure,imshow(x3);title('高通濾波')% -function untitled_28_callback(h

29、object, eventdata, handles)global file;j=imadjust(file,70/255 160/255,); j = rgb2gray(j);k=imnoise(j,'salt & pepper');figure,imshow(k);title('灰度圖象')f=double(k);%傅立葉變換g=fft2(f);%轉(zhuǎn)換數(shù)據(jù)矩陣g=fftshift(g);n1,n2=size(g);n=2;d0=50;n1=fix(n1/2);n2=fix(n2/2);for i=1:n1 for j=1:n2 d=sqrt(i-n1

30、)2+(j-n2)2); %計算butterwaorth低通轉(zhuǎn)換函數(shù) h=1/(1+0.414*(d/d0)(2*n); result(i,j)=h*g(i,j); endendresult=ifftshift(result);x2=ifft2(result);x3=uint8(real(x2);figure,imshow(x3);title('低通濾波')% -function untitled_73_callback(hobject, eventdata, handles)global file;j=imadjust(file,70/255 160/255,); figur

31、e,imshow(j),title('經(jīng)灰度級調(diào)整后的彩色圖') i = rgb2gray(file);figure,imshow(i),title('經(jīng)灰度級調(diào)整后的灰度圖')figure,imhist(i,128),title('灰度級調(diào)整后的直方圖')4.2.4 圖像分割:點、線(hough變換檢測直線)、及邊緣檢測(梯度算子、拉普拉斯算子等),區(qū)域分割包括閾值分割、區(qū)域生長、分裂合并等。% - hough變換檢測直線-function untitled_34_callback(hobject, eventdata, handles)glo

32、bal file; i = rgb2gray(file); % convert to intensitybw = edge(i,'canny'); % extract edgesh,t,r = hough(bw,'rhoresolution',0.5,'thetaresolution',0.5);figure,imshow(imadjust(mat2gray(h),'xdata',t,'ydata',r,. 'initialmagnification','fit'); title(&

33、#39;hough transform of gantrycrane.png'); xlabel('theta'), ylabel('rho'); axis on, axis normal, hold on; colormap(hot);% -function untitled_58_callback(hobject, eventdata, handles)%*梯度算子-roberts cross-垂直*global file;j=rgb2gray(file);p,t=edge(j,'roberts','vertical'

34、); figure,imshow(p);title('梯度算子-roberts cross-垂直') % -function untitled_59_callback(hobject, eventdata, handles)%*梯度算子-roberts cross-水平*global file; j=rgb2gray(file); p,t=edge(j,'roberts','horizontal'); figure,imshow(p);title('梯度算子-roberts cross-水平') % -function untit

35、led_60_callback(hobject, eventdata, handles)%*梯度算子-roberts cross-雙向*global file;g=rgb2gray(file);p,t=edge(g,'roberts','both'); figure,imshow(p);title('梯度算子-roberts cross-雙向')% -function untitled_61_callback(hobject, eventdata, handles)global file;g=rgb2gray(file);p,t=edge(g,&

36、#39;prewitt','vertical'); figure,imshow(p);title('梯度算子-prewitt-垂直')% -function untitled_62_callback(hobject, eventdata, handles)global file;g=rgb2gray(file);p,t=edge(g,'prewitt','horizontal'); figure,imshow(p);title('梯度算子-prewitt-水平')% -function untitled_6

37、3_callback(hobject, eventdata, handles)global file;g=rgb2gray(file);p,t=edge(g,'prewitt','both'); figure,imshow(p);title('梯度算子-prewitt-雙向')% -function untitled_64_callback(hobject, eventdata, handles)global file;g=rgb2gray(file);p,t=edge(g,'sobel','vertical');

38、 figure,imshow(p);title('梯度算子-sobel-垂直')% -function untitled_65_callback(hobject, eventdata, handles)global file;g=rgb2gray(file);p,t=edge(g,'sobel','horizontal'); figure,imshow(p);title('梯度算子-sobel-水平')% -function untitled_66_callback(hobject, eventdata, handles)glob

39、al file;g=rgb2gray(file);p,t=edge(g,'sobel','both'); figure,imshow(p);title('梯度算子-sobel-雙向')% -function untitled_37_callback(hobject, eventdata, handles)%*拉普拉斯算子*global file;g=rgb2gray(file);p,t=edge(g,'log',0,2.2);figure,imshow(p);title('拉普拉斯算子')4.2.5 數(shù)字圖像的變換

40、普通傅立葉變換(ft)與逆變換(ift)、快速傅立葉變換(fft)與逆變換(ifft)、離散余弦變換(dct),小波變換等。% -普通傅立葉變換(ft)-function untitled_43_callback(hobject, eventdata, handles)global file; figure,imshow(file);f=zeros(128,128); f(60:68,60:68)=1; %中間有個小孔 figure,imshow(f);%原圖像 f=fft2(f,256,256); k=fftshift(f); figure,imshow(abs(k);%功率譜 figure

41、,mesh(f.*conj(k)/(256*256);%功率譜密度 % -普通傅立葉逆變換(ift)-function untitled_44_callback(hobject, eventdata, handles)global file;figure,imshow(file);f=zeros(128,128); f(60:68,60:68)=1; %中間有個小孔 imshow(f);%原圖像 f=ifft2(f,256,256); k=ifftshift(f); figure,imshow(abs(k);%功率譜 figure,mesh(k.*conj(k)/(256*256);%功率譜密

42、度 % -快速傅立葉變換(fft)-function untitled_45_callback(hobject, eventdata, handles)global file;j=rgb2gray(file);f=fft2(j);figure,imshow(f);title('快速傅立葉變換')% -快速傅立葉逆變換(ifft)-function untitled_46_callback(hobject, eventdata, handles)global file;j=rgb2gray(file);f=ifft2(j);figure,imshow(f);title('

43、快速傅立葉逆變換')% -離散余弦變換-function untitled_47_callback(hobject, eventdata, handles)global file;j=rgb2gray(file);t=dct(j);figure,imshow(log(abs(t),);title('離散余弦變換')% -function untitled_48_callback(hobject, eventdata, handles)global file;j=rgb2gray(file);c,y=wavedec2(j,2,'db1'); %yc,ys=wavedec2(y,2,'db1'); %y為要分解的圖像矩陣,2為分解的層數(shù),db1'為采用的小波基 %返回兩個矩陣yc和ys。yh2=detcoef2('h',yc,ys,2);%這是提取出圖像2層分解后的水平分量,h改v是垂直分量,h該d是對角分量。%細(xì)節(jié)分量用另外一個方法提取。yv2=detcoef2('v',c,y,2);figure,imshow(yv2);title('2層分解后垂直分量小波變換')yh2=detcoef2('v',c,y,2);fig

溫馨提示

  • 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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論