MATLAB Answers

0

I need to chose between two images for postprocessing using uibuttongroup. Why is not working?

Asked by Stelios Fanourakis on 3 Feb 2019
Latest activity Answered by Walter Roberson
on 3 Feb 2019
I have two images as Option 1 and Option 2.
How to make it run and user be able to chose among the two images?
Is it correct How I call it?
Img = bg;
I use
bg = uibuttongroup('Visible','off',...
'Position',[0 0 .2 1],...
'SelectionChangeFcn',@Do_plot);
r1 = uicontrol(bg,'Style',...
'radiobutton',...
'String','Option 1',...
'Position',[10 350 100 30],...
'HandleVisibility','off');
r2 = uicontrol(bg,'Style','radiobutton',...
'String','Option 2',...
'Position',[10 250 100 30],...
'HandleVisibility','off');
% Make the uibuttongroup visible after creating child objects.
bg.Visible = 'on';
Img = bg; %% This is the crucial point where the chosen image goes for more postprocessing.
function Do_plot(hObject, event, varargin)
bg = findobj(gcf,sel);
sel = bg.SelectedObject;
if isempty(sel)
return; %no buttons selected
end
sel_string = sel.String;
switch sel_string
case 'Option 1'
bg = double(croppedImage);
case 'Option 2'
bg = double(J);
end
end

  0 Comments

Sign in to comment.

1 Answer

Answer by Walter Roberson
on 3 Feb 2019

Img = bg;
would assign Img a copy of the handle to the button group. There is no numeric index or image associated with a button group.
You are trying to use callbacks as if they are functions that return values. The only kinds of callbacks that ever return values are the callbacks that act as position filters, such as a Position Constraint callback for an imroi. Callbacks for uicontrol, uipanel, axes, button groups, plots, surfaces, contour plots, patches: it is impossible for any of those to return a value. Likewise, graphics objects do not return values either. You can ask what the current state of a graphics object is.
Perhaps you need to read How To Share Variables in Callbacks

  0 Comments

Sign in to comment.