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

2 次查看(过去 30 天)
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]

回答(2 个)

Fangjun Jiang
Fangjun Jiang 2011-10-19
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 个评论
Fangjun Jiang
Fangjun Jiang 2011-10-19
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)

请先登录,再进行评论。


Naz
Naz 2011-10-19
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);

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by