how to make only one image as input for all buttons in gui?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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?
0 Commenti
Risposta accettata
Matt Fig
il 21 Apr 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 Commenti
Matt Fig
il 23 Apr 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....
Più risposte (2)
Vedere anche
Categorie
Scopri di più su Image Processing Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!