function varargout = Gui_Main(varargin) % GUI_MAIN MATLAB code for Gui_Main.fig % GUI_MAIN, by itself, creates a new GUI_MAIN or raises the existing % singleton*. % % H = GUI_MAIN returns the handle to a new GUI_MAIN or the handle to % the existing singleton*. % % GUI_MAIN('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in GUI_MAIN.M with the given input arguments. % % GUI_MAIN('Property','Value',...) creates a new GUI_MAIN or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Gui_Main_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Gui_Main_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 Gui_Main % Last Modified by GUIDE v2.5 20-Apr-2011 14:40:49 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Gui_Main_OpeningFcn, ... 'gui_OutputFcn', @Gui_Main_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end
时间: 2024-04-27 10:24:49 浏览: 134
这是一个MATLAB GUI程序的主函数,它定义了GUI的一些属性和回调函数。
具体功能:
1. 定义了一个结构体gui_State,用于存储GUI的属性和回调函数。
2. 如果有输入参数且第一个参数是字符类型,则将该参数作为回调函数名,并设置gui_State.gui_Callback为该回调函数。
3. 调用MATLAB的gui_mainfcn函数,创建GUI界面。
该函数根据输入参数的不同,可能会有输出参数。如果有输出参数,则返回gui_mainfcn函数的输出参数。
相关问题
function varargout = untitled1(varargin)
这是一个 MATLAB 代码文件的模板,用于定义一个函数。函数名称为 "untitled1",输入参数可以是任意数量和类型的,输出参数也可以是任意数量和类型的。函数体需要根据具体的需求进行修改。
以下是模板代码:
function varargout = untitled1(varargin)
% UNTITLED1 MATLAB code for untitled1.fig
% UNTITLED1, by itself, creates a new UNTITLED1 or raises the existing
% singleton*.
%
% H = UNTITLED1 returns the handle to a new UNTITLED1 or the handle to
% the existing singleton*.
%
% UNTITLED1('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UNTITLED1.M with the given input arguments.
%
% UNTITLED1('Property','Value',...) creates a new UNTITLED1 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before untitled1_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to untitled1_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 untitled1
% Last Modified by GUIDE v2.5 03-Jul-2021 19:01:56
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled1_OpeningFcn, ...
'gui_OutputFcn', @untitled1_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = 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 untitled1 is made visible.
function untitled1_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 untitled1 (see VARARGIN)
% Choose default command line output for untitled1
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes untitled1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = untitled1_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;
% --- 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)
% Hint: get(hObject,'Value') returns toggle state of pushbutton1
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(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 array
% 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 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'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
% hObject handle to checkbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox1
% --- Executes on button press in radiobutton1.
function radiobutton1_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton1
% --- Executes on button press in togglebutton1.
function togglebutton1_Callback(hObject, eventdata, handles)
% hObject handle to togglebutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of togglebutton1
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns position of slider
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on key press with focus on pushbutton1 and none of its controls.
function pushbutton1_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata structure with the following fields (see MATLAB.UI.CONTROL.UICONTROL)
% EventName: string 'KeyPress'
% Indices: row vector
% Key: character vector containing the key(s) that was pressed
% Modifier: cell array containing a modifier key string of 'alt', 'ctrl',
% or 'shift', if it was pressed or {} if it was not
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of pushbutton1
已知GUI界面中有名为axes2的图像显示区域, GUI界面中有名为zhifangtulei的按钮。要求matlabGUI界面续写下面基于retinex方法和直方图方法的图像增强完整代码并且通过调试:global s if ~isfield(handles, 'img') msgbox('请先选择图像!', 'error'); return end % 读取图像 im = handles.img; % 进行retinex增强 im_retinex = retinex(im); % 显示增强后的图像 axes(handles.axes2); imshow(im_retinex); % 保存增强后的图像 [pathname, filename, ext] = fileparts(s); imwrite(im_retinex, [pathname, filesep, 'retinex_', filename, ext]); % 保存数据 handles.im_retinex = im_retinex; guidata(hObject, handles); function im_retinex = retinex(im)和function zhifangtulei_Callback(hObject, eventdata, handles)
下面是基于retinex方法和直方图方法的图像增强完整代码:
```
function varargout = image_enhancement_gui(varargin)
% IMAGE_ENHANCEMENT_GUI MATLAB code for image_enhancement_gui.fig
% IMAGE_ENHANCEMENT_GUI, by itself, creates a new IMAGE_ENHANCEMENT_GUI or raises the existing
% singleton*.
%
% H = IMAGE_ENHANCEMENT_GUI returns the handle to a new IMAGE_ENHANCEMENT_GUI or the handle to
% the existing singleton*.
%
% IMAGE_ENHANCEMENT_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in IMAGE_ENHANCEMENT_GUI.M with the given input arguments.
%
% IMAGE_ENHANCEMENT_GUI('Property','Value',...) creates a new IMAGE_ENHANCEMENT_GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before image_enhancement_gui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to image_enhancement_gui_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 image_enhancement_gui
% Last Modified by GUIDE v2.5 25-Jul-2021 16:47:17
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @image_enhancement_gui_OpeningFcn, ...
'gui_OutputFcn', @image_enhancement_gui_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = 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 image_enhancement_gui is made visible.
function image_enhancement_gui_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 image_enhancement_gui (see VARARGIN)
% Choose default command line output for image_enhancement_gui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes image_enhancement_gui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = image_enhancement_gui_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;
% --- Executes on button press in open_btn.
function open_btn_Callback(hObject, eventdata, handles)
% hObject handle to open_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% 打开图像
[filename, pathname] = uigetfile({'*.bmp;*.jpg;*.jpeg;*.png;*.tif;*.tiff', 'Image Files (*.bmp, *.jpg, *.jpeg, *.png, *.tif, *.tiff)'}, '请选择一张图片');
if isequal(filename,0) || isequal(pathname,0)
msgbox('未选择图片', 'warn');
return;
end
s = fullfile(pathname, filename);
im = imread(s);
if size(im, 3) == 3
im = rgb2gray(im);
end
% 显示原始图像
axes(handles.axes1);
imshow(im);
% 保存数据
handles.img = im;
guidata(hObject, handles);
% --- Executes on button press in retinex_btn.
function retinex_btn_Callback(hObject, eventdata, handles)
% hObject handle to retinex_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ~isfield(handles, 'img')
msgbox('请先选择图像!', 'error');
return
end
% 读取图像
im = handles.img;
% 进行retinex增强
im_retinex = retinex(im);
% 显示增强后的图像
axes(handles.axes2);
imshow(im_retinex);
% 保存增强后的图像
[pathname, filename, ext] = fileparts(s);
imwrite(im_retinex, [pathname, filesep, 'retinex_', filename, ext]);
% 保存数据
handles.im_retinex = im_retinex;
guidata(hObject, handles);
% 定义retinex函数
function im_retinex = retinex(im)
% 进行retinex增强
im_log = log(double(im) + 1);
im_mean = mean2(im_log);
im_retinex = exp(im_log - im_mean);
% --- Executes on button press in zhifangtulei_btn.
function zhifangtulei_btn_Callback(hObject, eventdata, handles)
% hObject handle to zhifangtulei_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ~isfield(handles, 'img')
msgbox('请先选择图像!', 'error');
return
end
% 读取图像
im = handles.img;
% 进行直方图均衡化增强
im_zhifangtulei = histeq(im);
% 显示增强后的图像
axes(handles.axes2);
imshow(im_zhifangtulei);
% 保存增强后的图像
[pathname, filename, ext] = fileparts(s);
imwrite(im_zhifangtulei, [pathname, filesep, 'zhifangtulei_', filename, ext]);
% 保存数据
handles.im_zhifangtulei = im_zhifangtulei;
guidata(hObject, handles);
% --- Executes on button press in close_btn.
function close_btn_Callback(hObject, eventdata, handles)
% hObject handle to close_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% 关闭窗口
close(handles.figure1);
```
需要注意的是,在retinex_btn_Callback和zhifangtulei_btn_Callback中,增强后的图像保存路径和文件名的命名方式不一样,因为需要区分不同的增强方法。
阅读全文