using addlistener in GUIDE

13 views (last 30 days)
marco penso
marco penso on 19 Feb 2020
Commented: marco penso on 19 Feb 2020
I am using addlistener in guide but I have the following error message:
Warning: Error occurred while executing the listener callback for event ROIMoved defined
for class images.roi.Circle:
Error using images.roi.internal.mixin.CreateMask/validateInputs
Ambiguous syntax. Associated axes contains more than one image. Specify image handle as
input argument to resolve ambiguity.
Error in images.roi.Freehand/createMask
Error in editFreehand (line 4)
tmask = hf.createMask();
Error in BasicGUI>@(varargin)editFreehand(hf,he) (line 211)
lf = addlistener(he,'ROIMoved', @(varargin)editFreehand(hf, he));
Error in images.roi.internal.ROI/stopDrag
Error in images.roi.internal.ROI
> In images.roi.internal/ROI/stopDrag
In images.roi.internal.ROI
Warning: Error occurred while executing the listener callback for event ROIMoved defined
for class images.roi.Circle:
Error using images.roi.internal.mixin.CreateMask/validateInputs
Ambiguous syntax. Associated axes contains more than one image. Specify image handle as
input argument to resolve ambiguity.
Error in images.roi.Freehand/createMask
Error in editFreehand (line 4)
tmask = hf.createMask();
Error in BasicGUI>@(varargin)editFreehand(hf,he) (line 211)
lf = addlistener(he,'ROIMoved', @(varargin)editFreehand(hf, he));
Error in images.roi.internal.ROI/stopDrag
The code is this one:
function pushbutton1_Callback(hObject, eventdata, handles)
... other code here ...
hf = drawfreehand('Position', [boundary(:,2), boundary(:,1)]);
he = images.roi.Circle(...
'Center', [50 50],...
'Radius', 5,...
'Parent', gca,...
'Color','r');
lh = addlistener(he,'MovingROI', @(varargin)editorROIMoving(he, hf));
lf = addlistener(he,'ROIMoved', @(varargin)editFreehand(hf, he));
handles.lf = lf;
setappdata(0,'lf',lf);
handles.lh = lh;
setappdata(0,'lh',lh);
handles.hf = hf;
setappdata(0,'hf',hf);
handles.he = he;
setappdata(0,'he',he);
guidata( hObject, handles);
end
and editFreehand
function editFreehand(hf, he, handles)
% Create a mask for the target freehand.
tmask = hf.createMask();
[m, n,~] = size(tmask);
% Include the boundary pixel locations
boundaryInd = sub2ind([m,n], hf.Position(:,2), hf.Position(:,1));
tmask(boundaryInd) = true;
% Create a mask from the editor ROI
emask = he.createMask();
boundaryInd = sub2ind([m,n], he.Position(:,2), he.Position(:,1));
emask(boundaryInd) = true;
% Check if center of the editor ROI is inside the target freehand. If you
% use a different editor ROI, ensure to update center computation.
center = he.Center; %
isAdd = hf.inROI(center(1), center(2));
if isAdd
% Add the editor mask to the freehand mask
newMask = tmask|emask;
else
% Delete out the part of the freehand which intersects the editor
newMask = tmask&~emask;
end
% Update the freehand ROI
perimPos = bwboundaries(newMask, 'noholes');
hf.Position = [perimPos{1}(:,2), perimPos{1}(:,1)];
end
I dont know why MovingROI works whereas ROIMoved gives problem.
  3 Comments
marco penso
marco penso on 19 Feb 2020
not yet because reading the documentation it is not clear how to do that.
createMask is not recommended. Use the createMask object function associated with the new ROI objects instead, described in Compatibility
Compatibility Considerations
createMask is not recommended
Not recommended starting in R2018b
marco penso
marco penso on 19 Feb 2020
ok I have done simply passing hImage = imshow(img,[]);
thank you

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!