using addlistener in GUIDE
13 views (last 30 days)
Show older comments
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
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!