how to pass an image from a push button to function ?
3 views (last 30 days)
Show older comments
Riya Augustine
on 19 Mar 2017
Commented: Riya Augustine
on 19 Mar 2017
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
0 Comments
Accepted Answer
Image Analyst
on 19 Mar 2017
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.
More Answers (0)
See Also
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!