How do I update an image in gui using selections?

1 view (last 30 days)
I created a GUI with check boxes and an indexed, labelled image of foot bones and the check boxes are of the names of the bones. I want the check boxes to cause a display on the axes of all of the bones corresponding to boxes that have been selected. How would I do this since the variables are not global? This is what I have now for distal phalange 1 and I was hoping to create an image that is the sum of all of the images resulting from the check boxes.
% --- Executes on button press in dp1.
function dp1_Callback(hObject, eventdata, handles)
% hObject handle to dp1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of dp1
dp1=zeros(680,498);
if (get(hObject,'Value')==get(hObject,'Max'))
axes(handles.axes1);
fl=imread('foot_label.png');
for q=1:680
for w=1:498
if fl(q,w)==14
dp1(q,w)=1;
end
end
imshow(double(dp1));
%+dp3+dp4+ mp1+mp2+mp3+mp4+mp5+ pp1pp2+pp3+pp4+pp5+ m1+m2+m3+m4+m5+mc+
%lc+ic+cu+ta+ca+ti
end
else
dp1=zeros(680,498);
end

Answers (2)

Joseph Cheng
Joseph Cheng on 24 Apr 2015
I see you've already know about the get(handles.(tag),'value') to get the state of the checkbox(s) so the question is in whatever button or checkbox update how do you access the image data or other stuff. Well you'd want to store them in the handles structure. For example in most of my GUIs i have a button called load which then goes through and reads, parses, conversions if need be, etc and stores them under handles.Raw which then in another button can be access for plotting, additional calculations, etc by referencing handles.Raw.temperature or handles.Raw.Volts.
  1 Comment
Joseph Cheng
Joseph Cheng on 24 Apr 2015
ah... after it was edited by Geoff Hayes (thank you Geoff its way too late on a friday to wade through it deeply) it might seem that you're in a push button? if you're in side a push button and you want to access the checkboxes use the get(handles.(tag),'Value') which tag is the tag assigned to the checkbox that you inserted. it probably has the default tag of checkbox1 to checkboxN unless you renamed them. by using hObject as you did there you'll only get the value from the pushbutton as that is the handle of the object passed to the callback function.
Another thing you could do to make it easier and less laborious to check each and every check box if you have lots of them. in each checkbox callback you flip a flag on a stored variable in handles. such as
function myGUI_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
handles.CheckboxChecked = zeroes(1,N) %where N is the number of checkboxes.
%where X is the specific checkbox callback
function checkboxX_Callback(hObject,eventdata,handles)
handles.CheckBoxFlags(X)=get(handles.checkboxX,'value');
then in your dp1_callback function (which is a button?) you can then figure out which boxes are checked by the values inside handles.CheckBoxFlags.

Sign in to comment.


Geoff Hayes
Geoff Hayes on 24 Apr 2015
Nina - if you wish to have one callback access the variables created in another callback (for example, your dp1) then you can use the handles structure to manage that data along with the function guidata to store that data.
Suppose you wish to store the dp1 from the above code. In your callback you would do something like
% --- Executes on button press in dp1.
function dp1_Callback(hObject, eventdata, handles)
% create dp1 as above
dp1 = ...;
% add dp1 to the structure
handles.dp1 = dp1;
% save the updated structure
guidata(hObject,handles);
Now in another callback you can access this data directly from handles as
handles.dp1
Is that what you would like to do?
  8 Comments
Geoff Hayes
Geoff Hayes on 25 Apr 2015
Nina - you have tried to use a function called updateImage but you have never defined what it does. All you have added is the callback for the DONE button. If you want your other callbacks to reference this one, then you mush replace the calls to updateImage with
done_Callback(handles.done,[],handles);
From this callback you can remove the line
handles = guidata(hObject);
as it isn't needed since you handles is being passed in as the third input.
Nina Friedly
Nina Friedly on 25 Apr 2015
That fixed it. I learned a lot, it's my first time using this. Thanks again!

Sign in to comment.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!