How can I share image data between callbacks?
2 次查看(过去 30 天)
显示 更早的评论
The code that I am using is :
function pushbutton1_Callback(hObject, eventdata, handles)
handles.pushbutton1 = imread(uigetfile);
axes(handles.axes1);
imshow(handles.pushbutton1);
guidata(hObject, handles);
function pushbutton2_Callback(hObject, eventdata, handles)
handles = guidata(hObject);
handles.y = rgb2gray(imread(handles.pushbutton1));
axes(handles.axes1);
imshow(handles.y);
guidata(hObject,handles);
I need to use the image that I have loaded using pushbutton1 in the callback of pushbutton2. pushbutton2 does the job of converting the image to grayscale. the error that I am getting is :
Error using imread>parse_inputs (line 458)
The filename or url argument must be a string.
Error in imread (line 317)
[filename, fmt_s, extraArgs] = parse_inputs(varargin{:});
Error in simpleplan3>pushbutton2_Callback (line 96)
handles.y = rgb2gray(imread(handles.imagedata.pushbutton1));
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in simpleplan3 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)simpleplan3('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
0 个评论
回答(1 个)
Sven
2014-4-10
Hi Saurabh,
This one has a simple solution. Note the call in your first function:
handles.pushbutton1 = imread(uigetfile);
After that function is finished, the contents of handles.pushbutton1 is the image matrix itself, and not the filename to the image. Therefore in the second function where you call:
handles.y = rgb2gray(imread(handles.pushbutton1));
You can simply replace that with:
handles.y = rgb2gray(handles.pushbutton1);
Did that answer your question?
Thanks, Sven.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!