Get handles from GUI img
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi,
I'm kind of new with GUI use in Matlab. I was working on a little script to find pixel under certains condition in a RGB image for a colleague, and I elect to go with a GUI.
So, first i build my GUI
fig = figure('units', 'pixels', ...
'position', [100 100 762 550], ...
'color',[0.9 0.9 0.9],...
'numbertitle','off',...
'menubar','none',...
'toolbar','figure',...
'name', 'Pixdef',...
'tag', 'Interface');
movegui(fig,'center');
.... % creation of button, editbox, etc
axes1 = axes('parent', fig,...
'units','normalized',...
'position',[0.09 0.14 0.82 0.82] ,...
'tag','img');
handles = guihandles(fig);
guidata(fig,handles)
Then, I proceed to put button, edit box, axes to plot my image and thing like that in this figure, and notably :
- A button to open a RGB image from a file and show it in the figure.
- A button to run some calcuation to detect pixel I want.
These button callback 2 different functions :
function openImg(obj,~)
h = get(obj,'parent');
handles = guidata(h);
[file, path] = uigetfile(cd,'Image choice','*.png;*.bmp;*.tiff;*.jpg');
imgRGB = imread(fullfile(path,file));
imgplot = imshow(imgRGB,'parent',axes1);
end
This one, to plot the image i want to analyse in my figure. It works as i want.
And the second one, where I run the calucation, which needs the handles of "imgRGB".
Thing is, I currnetly don't manage to get the data from imgRGB.
I'm pretty sure it's something simple and that it's because i'm rushing something i don't mastered (GUI in Matlab) but if someone could explain me how I can do, it would help me a lot !
Thanks,
Imra'
댓글 수: 0
채택된 답변
Adam
2019년 1월 30일
편집: Adam
2019년 1월 30일
Add
handles.imgRGB = imgRGB
guidata(h, handles)
in your above function, then if you get handles in your other function you can just access handles.imgRGB
댓글 수: 3
Adam
2019년 1월 30일
You should just be able to use
handles = guidata( obj )
assuminig obj is the first argument of your callback.
But if you haven't added the lines above to attach imgRGB to your handles and then write the handles back to the GUI it won't be there.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!