Get handles from GUI img

3 visualizaciones (últimos 30 días)
Imra
Imra el 30 de En. de 2019
Comentada: Imra el 31 de En. de 2019
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'

Respuesta aceptada

Adam
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
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.
Imra
Imra el 31 de En. de 2019
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 !

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by