Get handles from GUI img
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
Adam
el 30 de En. de 2019
Editada: Adam
el 30 de En. de 2019
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 comentarios
Adam
el 30 de En. de 2019
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!