How to transfer a callback function of one pushbutton to other?
Ältere Kommentare anzeigen
I have created two pushbuttons one of them will browse images having code % --- Executes on button press in Browse_image. function Browse_image_Callback(hObject, eventdata, handles) % hObject handle to Browse_image (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) [filename direc]=uigetfile('*jpg','pick a file') if filename==0 return end image1=imread(fullfile(direc,filename)); axes(handles.axes1); imshow(image1); handles.Browse_image=fullfile(direc,filename); guidata(hObject,handles); set(handles.text1,'String',filename); which is in working condition...I want help in writing the callback function for other pushbutton to convert the scale of browsed image RGB to gray.
Antworten (1)
Geoff Hayes
am 11 Jun. 2014
Bearbeitet: Geoff Hayes
am 11 Jun. 2014
Rather than saving the path to the image to the handles structure like
handles.Browse_image=fullfile(direc,filename);
why not save the image itself as
handles.imageRgb = image1;
guidata(hObject,handles);
That way, in your other callback, you have the image and are not required to reload it via imread
function rgb2grayButton_Callback(hObject, eventdata, handles)
% get the image
imageRgb = handles.imageRgb;
% convert it to grayscale
imgageGs = rgb2gray(imageRgb);
% display it in some axes (to do)
2 Kommentare
Smriti bhaleshwar
am 12 Jun. 2014
Geoff Hayes
am 12 Jun. 2014
Right - so you have selected that file with uigetfile and then save that image data (as read in by imread) to the handles structure for later processing.
Kategorien
Mehr zu Convert Image Type finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!