how to make only one image as input for all buttons in gui?

Hi, I am currently working on a project which edits images. I want the user to select an image in the starting by clicking open button designed on GUI. Then I want that this image is edited for all the functionality buttons that are clicked, for eg: brighten, invert colors, deblur and so on. I do not want the user to select an image every time he clicks some functionality button. Is it possible?

 Accepted Answer

Yes, it is possible. Once the user has selected an image, set the 'enable' property of the image selection button to 'inactive'. Then when the image processing is complete and the image saved (or whatever) set the property back to 'on' for the next image.
I hope you do not mean that you programmed the GUI to prompt the user to open an image with every functionality button! If so, take that code out. Have the user prompted only with the first button. Then save the image in GUIDATA for access in other callbacks.
%
%
%
EDIT In response to your 'answers' below.
In your callback pushbutton6, you didn't store the handle in GUIDATA so it is not available later.
function pushbutton6_Callback(hObject, eventdata, handles)
H.Id = imread((uigetfile('*.JPG')));%read in the image file
H.Ih = imshow(H.Id)% display image in axis1
guidata(gcbf,H) % Store information in GUIDATA
Now in any other callback, you can access the image data (Id) and the image handle (Ih) by calling GUIDATA. For example, in your other callback,
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
H = guidata(gcbf);
g = rgb2gray(H.Id); % Use the same field name! H.Id is image data.
imshow(g);
% guidata(object_handles,data) Not necessary, nothing changed in data.
If you wanted to save g for later use, you will need to do something similar as in the first callback, i.e.,
H.g = rgb2gray(H.Id); % Save gray out put in H.
imshow(H.g);
guidata(gcbf,H) % Store in GUIDATA
Also, you may instead want to not store both the original and the gray data. If so, simply overwrite H.Id instead of assigning an new field, H.g. The more large data you have stored, the more chances that your program will experience lag...

10 Comments

hi Matt thanks but can I do the similar thing on next page?as in, can the user select image on first page and transport the selected image to the next page to carry out editing?
You need to define what you mean by "next page." GUIs don't have pages. What are you talking about?
By GUI i mean connected web pages type of something.i give the user the function color and he clicks it to go to the next page which has "gray" editing function and "invert".now is there anyway by which i can transport this image on to the next page?
I didn't ask what you meant by GUI, I asked what you meant by "Next Page." A GUI is just a MATLAB figure with uicontrols, axes and panels on it. No pages.
There is no MATLAB page object that I can see.
Do you mean that you are opening a new figure each time with the different editing function buttons on them? So you mean "New Figure" not "New Page?" Is that the case? If so, is the original figure kept open?
Basically I dont want to crowd the page with so may editing functions..so can i put something like pull down menu option?
Subiya, you again say, "the page" but don't explain what a page is. I cannot help you more if you don't clearly explain what a page is. When you say "page" do you mean a MATLAB figure?
I am trying my best to be as clear as I can possibly be. However I shall not quit. Yes matlab figure with buttons so is there a way to put pull down menu?
O.k., so we have established (I hope) that each "page" is actually a different MATLAB figure. Note that this will require a different approach than your original question. It would have been better to specify the whole problem from the start, but anyway.....
For example, instead of using GUIDATA, this new problem will be more easily solved by using FINDALL to get the handle to the image.
Ih = findall(0,'type','image'); % Image handle...
Id = get(Ih,'cdata') ; % Image data....
Now this can be done from any figure or the command line to access the image....
right Matt thanks I will try this also.

Sign in to comment.

More Answers (2)

hi Matt this is the call back of a button which selects image
function pushbutton6_Callback(hObject, eventdata, handles) handles.I = imread((uigetfile('*.JPG')));%read in the image file imshow(handles.I)% display image in axis1
now i want that the image selected in this part should be changed when user clicks a button which turns image to gray.for this i am using guidata as you said. However since i am new to matlab, i dont seem to get what the code should be.
I did this in the callback of the functionality button
function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) data = guidata(hObject) g=rgb2gray(data); imshow(g); guidata(hObject,data)
this is still not working....:(
code for function button callback which has to use the same image as the user selected.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data = guidata(object_handles)
g=rgb2gray(data);
imshow(g);
guidata(object_handles,data)
what should I put in place of Object_handles here?

Categories

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

Community Treasure Hunt

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

Start Hunting!