版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、20122013學年第二學期課程名稱:教學實踐:軟硬件提高訓練任課教師: 題 目:MATLAB數字圖像處理學號:ROB12023姓名: 年級:2012級專業(yè):自動化評語:成績: 評卷人:提交日期: 年 月 日1.設計目的利用MATLAB的GUI程序設計一個簡單實用的圖像處理程序。該程序應具備圖像處理的常用功能,以滿足要求。2.設計要求設計程序有以下基本功能:1)圖像的讀取、保存和程序退出2)圖像轉化為灰度圖像3)底片處理(反色)4)截圖5)亮度和對比度度調節(jié)6)圖像的翻轉與旋轉7)添加噪聲8)平滑和銳化9)直方圖均衡化處理10)圖像的腐蝕和膨脹11)邊緣檢測12)還原和撤銷3.總體設計4.程序
2、與運行結果4.1圖像的讀取、保存和程序退出1圖像讀取1)主要程序A=imread(str) %讀取圖片imshow(A) %顯示圖片2)運行結果 2圖像保存1)主要程序imwrite(handles.img,sfilefullname); %圖像的保存2)運行結果3退出1)主要程序close all; %關閉所有 2)運行結果(略)4.2圖像轉化為灰度圖像1)主要程序C=rgb2gray(img); %將rgb彩色圖像轉換為灰度圖2)運行結果4.3底片處理(反色)1)主要程序I=imcomplement(handles.img); %底片處理(反色)2)運行結果4.4截圖1)主要程序a=imc
3、rop(handles.img); %圖像的截取2)運行結果4.5亮度和對比度度調節(jié)1亮度調節(jié)1)主要程序y=imadjust(handles.img, , ,p1); %亮度調節(jié)2)運行結果2對比度調節(jié)1)主要程序f=immultiply(handles.img,p1); %對比度增強f=imdivide(handles.img,p1); %對比度減弱2)運行結果4.6圖像的翻轉與旋轉1圖像的翻轉1)主要程序fliplr(b) %圖像的翻轉2)運行結果2圖像的旋轉1)主要程序f=imrotate(handles.img,p1,'bilinear','crop'
4、); %圖像的旋轉2)運行結果 4.7添加噪聲1椒鹽噪聲1)主要程序f=imnoise(handles.img,'salt & pepper',p1); %添加椒鹽噪聲2)運行結果2高斯噪聲1)主要程序f=imnoise(handles.img,'gaussian',p1,p2); %添加高斯噪聲2)運行結果3乘法噪聲1)主要程序f=imnoise(handles.img,'speckle',p1); %添加乘法噪聲2)運行結果4.8平滑和銳化1平滑1)主要程序Imfilter % 均值濾波medfilt2 % 中值濾波2)運行結果2銳化
5、1)主要程序fspecial( ) %創(chuàng)建預定義的濾波算子imfilter( );imadd( ); %在實現卷積運算的基礎上進行濾波2)運行結果4.9直方圖均衡化處理1灰度圖像1)主要程序B=histeq(C); %直方圖均衡化函數2)運行結果2RGB圖像1)主要程序B=histeq(C); %直方圖均衡化函數2)運行結果4.10 圖像的腐蝕和膨脹1圖像的腐蝕1)主要程序I1=imerode(handles.img,se); %圖像的腐蝕2)運行結果2圖像的膨脹1)主要程序I1=imdilate(handles.img,se); %圖像的膨脹2)運行結果4.11 邊緣檢測 1)主要程序rsl
6、t=ycbcr2rgb(uint8(img2); %邊緣檢測2)運行結果4.12 還原和撤銷1還原1)主要程序global S %設計一個全局變量S,保存初始圖像路徑,以便之后的還原操作 2)運行結果2撤銷(只能撤銷一次)1)主要程序global T %設計一個全局變量S,保存每次操作原圖像,以便撤銷操作 2)運行結果5心得體會通過用()設計數字圖像處理界面,我掌握了有關數字圖像處理的相關知識和的操作知識,讓理論知識與實際相結合,做出了數字圖像處理的圖形用戶界面。在實踐前,通過一天的數字圖像處理的相關知識與一天的知識的學習,掌握了其基本入門知識;然后在實踐中,結合要設計要求補充自學相關知識,在
7、實踐中驗證理論知識,充實理論知識,加強動手能力;在實踐后,總結實踐過程,撰寫實驗報告,再次加深所學知識。6.附錄代碼(帶注釋)function varargout = dazouyematlab(varargin)%DAZOUYEMATLAB M-file for dazouyematlab.fig% DAZOUYEMATLAB, by itself, creates a new DAZOUYEMATLAB or raises the existing% singleton*.% H = DAZOUYEMATLAB returns the handle to a new DAZOUYEMATL
8、AB or the handle to% the existing singleton*.% DAZOUYEMATLAB('Property','Value',.) creates a new DAZOUYEMATLAB using the% given property value pairs. Unrecognized properties are passed via% varargin to dazouyematlab_OpeningFcn. This calling syntax produces a% warning when there is an
9、 existing singleton*.% DAZOUYEMATLAB('CALLBACK') and DAZOUYEMATLAB('CALLBACK',hObject,.) call the% local function named CALLBACK in DAZOUYEMATLAB.M with the given input% arguments.% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one% instance to run (singlet
10、on)".% See also: GUIDE, GUIDATA, GUIHANDLES% Edit the above text to modify the response to help dazouyematlab% Last Modified by GUIDE v2.5 18-Jul-2014 11:52:53% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, . 'gui_Singleton',
11、gui_Singleton, . 'gui_OpeningFcn', dazouyematlab_OpeningFcn, . 'gui_OutputFcn', dazouyematlab_OutputFcn, . 'gui_LayoutFcn', , . 'gui_Callback', );if nargin && ischar(varargin1) gui_State.gui_Callback = str2func(varargin1);endif nargout varargout1:nargout = gui
12、_mainfcn(gui_State, varargin:);else gui_mainfcn(gui_State, varargin:);end% End initialization code - DO NOT EDIT% - Executes just before dazouyematlab is made visible.function dazouyematlab_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject h
13、andle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin unrecognized PropertyName/PropertyValue pairs from the% command line (see VARARGIN)% Choose default command line output for dazouyematlabhandles.out
14、put = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes dazouyematlab wait for user response (see UIRESUME)% uiwait(handles.figure1);% - Outputs from this function are returned to the command line.function varargout = dazouyematlab_OutputFcn(hObject, eventdata, handles)% var
15、argout 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.output;% -
16、Executes on button press in pushbutton14.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)clc;close all;close(gcf);cle
17、ar;% - Executes on button press in pushbutton15.function pushbutton15_Callback(hObject, eventdata, handles)%圖像載入% hObject handle to pushbutton15 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)filename,pathname=u
18、igetfile('*.jpg''*.bmp''*.tif','選擇圖片'); str=pathname filename;global S %設計一個全局變量S,保存初始圖像路徑,以便之后的還原操作S=str;A=imread(str);set(handles.axes1,'HandleVisibility','ON');axes(handles.axes1);imshow(A);set(handles.axes1,'HandleVisibility','OFF')
19、;axes(handles.axes2); imshow(A);cla(handles.axes2);handles.img=A;guidata(hObject,handles);% - Executes on button press in pushbutton16.function pushbutton16_Callback(hObject, eventdata, handles)%圖像保存% hObject handle to pushbutton16 (see GCBO)% eventdata reserved - to be defined in a future version o
20、f MATLAB% handles structure with handles and user data (see GUIDATA)sfilename,sfilepath=uiputfile('*.jpg''*.bmp''*.tif''*.*','保存圖像文件','untitled.jpg');if isequal(sfilename,sfilepath,0,0) sfilefullname=sfilepath,sfilename; imwrite(handles.img,sfilefullna
21、me);else msgbox('取消保存','保存失敗');end% - Executes on button press in pushbutton22.function pushbutton22_Callback(hObject, eventdata, handles)%腐蝕% hObject handle to pushbutton22 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles a
22、nd user data (see GUIDATA)temp='腐蝕圓盤半徑:'defans='0'p=inputdlg(temp,'請輸入',1,defans);p1=str2num(p1);se=strel('disk',p1,0);global Taxes(handles.axes2);T=handles.img;I1=imerode(handles.img,se);imshow(I1); handles.img=I1;guidata(hObject,handles);% - Executes on button press
23、 in pushbutton23.function pushbutton23_Callback(hObject, eventdata, handles)%膨脹% hObject handle to pushbutton23 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)temp='膨脹結構長度:'defans='0'p=inputdlg(t
24、emp,'請輸入',1,defans);p1=str2num(p1);se=strel('line',p1,0);I1=imdilate(handles.img,se);global Taxes(handles.axes2);T=handles.img;imshow(I1);handles.img=I1;guidata(hObject,handles);% - Executes on button press in pushbutton21.function pushbutton21_Callback(hObject, eventdata, handles)%R
25、GB圖象% 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 Taxes(handles.axes2);T=handles.img;RGB=handles.img;R=RGB(:,:,1);G=RGB(:,:,2);B=RGB(:,:,3);G1(:,:,1)=histeq(R);G1(:,:,2)=
26、histeq(G);G1(:,:,3)=histeq(B);imshow(G1);handles.img=G1;guidata(hObject,handles);% - Executes on button press in pushbutton19.function pushbutton19_Callback(hObject, eventdata, handles)%添加噪聲% hObject handle to pushbutton19 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB%
27、 handles structure with handles and user data (see GUIDATA)I=handles.img;global Tstr=get(handles.popupmenu7,'value');axes(handles.axes2);switch str case 1 T=handles.img; prompt='輸入椒鹽噪聲參數1:' defans='0.02' p=inputdlg(prompt,'input',1,defans); p1=str2num(p1); f=imnoise(h
28、andles.img,'salt & pepper',p1); imshow(f); handles.img=f; guidata(hObject,handles); case 2 T=handles.img; prompt='輸入高斯噪聲1:','輸入高斯噪聲2' defans='0','0.02' p=inputdlg(prompt,'input',1,defans); p1=str2num(p1); p2=str2num(p2); f=imnoise(handles.img,'
29、gaussian',p1,p2); imshow(f); handles.img=f; guidata(hObject,handles); case 3 T=handles.img; 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)
30、; end% - Executes on selection change in popupmenu7.function popupmenu7_Callback(hObject, eventdata, handles)% hObject handle to popupmenu7 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: contents = cell
31、str(get(hObject,'String') returns popupmenu7 contents as cell array% contentsget(hObject,'Value') returns selected item from popupmenu7% - Executes during object creation, after setting all properties.function popupmenu7_CreateFcn(hObject, eventdata, handles)% hObject handle to popup
32、menu7 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: popupmenu controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'Backgroun
33、dColor'), get(0,'defaultUicontrolBackgroundColor') set(hObject,'BackgroundColor','white');end% - Executes on button press in pushbutton17.function pushbutton17_Callback(hObject, eventdata, handles)%平滑% hObject handle to pushbutton17 (see GCBO)% eventdata reserved - to be
34、defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global Tstr=get(handles.popupmenu5,'value');axes(handles.axes2);switch str case 1 T=handles.img; prompt='請輸入模版維度:' defans='3' p=inputdlg(prompt,'input',1,defans); p1=str2n
35、um(p1); h1=fspecial('average',p1 p1); I=imfilter(handles.img,h1); imshow(I); handles.img=I; guidata(hObject,handles); case 2 T=handles.img; prompt='請輸入模版維度:' defans='3' p=inputdlg(prompt,'input',1,defans); p1=str2num(p1); if numel(size(handles.img)>2 A=handles.img;
36、 R=A(:,:,1); G=A(:,:,2); B=A(:,:,3); GP(:,:,1)=medfilt2(R,p1 p1); GP(:,:,2)=medfilt2(G,p1 p1); GP(:,:,3)=medfilt2(B,p1 p1); imshow(GP); handles.img=GP; else A=handles.img; I=medfilt2(A,p1 p1); imshow(I); handles.img=I; end guidata(hObject,handles); end% - Executes on button press in pushbutton20.fun
37、ction pushbutton20_Callback(hObject, 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)clc;close all;close(gcf);clear;% - Executes on button press in pushbutton16
38、.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 data (see GUIDATA)global Tstr=get(handles.popupmenu5,'value');axes(handles.axes2)
39、;switch str case 1 T=handles.img; prompt='請輸入模版維度:' defans='3' p=inputdlg(prompt,'input',1,defans); p1=str2num(p1); h1=fspecial('average',p1 p1); I=imfilter(handles.img,h1); imshow(I); handles.img=I; guidata(hObject,handles); case 2 T=handles.img; prompt='請輸入模版維度:
40、' defans='3' p=inputdlg(prompt,'input',1,defans); p1=str2num(p1); if numel(size(handles.img)>2 A=handles.img; R=A(:,:,1); G=A(:,:,2); B=A(:,:,3); GP(:,:,1)=medfilt2(R,p1 p1); GP(:,:,2)=medfilt2(G,p1 p1); GP(:,:,3)=medfilt2(B,p1 p1); imshow(GP); handles.img=GP; else A=handles.i
41、mg; I=medfilt2(A,p1 p1); imshow(I); handles.img=I; end guidata(hObject,handles); end% - Executes on button press in pushbutton18.function pushbutton18_Callback(hObject, eventdata, handles)%銳化% hObject handle to pushbutton18 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB
42、% handles structure with handles and user data (see GUIDATA)global Tstr=get(handles.popupmenu6,'value');axes(handles.axes2);T=handles.img;g=handles.img;switch str case 1 h=fspecial('sobel'); case 2 h=fspecial('prewitt'); case 3 h=fspecial('laplacian');endif numel(size
43、(g)>2 R=g(:,:,1); G=g(:,:,2); B=g(:,:,3); R1=imfilter(R,h); GP(:,:,1)=imadd(R,R1); G1=imfilter(G,h); GP(:,:,2)=imadd(G,G1); B1=imfilter(B,h); GP(:,:,3)=imadd(B,B1); imshow(GP); handles.img=GP;else g1=g; g2=imfilter(g1,h); g3=imadd(g2,g1); imshow(g3); handles.img=g3;endguidata(hObject,handles);% -
44、 Executes on selection change in popupmenu5.function popupmenu5_Callback(hObject, eventdata, handles)% hObject handle to popupmenu5 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: contents = cellstr(get(
45、hObject,'String') returns popupmenu5 contents as cell array% contentsget(hObject,'Value') returns selected item from popupmenu5% - Executes during object creation, after setting all properties.function popupmenu5_CreateFcn(hObject, eventdata, handles)% hObject handle to popupmenu5 (s
46、ee GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: popupmenu controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor
47、39;), get(0,'defaultUicontrolBackgroundColor') set(hObject,'BackgroundColor','white');end% - Executes on selection change in popupmenu6.function popupmenu6_Callback(hObject, eventdata, handles)% hObject handle to popupmenu6 (see GCBO)% eventdata reserved - to be defined in a
48、future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: contents = cellstr(get(hObject,'String') returns popupmenu6 contents as cell array% contentsget(hObject,'Value') returns selected item from popupmenu6% - Executes during object creation, afte
49、r setting all properties.function popupmenu6_CreateFcn(hObject, eventdata, handles)% hObject handle to popupmenu6 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: popupmenu controls usually have
50、 a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor') set(hObject,'BackgroundColor','white');end% - Executes on button press in pushbutton10.function pushbutton10_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 Tstr=get(handles.popupmenu4,'value');axes(handles.axes2);if numel(size(handles.
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 醫(yī)療合同管理規(guī)范制度
- 第一單元+任務二《詩歌朗誦》課件-2024-2025學年統(tǒng)編版語文九年級上冊
- 石河子大學《影像診斷學》2021-2022學年第一學期期末試卷
- 防三無食品安全
- 石河子大學《包裝容器與紙盒結構》2023-2024學年第一學期期末試卷
- 沈陽理工大學《數據庫系統(tǒng)原理》2022-2023學年期末試卷
- 沈陽理工大學《科技文獻檢索與寫作》2022-2023學年第一學期期末試卷
- 沈陽理工大學《產品形導思維設計》2022-2023學年第一學期期末試卷
- 規(guī)范人事檔案和勞動合同
- 合股開店協(xié)議合同書模板
- 正弦交流電路相量
- 長沙市某辦公建筑的冰蓄冷空調系統(tǒng)的設計畢業(yè)設計
- 不抱怨的世界(課堂PPT)
- 企業(yè)盈利能力分析——以青島啤酒股份有限公司為例
- 消火栓滅火器檢查記錄表
- 岸墻、翼墻及導水墻砼澆筑方案
- 第三章_配位化學
- 中國話-完整版PPT課件
- 纏論基本概念圖解(推薦)
- 海瑞克英文翻譯
- 培訓師經常用到的七大培訓方式及操作方法
評論
0/150
提交評論