Azzera filtri
Azzera filtri

how to get handle of an image opened in the GUI figure window, to be used in other callbacks.

3 visualizzazioni (ultimi 30 giorni)
let an editbox named parmeter1,whose value is to be used for other callback functions, can be used in other callbacks by code
a=str2num(get(handles.parameter1,'string'))
I am creating a gui where image is loaded in the gui figure window and is to be used in other callback functions like contrast adjustment. for this handle of the image is required. can anyone tell me the code for getting handle of an image file.
An answer with description would be better.
[SL: removed code formatting on the first line]

Risposte (2)

Fangjun Jiang
Fangjun Jiang il 19 Ott 2011
You must have an axes in your GUI. Let's say its tag is a. If you have an image shown in the axes, you can do this:
h=findobj(handles.a,'type','image');
  2 Commenti
Fangjun Jiang
Fangjun Jiang il 19 Ott 2011
No, Walter! I think this is the use case. The OP has a GUI developed using GUIDE. The GUI has at least an axes and two push buttons. One button is to load an image to the axes. The other button is to do some processing on the image. To do the processing, the OP needs to get the handle of the image object. a is the tag of the axes so handles.a is the handle of the axes.
Follow your approach, it could work but should be:
h=findobj(0,'type','image','parent',handles.a)

Accedi per commentare.


Naz
Naz il 19 Ott 2011
handles.a=str2num(get(handles.parameter1,'string')); %similar to global variable (don't know for sure)
guidata(hObject, handles); %this must be written at the end of each function to make sure the changes to the hadles are saved.
I am not sure if you need to initialize handles.a during the GUI initialization. Try it directly first.
For the second question, (assuming that you use 'axis' to display the picture) I believe that you need to make them active:
axes(handles.axes1);
imagesc(your_image);
Then, all operations on the axis will be performed on axis1. If you use the separate figure to display the image, then before operation you can make it active the following way:
figure(2); % activates new window for figure;
imagesc(your_image);

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by