我正在使用增加和减少锐度,图像对比度的功能,但问题是我必须从函数中获得增加或减少的锐度或对比度值以重用这些值。当在GUI中单击按钮时,会发生锐度或对比度增加或减少的功能。请帮助我使用和声明将在应用程序中使用的静态和全局变量。
主GUI文件
function varargout = Cotton_Disease_Detector(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Cotton_Disease_Detector_OpeningFcn, ...
'gui_OutputFcn', @Cotton_Disease_Detector_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
function Cotton_Disease_Detector_OpeningFcn(hObject, eventdata, handles, varargin)
axes(handles.axes1);
axis off
axes(handles.axes4);
axis off
axes(handles.axes5);
axis off
axes(handles.axes6);
axis off
handles.output = hObject;
guidata(hObject, handles);
function varargout = Cotton_Disease_Detector_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function browse_Callback(hObject, eventdata, handles)
image=browseImage();
imshow(image,'Parent',handles.axes1)
function segmentation_image_Callback(hObject, eventdata, handles)
image = imread('enhance.jpg');
image=imageSegmentation(image);
imshow(image,'Parent',handles.axes5);
function enhance_image_Callback(hObject, eventdata, handles)
image=imread('resize.jpg');
set(handles.enhancementPanel,'Visible','On')
image=imageEnhancement(image);
imwrite(image,'enhance.jpg');
imshow(image,'parent',handles.axes4);
function classification_image_Callback(hObject, eventdata, handles)
function feature_extraction_image_Callback(hObject, eventdata, handles)
function decreaseContrast_Callback(hObject, eventdata, handles)
image=imread('enhance.jpg');
[J,x]=decreaseContrast(image,x);
imwrite(J,'enhance.jpg');
imshow(J,'parent',handles.axes4);
function increaseContrast_Callback(hObject, eventdata, handles)
image=imread('enhance.jpg');
[J,x]=increaseContrast(image,x);
imwrite(J,'enhance.jpg');
imshow(J,'parent',handles.axes4);
function decreaseSharpness_Callback(hObject, eventdata, handles)
image=imread('enhance.jpg');
[J,x]=decreaseSharpness(image,x);
imwrite(J,'enhance.jpg');
imshow(J,'parent',handles.axes4);
function increaseSharpness_Callback(hObject, eventdata, handles)
image=imread('enhance.jpg');
[J,x]=increaseSharpness(image,x);
imwrite(J,'enhance.jpg');
imshow(J,'parent',handles.axes4);
function resizeImage_Callback(hObject, eventdata, handles)
image=imread('read.jpg');
image=resizeImage(image);
imwrite(image,'resize.jpg');
增加清晰度的功能
function [image,x] = increaseSharpness(image,x)
if isempty(x)
x=0.2;
end
x=x+0.2;
image=imsharpen(image,'radius',2,'Amount',x);
end
降低清晰度的功能
function [image,x] = decreaseSharpness(image,x)
if isempty(x)
x=0.2;
end
x=x-0.2;
image=imsharpen(image,'radius',2,'Amount',x);
end
增加减少的功能对比度与锐度相同。
答案 0 :(得分:2)
Matlab提供了直接在GUI对象上存储数据的方法,而不是使用全局变量。
This page对这些方法有很好的概述。
在调用之间共享数据的最合适方法是使用setappdata(hObject, name, value)
在GUI对象上存储值,并使用getappdata(hObject, name)
来检索它们。
另一种方法是使用guidata(hObject, data)
函数,允许您存储单个变量或结构。但是,GUIDE GUI使用此函数来存储句柄对象,因此首选setappdata方法。
[编辑基于@Hoki的评论]