I have question about using "handles" in Matlab Callback function. I don t know how to use the same thing twice. Please help me.
So,I build Matlab GUI and I have callback function for upload image:
function pushbutton2_Callback(hObject, eventdata, handles)
handles = guidata(hObject);
[filename pathname]=uigetfile({'*.jpg';'*.bmp'},'File Selector');
image=strcat(pathname, filename)
handles.data1=imread(image)
axes(handles.axes1);
imshow(handles.data1);
set(handles.edit1,'string',filename)
set(handles.edit2,'string',pathname)
guidata(hObject, handles);
,and I have callback fuction for converting the same image to "Gray Scale":
function Gray_Callback(hObject, eventdata, handles)
handles = guidata(hObject);
axes(handles.axes2);
img=handles.data1;
x=imread(img);
y=rgb2gray(x); %function to convert an rgb image to gray scale
imshow (y)
guidata(hObject, handles);
,but it doesn't work.
Does anyone know what I'm doing wrong?
Your first function says
handles.data1=imread(image)
Then your second function says
img=handles.data1;
x=imread(img);
Since img
contains image data, not the name of a file, what does imread(img)
mean?
I presume you want to work directly with the image data img
here, not use imread
at all.