數字圖像處理 降噪濾波 大作業(yè)_第1頁
數字圖像處理 降噪濾波 大作業(yè)_第2頁
數字圖像處理 降噪濾波 大作業(yè)_第3頁
數字圖像處理 降噪濾波 大作業(yè)_第4頁
數字圖像處理 降噪濾波 大作業(yè)_第5頁
已閱讀5頁,還剩22頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、昆明理工大學信息工程與自動化學院學生實驗報告( 20152016學年 第 一 學期 )課程名稱:圖形圖像基礎程序設計 開課實驗室: 2015年 12月 1 日年級、專業(yè)、班物聯(lián)網131學號201310410133姓名李哲成績實驗項目名稱圖像綜合處理指導教師毛存禮教師評語 教師簽名: 年 月 日一、實驗目的及內容目的:掌握和熟悉Matlab編程環(huán)境及語言;掌握圖像降噪算法和用途。內容:在課程教學和查閱相關文獻資料的基礎上,選擇下面一個數字圖像處理技術專題,實現(xiàn)相應算法進行仿真實驗,并完成大作業(yè)報告。專題如下:(1) 圖像增強處理技術;(2) 圖像降噪處理技術。2、題目分析 利用matlab的GU

2、I程序設計一個簡單實用的圖像處理程序。該程序應具備圖像處理的常用功能,以滿足用戶的使用?,F(xiàn)設計程序有以下基本功能:1)圖像的讀取和保存。2)通過自己輸入數值,實現(xiàn)圖像的旋轉。3)圖像直方圖統(tǒng)計和直方圖均衡,要求顯示直方圖統(tǒng)計,比較直方圖均衡后的效果。4)能對圖像加入各種噪聲,5)并通過幾種濾波算法實現(xiàn)去噪并顯示結果。6)將圖像轉化成灰度圖像。3.總體設計軟件的總體設計界面布局如上圖所示分為顯示區(qū)域與操作區(qū)域。上邊為顯示區(qū)域:顯示載入原圖,以及通過處理后的圖像。操作區(qū)域:通過功能鍵實現(xiàn)對圖像的各種處理。設計完成后運行的軟件界面如下:4、具體設計現(xiàn)介紹各個功能模塊的功能與實現(xiàn)。4.1圖像的讀取和保

3、存: (1)利用matlab中 “ uigetfile”、“imread” “imshow”實現(xiàn)圖像文件的讀取與顯示:實現(xiàn)代碼:function pushbutton2_Callback(hObject, eventdata, handles)% hObject handle to pushbutton2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)filename,p

4、athname=uigetfile('*.jpg''*.bmp''*.tif''*.*','載入圖像');if isequal(filename,0)|isequal(pathname,0) errordlg('沒有選中文件','出錯'); return;else file=pathname,filename; global S %設置一個全局變量S,保存初始圖像路徑,以便之后的還原操作 S=file; x=imread(file); set(handles.axes1,'H

5、andleVisibility','ON'); axes(handles.axes1); imshow(x); set(handles.axes1,'HandleVisibility','OFF'); axes(handles.axes2); imshow(x); handles.img=x; guidata(hObject,handles);end % - Executes on button press in pushbutton4.function pushbutton4_Callback(hObject, eventdata, h

6、andles)% hObject handle to pushbutton4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) sfilename ,sfilepath=uiputfile('*.jpg''*.bmp''*.tif''*.*','保存圖像文件','untitled.jpg

7、'); if isequal(sfilename,sfilepath,0,0) sfilefullname=sfilepath ,sfilename; imwrite(handles.img,sfilefullname); else msgbox('你按了取消鍵','保存失敗'); end(2)圖像保存。利用uiputfile和imwrite函數實現(xiàn)圖像文件的保存。實現(xiàn)代碼:function pushbutton4_Callback(hObject, eventdata, handles)% hObject handle to pushbutton4 (

8、see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) sfilename ,sfilepath=uiputfile('*.jpg''*.bmp''*.tif''*.*','保存圖像文件','untitled.jpg'); if isequal(sfilename,sfilepath,0

9、,0) sfilefullname=sfilepath ,sfilename; imwrite(handles.img,sfilefullname); else msgbox('你按了取消鍵','保存失敗'); end3) 程序的退出。實現(xiàn)代碼: function pushbutton5_Callback(hObject, eventdata, handles)% hObject handle to pushbutton5 (see GCBO)% eventdata reserved - to be defined in a future version of

10、MATLAB% handles structure with handles and user data (see GUIDATA)clc;close all;close(gcf);clear;4.2圖像轉化為灰度圖像因為matlab中較多的圖像處理函數支持對灰度圖像進行處理,故對圖像進行灰度轉化十分必要。利用rgb2gray(X)函數對其他圖像進行灰度圖像的轉化。實現(xiàn)代碼:function pushbutton11_Callback(hObject, eventdata, handles)% hObject handle to pushbutton11 (see GCBO)% eventda

11、ta reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global Taxes(handles.axes2);T=getimage;x=rgb2gray(handles.img); %RGB?×?imshow(x);handles.img=x;guidata(hObject,handles);4.3圖像直方圖統(tǒng)計和直方圖均衡(1)通過histeq(X)函數實現(xiàn)直方圖均衡。此函數只能對灰度圖像進行直方圖均衡所

12、以要先將彩圖轉為灰度圖像。實現(xiàn)代碼:function pushbutton12_Callback(hObject, eventdata, handles)% hObject handle to pushbutton12 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global Taxes(handles.axes2);T=getimage;h=histeq(handle

13、s.img); imshow(h);handles.img=h;guidata(hObject,handles); (2) 直方圖統(tǒng)計。通過利用imhist(X)函數來實現(xiàn)直方圖統(tǒng)計。實現(xiàn)代碼:function pushbutton13_Callback(hObject, eventdata, handles)% hObject handle to pushbutton13 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles an

14、d user data (see GUIDATA)axes(handles.axes2);x=imhist(handles.img); %直方圖統(tǒng)計x1=x(1:10:256);horz=1:10:256;bar(horz,x1);axis(0 255 0 15000);set(handles.axes2,'xtick',0:50:255);set(handles.axes2,'ytick',0:2000:15000); 4.4加入各種噪聲,并通過幾種濾波算法實現(xiàn)去噪(1)加入噪聲。通過imnoise(I,type,parameters)來加入各種噪聲。加入椒鹽

15、噪聲實現(xiàn)代碼:function pushbutton6_Callback(hObject, eventdata, handles)% hObject handle to pushbutton6 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global Taxes(handles.axes2);T=getimage; prompt='數日椒鹽噪聲參數1:'

16、 defans='0.02' p=inputdlg(prompt,'input',1,defans); p1=str2num(p1); f=imnoise(handles.img,'salt & pepper',p1); imshow(f); handles.img=f; guidata(hObject,handles);加入高斯噪聲:實現(xiàn)代碼:function pushbutton10_Callback(hObject, eventdata, handles)% hObject handle to pushbutton10 (see G

17、CBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global Taxes(handles.axes2);T=getimage; prompt='輸入高斯噪聲1:','輸入高斯噪聲2' defans='0','0.02' p=inputdlg(prompt,'input',1,defans); p1=str2

18、num(p1); p2=str2num(p2); f=imnoise(handles.img,'gaussian',p1,p2); imshow(f); handles.img=f; guidata(hObject,handles);加入乘性噪聲:實現(xiàn)代碼:function pushbutton8_Callback(hObject, eventdata, handles)% hObject handle to pushbutton8 (see GCBO)% eventdata reserved - to be defined in a future version of MAT

19、LAB% handles structure with handles and user data (see GUIDATA)global Taxes(handles.axes2);T=getimage; prompt='輸入乘性噪聲1:' defans='0.02' p=inputdlg(prompt,'input',1,defans); p1=str2num(p1); f=imnoise(handles.img,'speckle',p1); imshow(f); handles.img=f; guidata(hObject,h

20、andles); (2) 濾除噪聲(椒鹽噪聲)濾波前中值濾波后實現(xiàn)代碼:function pushbutton14_Callback(hObject, eventdata, handles)% hObject handle to pushbutton14 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global Taxes(handles.axes2); T=getim

21、age; k=medfilt2(handles.img); imshow(k); handles.img=k; guidata(hObject,handles);線性濾波后實現(xiàn)代碼:function pushbutton16_Callback(hObject, eventdata, handles)% hObject handle to pushbutton16 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user

22、 data (see GUIDATA)global Taxes(handles.axes2);T=getimage; h=1 1 1;1 1 1;1 1 1; H=h/9; i=double(handles.img); k=convn(i,h); imshow(k,); handles.img=k; guidata(hObject,handles);自適應濾波后實現(xiàn)代碼:function pushbutton18_Callback(hObject, eventdata, handles)% hObject handle to pushbutton18 (see GCBO)% eventdata

23、 reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global Taxes(handles.axes2);T=getimage; k=wiener2(handles.img,5,5); imshow(k); handles.img=k; guidata(hObject,handles);低通濾波器濾波后實現(xiàn)代碼:function pushbutton19_Callback(hObject, eventdata, ha

24、ndles)% hObject handle to pushbutton19 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)axes(handles.axes2);y1=handles.img; f=double(y1); % 數據類型轉換,matlab不支持圖像的無符號整型的計算g=fft2(f); % 傅里葉變換g=fftshift(g); % 轉換數據矩陣M,N=s

25、ize(g);nn=2; %二階巴特沃斯低通濾波器d0=50; %截止頻率50m=fix(M/2); n=fix(N/2);for i=1:M for j=1:N d=sqrt(i-m)2+(j-n)2); h=1/(1+0.414*(d/d0)(2*nn); % 計算低通濾波器傳遞函數 result(i,j)=h*g(i,j); endendresult=ifftshift(result);y2=ifft2(result);y3=uint8(real(y2);imshow(y3); % 顯示處理后的圖像高通濾波器濾波后實現(xiàn)代碼:function pushbutton20_Callback(h

26、Object, eventdata, handles)% hObject handle to pushbutton20 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)axes(handles.axes2);x=(handles.img); f=double(x); % 數據類型轉換k=fft2(f); % 傅里葉變換g=fftshift(k); % 轉換數據矩陣M,N=s

27、ize(g);nn=2;d0=25; %截止頻率25m=fix(M/2); n=fix(N/2);for i=1:M for j=1:N d=sqrt(i-m)2+(j-n)2); % 計算高通濾波器傳遞函數 if d<=d0 h=0; else h=1; end result(i,j)=h*g(i,j); endendresult=ifftshift(result);y2=ifft2(result);y3=uint8(real(y2);imshow(y3); % 顯示濾波處理后的圖像4.5還原通過一個全局變量保存原始圖像路徑,在需要還原至原始圖像時,重新讀取該全局變量即可。實現(xiàn)代碼:f

28、unction pushbutton21_Callback(hObject, eventdata, handles)% hObject handle to pushbutton21 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global S %還原 axes(handles.axes2); y=imread(S); f=imshow(y); handles.img=y

29、;guidata(hObject,handles);5、結果分析軟件測試基本成功,課題所要求的功能均能較好實現(xiàn)。但一些功能只支持灰度圖像的處理。其中值得一提的是在濾波處理中的低通濾波與高通濾波的效果。由于一般圖像中含有較多的低頻信息成分高頻成分較少,通過低通濾波后,噪聲以及高頻成分被濾除,圖像雖有少量失真,略顯模糊,但尚可辨識。但若是通過高通濾波后,大量的有效低頻信息被濾除,圖像嚴重失真,不可辨識。當我第一次拿到此次的課題時,感到有些無所適從。雖然,曾經學習過matlab的課程,在課程的考核中也取得了較好的成績,但由于對matlab的學習更多的只是停留在理論上的學習,在課時內的試驗也只是簡單的

30、基礎性試驗, 所以對matlab實際運用不是很熟練。 為此,在實踐正式開始前,我利用課余時間,重新復習了matlab教材,專門借閱了利用matlab進行圖像處理的相關教程,通過索引網絡上的相關資料,為課設做了較為充分的準備。在參考了相關材料及源程序,我對自己要做的課設內容有了進一步的了解,并對matlab的使用有了更深的體會。 當然,在課設的進行過程中,我還是遇到了不少問題。例如,起初由于我對句柄使用以及一些函數使用的不恰當,使得在對圖像文件的保存上就遇到了問題,不過最后還是在老師的提示下解決了。隨著課設的進行,對matlab的的熟悉度逐步加深。 總體來說,此次的課程設計,還是較為滿意的。它不

31、但鞭策著我去鞏固matlab的基礎理論知識,還提高了我對matlab的實際操作運用,使得理論與實踐相結合,為進一步學習matlab打下堅實的基礎;同時,在實踐的工程中,也讓我體會到一種努力付出并得到回報的滿足感覺。參考書目:(五號,宋體加粗)1 數字圖像處理(MATLAB)(第二版) 美Rafael C.Gonzalez 電子工業(yè)出版社附錄:(五號,宋體加粗)function varargout = faded(varargin)% FADED MATLAB code for faded.fig% FADED, by itself, creates a new FADED or raises

32、the existing% singleton*.% H = FADED returns the handle to a new FADED or the handle to% the existing singleton*.% FADED('CALLBACK',hObject,eventData,handles,.) calls the local% function named CALLBACK in FADED.M with the given input arguments.% FADED('Property','Value',.) cr

33、eates a new FADED or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before faded_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to faded_OpeningFcn via varargin.% *

34、See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one% instance to run (singleton)".% See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help faded % Last Modified by GUIDE v2.5 29-Dec-2015 22:05:27 % Begin initialization code - DO NOT EDI

35、Tgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, . 'gui_Singleton', gui_Singleton, . 'gui_OpeningFcn', faded_OpeningFcn, . 'gui_OutputFcn', faded_OutputFcn, . 'gui_LayoutFcn', , . 'gui_Callback', );if nargin && ischar(varargin1) gui

36、_State.gui_Callback = str2func(varargin1);end if nargout varargout1:nargout = gui_mainfcn(gui_State, varargin:);else gui_mainfcn(gui_State, varargin:);end% End initialization code - DO NOT EDIT % - Executes just before faded is made visible.function faded_OpeningFcn(hObject, eventdata, handles, vara

37、rgin)% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to faded (see VARARGIN) % Choose default command line outpu

38、t for fadedhandles.output = hObject; % Update handles structureguidata(hObject, handles); % UIWAIT makes faded wait for user response (see UIRESUME)% uiwait(handles.figure1); % - Outputs from this function are returned to the command line.function varargout = faded_OutputFcn(hObject, eventdata, hand

39、les) % varargout cell array for returning output args (see VARARGOUT);% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structurevarargout1 = handles.

40、output; % - Executes on button press in pushbutton2.function pushbutton2_Callback(hObject, eventdata, handles)% hObject handle to pushbutton2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)filename,pathname=uige

41、tfile('*.jpg''*.bmp''*.tif''*.*','載入圖像');if isequal(filename,0)|isequal(pathname,0) errordlg('沒有選中文件','出錯'); return;else file=pathname,filename; global S %設置一個全局變量S,保存初始圖像路徑,以便之后的還原操作 S=file; x=imread(file); set(handles.axes1,'HandleVisibil

42、ity','ON'); axes(handles.axes1); imshow(x); set(handles.axes1,'HandleVisibility','OFF'); axes(handles.axes2); imshow(x); handles.img=x; guidata(hObject,handles);end % - Executes on button press in pushbutton4.function pushbutton4_Callback(hObject, eventdata, handles)% hOb

43、ject handle to pushbutton4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) sfilename ,sfilepath=uiputfile('*.jpg''*.bmp''*.tif''*.*','保存圖像文件','untitled.jpg'); if i

44、sequal(sfilename,sfilepath,0,0) sfilefullname=sfilepath ,sfilename; imwrite(handles.img,sfilefullname); else msgbox('你按了取消鍵','保存失敗'); end % - Executes on button press in pushbutton5.function pushbutton5_Callback(hObject, eventdata, handles)% hObject handle to pushbutton5 (see GCBO)%

45、eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)clc;close all;close(gcf);clear; % - Executes on button press in pushbutton6.function pushbutton6_Callback(hObject, eventdata, handles)% hObject handle to pushbutton6 (see GCBO)

46、% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global Taxes(handles.axes2);T=getimage; prompt='數日椒鹽噪聲參數1:' defans='0.02' p=inputdlg(prompt,'input',1,defans); p1=str2num(p1); f=imnoise(handles.img,&

47、#39;salt & pepper',p1); imshow(f); handles.img=f; guidata(hObject,handles); % - Executes on button press in pushbutton7.function pushbutton7_Callback(hObject, eventdata, handles)% hObject handle to pushbutton7 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% hand

48、les structure with handles and user data (see GUIDATA) % - Executes on button press in pushbutton8.function pushbutton8_Callback(hObject, eventdata, handles)% hObject handle to pushbutton8 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles an

49、d user data (see GUIDATA)global Taxes(handles.axes2);T=getimage; prompt='輸入乘性噪聲1:' defans='0.02' p=inputdlg(prompt,'input',1,defans); p1=str2num(p1); f=imnoise(handles.img,'speckle',p1); imshow(f); handles.img=f; guidata(hObject,handles); % - Executes on button press

50、in pushbutton9.function pushbutton9_Callback(hObject, eventdata, handles)% hObject handle to pushbutton9 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) % - Executes on button press in pushbutton10.function push

51、button10_Callback(hObject, eventdata, handles)% hObject handle to pushbutton10 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global Taxes(handles.axes2);T=getimage; prompt='輸入高斯噪聲1:','輸入高斯噪聲2' d

52、efans='0','0.02' p=inputdlg(prompt,'input',1,defans); p1=str2num(p1); p2=str2num(p2); f=imnoise(handles.img,'gaussian',p1,p2); imshow(f); handles.img=f; guidata(hObject,handles); % - Executes on button press in pushbutton11.function pushbutton11_Callback(hObject, eventdata, handles)% hObject handle to pushbutton11 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global Taxes(handles.axes2);T=getimage;x=rgb2g

溫馨提示

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

評論

0/150

提交評論