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

1 vue (au cours des 30 derniers jours)
researcher
researcher le 21 Avr 2011
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?

Réponse acceptée

Matt Fig
Matt Fig le 21 Avr 2011
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 commentaires
Matt Fig
Matt Fig le 23 Avr 2011
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....
researcher
researcher le 24 Avr 2011
right Matt thanks I will try this also.

Connectez-vous pour commenter.

Plus de réponses (2)

researcher
researcher le 23 Avr 2011
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....:(

researcher
researcher le 23 Avr 2011
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?

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by