声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2699|回复: 9

[GUI界面] GUI界面参数返回问题

[复制链接]
发表于 2007-5-25 17:22 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
各位大哥好:
     我编了一个界面,一个 popup读入图象,第二个 popup选择不同的方法对读入的图象进行处理。请问:对第一个 popup读入的图象怎么无损的传输到第二个 popup中。

[ 本帖最后由 eight 于 2007-5-25 17:34 编辑 ]
回复
分享到:

使用道具 举报

发表于 2007-5-25 17:34 | 显示全部楼层
原帖由 ymc0112 于 2007-5-25 17:22 发表
各位大哥好:
     我编了一个界面,一个 popup读入图象,第二个 popup选择不同的方法对读入的图象进行处理。请问:对第一个 popup读入的图象怎么无损的传输到第二个 popup中。


看本版关于 GUI 心得的精华贴
 楼主| 发表于 2007-5-25 18:00 | 显示全部楼层

回复 #2 eight 的帖子

看了,我用的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')
发表于 2007-5-25 18:14 | 显示全部楼层
原帖由 ymc0112 于 2007-5-25 18:00 发表
看了,我用的Global,可还是有问题。我的设计如下,请指教

function varargout = ymc(varargin)
% YMC M-filemenu for ymc.fig
%      YMC, by itself, creates a new YMC or raises the existing
%       ...


还是有问题——问题是什么?
 楼主| 发表于 2007-5-27 08:48 | 显示全部楼层

回复 #4 eight 的帖子

直接运行下面这个程序
sig=imread('cell.tif');
subplot(2,2,1);
imshow(sig);
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);
而运行上述界面程序,所得的结果相差很大.
请问是不是参数返回的数值不太正确
发表于 2007-5-27 21:48 | 显示全部楼层
原帖由 ymc0112 于 2007-5-27 08:48 发表
直接运行下面这个程序
sig=imread('cell.tif');
subplot(2,2,1);
imshow(sig);
rat=1/4;
sig=double(sig)/255;
subplot(2,2,2);
imshow(sig);
%%%%%%%%%%
%求图像大小
[m_sig,n_sig]=size(sig);
%%给 ...


有可能,建议自己调试一下
 楼主| 发表于 2007-5-29 16:45 | 显示全部楼层

回复 #6 eight 的帖子

请您看一下global I引用的是不是正确,谢谢
发表于 2007-5-29 16:49 | 显示全部楼层
原帖由 ymc0112 于 2007-5-29 16:45 发表
请您看一下global I引用的是不是正确,谢谢


popupmenu2_Callback 的那个放在最外面吧,即函数体第一行
 楼主| 发表于 2007-5-29 17:04 | 显示全部楼层
还是不行啊
发表于 2007-5-29 17:17 | 显示全部楼层
原帖由 ymc0112 于 2007-5-29 17:04 发表
还是不行啊


那建议还是自己记录、调试一下吧,反正你有一个标准答案在手,可以对比的
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-24 07:22 , Processed in 0.070838 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表