How can I share image data between callbacks?
1 回表示 (過去 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!