how to make only one image as input for all buttons in gui?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
Matt Fig
2011년 4월 21일
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
Matt Fig
2011년 4월 23일
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....
추가 답변 (2개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!