Matlab图像处理创新实践-实验4【综合设计大实验——GUI综合设计】
- Matlab實(shí)驗(yàn)4——GUI程序操作說(shuō)明
目? ?錄
一、實(shí)驗(yàn)?zāi)康?/p>
二、實(shí)驗(yàn)內(nèi)容
三、實(shí)驗(yàn)過(guò)程及結(jié)果
步驟1:啟動(dòng)Matlab,在命令行窗口中輸入“guide”,新建GUI(創(chuàng)建空白GUI)。或者點(diǎn)擊“新建”再點(diǎn)擊“圖形用戶界面”,新建GUI。
步驟2:在左邊空間欄中選擇“Static Text”(靜態(tài)文本),將控件放入面板中,并右鍵單擊該控件,選擇“Property Inspector”(屬性檢查器)。
步驟3:在彈出的屬性對(duì)話框中,設(shè)置控件的屬性值。
步驟4:添加靜態(tài)文本控件后,再添加:可編輯文本(Edit Text)、軸(Axes)、按鈕(Push Button)等控件,右鍵點(diǎn)開其屬性框,修改他們的String屬性。右鍵點(diǎn)擊“打開”按鈕,選擇“查看回調(diào)”,點(diǎn)擊“Callback”。
步驟5:由于是先創(chuàng)建的“打開”按鈕,所以,“打開”按鈕對(duì)應(yīng)的控件名稱編號(hào)是1;控件名稱編號(hào)為1的下面編號(hào)為2的Callback對(duì)應(yīng)的則是“處理”按鈕。
步驟6:保存程序代碼,單擊菜單上的運(yùn)行圖形(Ctrl+T)按鈕,實(shí)現(xiàn)效果圖如下:
步驟7:在GUI圖形界面上,添加更多的控件,顯示多種濾波器的濾波效果。
步驟8:在GUI圖形界面上,添加更多的控件,顯示圖像的灰度圖、銳化效果圖。
四、分析與思考
附錄:代碼匯總
一、實(shí)驗(yàn)?zāi)康?/span>
掌握matlab環(huán)境下,圖形用戶界面(GUI)的設(shè)計(jì)方法;同時(shí)將學(xué)過(guò)的圖像處理方法和理論進(jìn)行綜合運(yùn)用和設(shè)計(jì)。
二、實(shí)驗(yàn)內(nèi)容
第一階段:根據(jù)為你們提供好的GUI說(shuō)明文檔,按照要求一步步進(jìn)行設(shè)計(jì),并最終完成一個(gè)基本的具有圖像處理功能的可視化程序。
第二階段:在第一階段工作基礎(chǔ)上,根據(jù)自己能力將該程序進(jìn)行適當(dāng)?shù)墓δ軘U(kuò)展。(比如,可以在用戶界面上實(shí)現(xiàn)其他濾波的操作、或者實(shí)現(xiàn)可調(diào)節(jié)的銳化操作等等)。盡量多發(fā)揮創(chuàng)造性,保證程序的個(gè)性化和獨(dú)特性,以防千篇一律導(dǎo)致分?jǐn)?shù)受影響。
相關(guān)主要函數(shù)說(shuō)明如下:
[filename pathname] = uigetfile({'*.jpg';'*.bmp';'*.png';'*.*'},'打開圖片'); % 打開文件對(duì)話框
str = [pathname filename]; % 將兩個(gè)字符串合并成一個(gè)字符串
axes(handles.axes1); % 打開axes1的句柄,對(duì)axes1進(jìn)行操作
三、實(shí)驗(yàn)過(guò)程及結(jié)果
【在這里描述下你的實(shí)驗(yàn)操作過(guò)程和相應(yīng)代碼,以及你得到的最終結(jié)果,需圖文并茂】
步驟1:啟動(dòng)Matlab,在命令行窗口中輸入“guide”,新建GUI(創(chuàng)建空白GUI)。或者點(diǎn)擊“新建”再點(diǎn)擊“圖形用戶界面”,新建GUI。
?
步驟2:在左邊空間欄中選擇“Static Text”(靜態(tài)文本),將控件放入面板中,并右鍵單擊該控件,選擇“Property Inspector”(屬性檢查器)。
?? ??
步驟3:在彈出的屬性對(duì)話框中,設(shè)置控件的屬性值。
步驟4:添加靜態(tài)文本控件后,再添加:可編輯文本(Edit Text)、軸(Axes)、按鈕(Push Button)等控件,右鍵點(diǎn)開其屬性框,修改他們的String屬性。右鍵點(diǎn)擊“打開”按鈕,選擇“查看回調(diào)”,點(diǎn)擊“Callback”。
步驟5:由于是先創(chuàng)建的“打開”按鈕,所以,“打開”按鈕對(duì)應(yīng)的控件名稱編號(hào)是1;控件名稱編號(hào)為1的下面編號(hào)為2的Callback對(duì)應(yīng)的則是“處理”按鈕。
在“打開”按鈕的callback函數(shù)下編寫代碼,完成對(duì)話框打開文件,并顯示在axes1控件框內(nèi)。然后在“處理”按鈕的callback函數(shù)下編寫代碼,讓其實(shí)現(xiàn):將兩個(gè)Edit Text文本框內(nèi)的數(shù)字轉(zhuǎn)換為高斯濾波器的參數(shù),并對(duì)打開的圖像進(jìn)行高斯濾波并顯示在axes2上。
步驟6:保存程序代碼,單擊菜單上的運(yùn)行圖形(Ctrl+T)按鈕,實(shí)現(xiàn)效果圖如下:
?
?
步驟7:在GUI圖形界面上,添加更多的控件,顯示多種濾波器的濾波效果。
步驟8:在GUI圖形界面上,添加更多的控件,顯示圖像的灰度圖、銳化效果圖。
利用double()將原圖像類型轉(zhuǎn)換為浮點(diǎn)型,然后按照“原圖像 + 邊緣圖像”的模式,進(jìn)行計(jì)算。利用uint8()或mat2gray()將得到的結(jié)果圖像,進(jìn)行類型轉(zhuǎn)換,并將原圖像和銳化后的圖像一同顯示在窗口中。
lotus.png四、分析與思考
【在此描述下你從該實(shí)驗(yàn)中的總結(jié)內(nèi)容,得出的結(jié)論,并對(duì)整個(gè)系統(tǒng)功能進(jìn)行評(píng)述,可以查閱資料,最后總結(jié)下整個(gè)課程的收獲。該部分占最終成績(jī)的50%】
此次試驗(yàn),獨(dú)立完成,收獲甚多。從0開發(fā)一個(gè)可以對(duì)圖片進(jìn)行濾波的GUI程序,令我對(duì)“圖像處理創(chuàng)新實(shí)踐”這門課有了更多的認(rèn)識(shí)。一個(gè)GUI程序,主要由兩個(gè)文件所構(gòu)成(.figure:界面文件;.m:程序文件)。使用Matlab可以對(duì)圖像進(jìn)行很多的操作,如:旋轉(zhuǎn)、裁剪、縮小及放大等基本功能,高斯濾波、平滑濾波、銳化濾波等濾波操作。
在GUI程序中,可以添加很多控件,分別實(shí)現(xiàn)不同的功能。在步驟8的程序中,設(shè)置了5個(gè)按鈕,分別實(shí)現(xiàn)“打開圖片”、“設(shè)置參數(shù)對(duì)圖片進(jìn)行濾波”、“顯示多種濾波效果”、“灰度處理”、“圖像銳化”等功能。在對(duì)圖像進(jìn)行處理的同時(shí),給圖像處理結(jié)果設(shè)置標(biāo)題,可以令使用者對(duì)圖像處理結(jié)果有更加直觀的體驗(yàn)。在“設(shè)置參數(shù)對(duì)圖片進(jìn)行濾波”的功能實(shí)現(xiàn)中,使用者可以設(shè)置濾波器的類型、尺寸以及方差,可以看到多種濾波器的不同濾波效果。
關(guān)于此GUI程序的評(píng)述:此GUI程序較為穩(wěn)定,內(nèi)容較為豐富,實(shí)現(xiàn)的功能涉及到本門課程的4篇實(shí)驗(yàn)報(bào)告,耗時(shí)較長(zhǎng),設(shè)計(jì)合理。
課程收獲總結(jié):非常感謝老師的指導(dǎo),我在本門課程中學(xué)到了很多知識(shí),學(xué)會(huì)了“使用Matlab對(duì)圖像進(jìn)行多種濾波處理”“使用Matlab涉及GUI程序”等重點(diǎn)內(nèi)容。但在課程的學(xué)習(xí)中,仍有很多不足,課下我會(huì)好好學(xué)習(xí)、多查資料、勤加練習(xí)。
評(píng)分標(biāo)準(zhǔn):①是否按時(shí)出勤實(shí)驗(yàn)課,實(shí)驗(yàn)任務(wù)是否全部完成,占50%;② 實(shí)驗(yàn)代碼及報(bào)告的格式是否規(guī)范,代碼是否注釋,是否美觀,是否詳盡,是否真實(shí),占40%;③? 實(shí)驗(yàn)作業(yè)及報(bào)告是否按時(shí)提交,占10%。
報(bào)告文件的命名格式:完整學(xué)號(hào)
例如:541807010101
附錄:代碼匯總
function varargout = experiment04(varargin) % EXPERIMENT04 MATLAB code for experiment04.fig % EXPERIMENT04, by itself, creates a new EXPERIMENT04 or raises the existing % singleton*. % % H = EXPERIMENT04 returns the handle to a new EXPERIMENT04 or the handle to % the existing singleton*. % % EXPERIMENT04('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in EXPERIMENT04.M with the given input arguments. % % EXPERIMENT04('Property','Value',...) creates a new EXPERIMENT04 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before experiment04_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to experiment04_OpeningFcn via varargin. % % *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 experiment04% Last Modified by GUIDE v2.5 21-Nov-2020 20:06:19% Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ...'gui_Singleton', gui_Singleton, ...'gui_OpeningFcn', @experiment04_OpeningFcn, ...'gui_OutputFcn', @experiment04_OutputFcn, ...'gui_LayoutFcn', [] , ...'gui_Callback', []); if nargin && ischar(varargin{1})gui_State.gui_Callback = str2func(varargin{1}); endif nargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); elsegui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT% --- Executes just before experiment04 is made visible. function experiment04_OpeningFcn(hObject, eventdata, handles, varargin) % 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 experiment04 (see VARARGIN)% Choose default command line output for experiment04 handles.output = hObject;% Update handles structure guidata(hObject, handles);% UIWAIT makes experiment04 wait for user response (see UIRESUME) % uiwait(handles.figure1);% --- Outputs from this function are returned to the command line. function varargout = experiment04_OutputFcn(hObject, eventdata, handles) % 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 structure varargout{1} = handles.output;function edit1_Callback(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit1 as text % str2double(get(hObject,'String')) returns contents of edit1 as a double% --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white'); endfunction edit2_Callback(hObject, eventdata, handles) % hObject handle to edit2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit2 as text % str2double(get(hObject,'String')) returns contents of edit2 as a double% --- Executes during object creation, after setting all properties. function edit2_CreateFcn(hObject, eventdata, handles) % hObject handle to edit2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have 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 pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)axis off % 去除刻度 % uigetfile:常規(guī)打開文件列表函數(shù)【filename:文件名;pathname:路徑;*.*:對(duì)應(yīng)所有文件】 [filename pathname] = uigetfile({'*.jpg';'*.bmp';'*.png';'*.*'}, '打開圖片'); % 函數(shù)返回值:文件名稱、文件路徑 str = [pathname filename]; % 合并字符串(合并文件名稱與路徑)global im; % 全局變量,其它函數(shù)也可以使用 im = imread(str); axes(handles.axes1); % 打開axes1(坐標(biāo)軸名)的句柄,對(duì)axes1進(jìn)行操作 設(shè)定圖像顯示到哪個(gè)組件上 axes:顯示圖像處理效果 str1 = ['圖片位置:' str]; imshow(im); title(str1);% --- 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)global im; gsize = get(handles.edit1, 'String'); % 通過(guò)句柄找到對(duì)應(yīng)的組件-尺寸 gsigma = get(handles.edit2, 'String'); % 通過(guò)句柄找到對(duì)應(yīng)的組件-方差 gtype = get(handles.edit3, 'String'); % 通過(guò)句柄找到對(duì)應(yīng)的組件-濾波器類型 f = fspecial(gtype, str2num(gsize), str2num(gsigma)); % str2num():字符串轉(zhuǎn)數(shù)字 im_f = imfilter(im, f);axes(handles.axes2); imshow(im_f); str = [gtype '濾波器;' '尺寸:' gsize ';方差:' gsigma]; % 合并字符串(合并文件名稱與路徑) title(str);% --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)global im;x = im; % 讀取圖片:將圖像數(shù)據(jù)讀取到Matlab環(huán)境中 smallx = imresize(x, 0.05); imshow(smallx); gx = rgb2gray(smallx);f1 = fspecial('average', 5); % 1、均值濾波器 gx1 = filter2(f1, gx); f2 = fspecial('gaussian'); % 2、高斯濾波器 gx2 = filter2(f2, gx); f3 = fspecial('laplacian'); % 3、拉普拉斯濾波器 gx3 = filter2(f3, gx); f4 = fspecial('sobel'); % 4、sobel濾波器 gx4 = filter2(f4, gx); f5 = fspecial('prewitt'); % 5、prewitt濾波器 gx5 = filter2(f5, gx); f6 = fspecial('disk'); % 6、disk濾波器 gx6 = filter2(f6, gx); f7 = fspecial('log'); % 7、log濾波器 gx7 = filter2(f7, gx); f8 = fspecial('motion'); % 8、motion濾波器 gx8 = filter2(f8, gx);axes(handles.axes3); imshow(smallx); title('縮小至原來(lái)的0.05倍'); axes(handles.axes4); imshow(uint8(gx1)); title('1、均值濾波器'); axes(handles.axes5); imshow(uint8(gx2)); title('2、高斯濾波器'); axes(handles.axes6); imshow(uint8(gx3)); title('3、拉普拉斯濾波器'); axes(handles.axes7); imshow(uint8(gx4)); title('4、sobel濾波器'); axes(handles.axes8); imshow(uint8(gx5)); title('5、prewitt濾波器'); axes(handles.axes9); imshow(uint8(gx6)); title('6、disk濾波器'); axes(handles.axes10); imshow(uint8(gx7)); title('7、log濾波器'); axes(handles.axes11); imshow(uint8(gx8)); title('8、motion濾波器');function edit3_Callback(hObject, eventdata, handles) % hObject handle to edit3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit3 as text % str2double(get(hObject,'String')) returns contents of edit3 as a double% --- Executes during object creation, after setting all properties. function edit3_CreateFcn(hObject, eventdata, handles) % hObject handle to edit3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have 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 pushbutton4. function pushbutton4_Callback(hObject, eventdata, handles) % 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)global im; x = im; % 讀取圖片:將圖像數(shù)據(jù)讀取到Matlab環(huán)境中 gx = rgb2gray(x); f1 = fspecial('average'); gx1 = filter2(f1, gx); axes(handles.axes12); imshow(uint8(gx1)); title('均值濾波器-灰度圖像處理');% --- Executes on button press in pushbutton5. function pushbutton5_Callback(hObject, eventdata, handles) % hObject handle to pushbutton5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global im; x = im; % 讀取圖片:將圖像數(shù)據(jù)讀取到Matlab環(huán)境中 gx = rgb2gray(x);F = fspecial('average', 66); % F = fspecial('prewitt', Size); y = filter2(F, gx); xy = double(gx) - y; % 進(jìn)行數(shù)據(jù)轉(zhuǎn)換,保證數(shù)據(jù)類型一致;高頻圖、輪廓、邊緣 sharpx = double(gx) + xy; % 原圖+輪廓:清晰度更高axes(handles.axes13); imshow(uint8(sharpx)); title('average濾波器圖像銳化');當(dāng)時(shí)寫了很久...
自己電腦💻上的Matlab沒(méi)辦法連接攝像頭,有點(diǎn)小遺憾...
總結(jié)
以上是生活随笔為你收集整理的Matlab图像处理创新实践-实验4【综合设计大实验——GUI综合设计】的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Bootstrap4+MySQL前后端综
- 下一篇: 分支界限算法【0-1背包问题】按照优先队