How to transfer a callback function of one pushbutton to other?

5 views (last 30 days)
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.

Answers (1)

Geoff Hayes
Geoff Hayes on 11 Jun 2014
Edited: Geoff Hayes on 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 Comments
Smriti bhaleshwar
Smriti bhaleshwar on 12 Jun 2014
Thanx Geoff,
Bt it is my projects requirement to select any one image from a folder of images for further process. I cant give particular image's name to read.
Geoff Hayes
Geoff Hayes on 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.

Sign in to comment.

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!