how to pass an image from a push button to function ?

조회 수: 9 (최근 30일)
Riya Augustine
Riya Augustine 2017년 3월 19일
댓글: Riya Augustine 2017년 3월 19일
I have created two push buttons to browse images for the original and target images and these images are taken for the further process.
function pushbutton1_Callback(hObject, eventdata, handles)
[original pathname1] = uigetfile({'*.jpg';'*.bmp'},'File Selector');
handles.originalImage = strcat(pathname1, original);
guidata(hObject,handles);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
[target pathname2] = uigetfile({'*.jpg';'*.bmp'},'File Selector');
handles.targetImage = strcat(pathname2, target);
guidata(hObject,handles);
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
proceed=msgbox('operation completed');
if isfield(handles,'originalImage')
original=msgbox('original image uploaded successfully');
im1=handles.originalImage
end
if isfield(handles,'targetImage')
target=msgbox('target image uploaded successfully');
im2=handles.targetImage
end
Mosaic=ritfn(im1,im2);
Another function
function [Mosaic] = ritfn(im1,im2)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
%Prepare Workspace
clear;clc;close all
%%Read Secret and Target images;
S=imread(im1); %Secret Image
T=imread(im2); %Target Image
M=256;
N=192;
S=imresize(S,[M,N]);
T=imresize(T,[M,N]);
end
But the problem is
Reference to a cleared variable im1.
Error in ritfn (line 7)
S=imread(im1); %Secret Image
Error in rdhgui>pushbutton3_Callback (line 101)
Mosaic=ritfn(im1,im2);
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in rdhgui (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)rdhgui('pushbutton3_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback

채택된 답변

Image Analyst
Image Analyst 2017년 3월 19일
When you cleared all variables in ritfn with this:
clear;clc;close all
you blew away im1 and im2. Delete that line!
Another problem you will encounter: ritfn() never assigns the output variable Mosaic, but you expect it to return a variable by that name.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by