Get handles from GUI img

3 ビュー (過去 30 日間)
Imra
Imra 2019 年 1 月 30 日
コメント済み: Imra 2019 年 1 月 31 日
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'

採用された回答

Adam
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
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.
Imra
Imra 2019 年 1 月 31 日
Hey,
It seems I just didn't manage my handles correctly, I did some weird thing with how my function was built.
It is corrected now and it works fine. Thank you !

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by