1、function varargout = mygui(varargin) % MYGUI M-file for mygui.fig % MYGUI, by itself, creates a new MYGUI or raises the existing % singleton*. % % H = MYGUI returns the handle to a new MYGUI or the handle to % the existing singleton*. % % MYGUI('CALLBACK',hObject,eve
2、ntData,handles,...) calls the local % function named CALLBACK in MYGUI.M with the given input arguments. % % MYGUI('Property','Value',...) creates a new MYGUI or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before m
3、ygui_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to mygui_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)".
4、 % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help mygui % Last Modified by GUIDE v2.5 18-May-2012 15:45:08 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'g
5、ui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @mygui_OpeningFcn, ... 'gui_OutputFcn', @mygui_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_C
6、allback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before mygui is made visible. function mygui_OpeningFcn(hObje
7、ct, 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 mygui (se
8、e VARARGIN) % Choose default command line output for mygui handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes mygui wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the comma
9、nd line. function varargout = mygui_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
10、 GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined
11、in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global im; [filename pathname]=uigetfile({'*.jpg';'*.bmp';'*.gif'},'选择图片'); str=[pathname filename]; im=imread(str); axes(handles.axes1); imshow(im); % --- Executes on button press in pushbutton2.
12、 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) close(gcf); % --- Executes on button press in pushbutt
13、on3. 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) % --- Executes when selected object is changed in
14、 uipanel1. function uipanel1_SelectionChangeFcn(hObject, eventdata, handles) % hObject handle to the selected object in uipanel1 % eventdata structure with the following fields (see UIBUTTONGROUP) % EventName: string 'SelectionChanged' (read only) % OldValue: handle of the previously selec
15、ted object or empty if none was selected % NewValue: handle of the currently selected object % handles structure with handles and user data (see GUIDATA) global im; str=get(hObject,'string'); axes(handles.axes1); switch str case '原图' imshow(im); case 'sobel' BW=e
16、dge(rgb2gray(im),'sobel'); imshow(BW); case 'prewitt' BW=edge(rgb2gray(im),'prewitt'); imshow(BW); case 'canny' BW=edge(rgb2gray(im),'canny'); imshow(BW); end % --- Executes on selection change in popupmenu1. function popupmenu1_Callback(
17、hObject, eventdata, handles) % hObject handle to popupmenu1 (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(hObject,'String')) returns popupmenu1 contents as cell a
18、rray % contents{get(hObject,'Value')} returns selected item from popupmenu1 % --- Executes during object creation, after setting all properties. function popupmenu1_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu1 (see GCBO) % eventdata reserved - to be defin
19、ed 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'), get(0,'defaultUicontrolBackground
20、Color')) set(hObject,'BackgroundColor','white'); end % -------------------------------------------------------------------- function Untitled_1_Callback(hObject, eventdata, handles) % hObject handle to Untitled_1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)






