how can i pass the output of one pushbutton to read as input to the other,i have posted my code ,here i want the output of 'read_image'(push button) to be as input of 'resize_image' (pushbutton)

2 次查看(过去 30 天)
function varargout = image_processing(varargin)
% IMAGE_PROCESSING M-file for image_processing.fig
% IMAGE_PROCESSING, by itself, creates a new IMAGE_PROCESSING or raises the existing
% singleton*.
%
% H = IMAGE_PROCESSING returns the handle to a new IMAGE_PROCESSING or the handle to
% the existing singleton*.
%
% IMAGE_PROCESSING('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in IMAGE_PROCESSING.M with the given input arguments.
%
% IMAGE_PROCESSING('Property','Value',...) creates a new IMAGE_PROCESSING or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before image_processing_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to image_processing_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_processing
% Last Modified by GUIDE v2.5 27-Dec-2015 09:51:22
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @image_processing_OpeningFcn, ...
'gui_OutputFcn', @image_processing_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_processing is made visible.
function image_processing_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_processing (see VARARGIN)
% Choose default command line output for image_processing
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes image_processing wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = image_processing_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 rgb_gray.
function read_image_Callback(hObject, eventdata, handles)
% hObject handle to rgb_gray (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axis(handles.axes1);
a=imread('night.jpg');
imshow(a,'parent',handles.axes1);
% --- Executes on button press in rgb_gray.
function rgb_gray_Callback(hObject, eventdata, handles)
% hObject handle to rgb_gray (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 resize_image.
function resize_image_Callback(hObject, eventdata, handles)
% hObject handle to resize_image (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axis(handles.axes1);
b=imresize(a,[256,256]);
imshow(b,'parent',handles.axes1);
  1 个评论
Walter Roberson
Walter Roberson 2015-12-31
[Copied from duplicate question]
actually i am reading an image in a pushbutton and now i have to resize this image through other push button and many more conversions(rgb2gray,image matching) but i dont wan to read image for every conversion so i want the code that can create and save a output variable from 1st push button and i can have it as input to the other .

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2015-12-27
uicontrol callbacks do not have outputs. Very few callbacks have outputs.
  3 个评论
Walter Roberson
Walter Roberson 2015-12-31
You only needed the information from the link. For example,
% --- Executes on button press in rgb_gray.
function read_image_Callback(hObject, eventdata, handles)
% hObject handle to rgb_gray (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axis(handles.axes1);
a=imread('night.jpg');
imshow(a,'parent',handles.axes1);
handles.original_image = a; %new
handles.current_image = a; %new
guidata(hObject, handles); %new
% --- Executes on button press in resize_image.
function resize_image_Callback(hObject, eventdata, handles)
% hObject handle to resize_image (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axis(handles.axes1);
a = handles.current_image; %new
b=imresize(a,[256,256]);
imshow(b,'parent',handles.axes1);
handles.current_image = b; %new
guidata(hObject, handles); %new
That is, you store whatever information you want in the handles structure, and then you guidata() to save the change to the master copy. Then later you can pull it out of the handles structure and use it, and even change it (remembering to use guidata() to save the change to the master copy.)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by