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!