看了,我用的Global,可还是有问题。我的设计如下,请指教
function varargout = ymc(varargin)
% YMC M-filemenu for ymc.fig
% YMC, by itself, creates a new YMC or raises the existing
% singleton*.
%
% H = YMC returns the handle to a new YMC or the handle to
% the existing singleton*.
%
% YMC('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in YMC.M with the given input arguments.
%
% YMC('Property','Value',...) creates a new YMC or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ymc_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ymc_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
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help ymc
% Last Modified by GUIDE v2.5 25-May-2007 16:17:13
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ymc_OpeningFcn, ...
'gui_OutputFcn', @ymc_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 ymc is made visible.
function ymc_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 ymc (see VARARGIN)
% Choose default command line output for ymc
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes ymc wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = ymc_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 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 = get(hObject,'String') returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from
% popupmenu1
global I;
popup1_sel_index= get(handles.popupmenu1, 'Value');
v=get(handles.popupmenu1, 'string');
switch popup1_sel_index
case 1
I = uigetfile('*.tif');subplot(221);imshow(I);title('原始图象');
case 2
I = uigetfile('*.jpg');subplot(221);imshow(I);title('原始图象');
end
handles.metricdata.I= popup1_sel_index
guidata(hObject,handles)
% --- 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 selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns popupmenu2 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu2
popup_sel_index = get(handles.popupmenu2, 'Value');
switch popup_sel_index
case 1
%装载并显示原始图象
global I;
sig=I;
rat=1/4;
sig=double(sig)/255;
subplot(2,2,2);
imshow(sig);
%%%%%%%%%%
%求图像大小
[m_sig,n_sig]=size(sig);
%%给出图像分块尺寸和保留系数的个数
sizi=16;
Snum=64;
%分块处理
T=hadamard(sizi);
hdcoe=blkproc(sig,[sizi,sizi],'P1*x*P2',T,T);
%重新排列系数
coe=im2col(hdcoe,[sizi,sizi],'distinct');
coe_temp=coe;
[Y,Ind]=sort(coe);
%求得系数矩阵的大小
[m,n]=size(coe);
Snum=m-Snum;
for i=1:n
coe_temp(Ind(1:Snum),i)=0;
end;
%重建图像
re_hdcoe=col2im(coe_temp,[sizi,sizi],[m_sig,n_sig],'distinct');
re_sig=blkproc(re_hdcoe,[sizi,sizi],'P1*x*P2',T,T);
%%%%%%%%%%%%%%%%
subplot(2,2,3);
imshow(re_sig);
case 2
%装载并显示原始图象
global I;
X1=I;
c=255/log(256);x=0:1:255;y=c*log(1+x);
subplot(222),plot(x,y);
axis tight,xlabel('f'),ylabel('g');title('对数变换');
[m,n]=size(X1);
X2=double(X1);
for i=1:m
for j=1:n
g(i,j)=c*log(X2(i,j)+1);
end
end
subplot(223),imshow(mat2gray(g));
end
% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu2 (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 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)
selection = questdlg(['Close ' get(handles.figure1,'Name') '?'],...
['Close ' get(handles.figure1,'Name') '...'],...
'Yes','No','Yes');
if strcmp(selection,'No')
return;
end
delete(handles.figure1)
% --------------------------------------------------------------------
function FileMenu_Callback(hObject, eventdata, handles)
% hObject handle to FileMenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton4.
% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes1
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)
axes(handles.axes1);
cla;
% --------------------------------------------------------------------
function OpenMenu_Callback(hObject, eventdata, handles)
% hObject handle to OpenMenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
file = uigetfile('*.fig');
if ~isequal(file, 0)
open(file);
end
% --------------------------------------------------------------------
function closeMenu_Callback(hObject, eventdata, handles)
% hObject handle to closeMenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
selection = questdlg(['Close ' get(handles.figure1,'Name') '?'],...
['Close ' get(handles.figure1,'Name') '...'],...
'Yes','No','Yes');
if strcmp(selection,'No')
return;
end
delete(handles.figure1)
% --------------------------------------------------------------------
function saveMenu_Callback(hObject, eventdata, handles)
% hObject handle to saveMenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
selection = questdlg(['save ' get(handles.figure1,'Name') '?'],...
['save ' get(handles.figure1,'Name') '...'],...
'Yes','No','Yes');
if strcmp(selection,'No')
return;
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)
saveas(gcf, 'output', 'fig') |