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

조회 수: 3 (최근 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]
  댓글 수: 1
KAE
KAE 2018년 5월 4일
Can someone with better reputation than me please edit the question to remove the unnecessary code formatting?

댓글을 달려면 로그인하십시오.

답변 (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
Walter Roberson
Walter Roberson 2011년 10월 19일
If its tag is 'a' then the code would be
h = findobj(0,'type','image','tag','a');
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에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by