Clear Filters
Clear Filters

Can't draw a new imroi after deleting old one

1 view (last 30 days)
John Barrett
John Barrett on 25 Feb 2017
Commented: Marek on 15 Mar 2018
I have a simple GUI that allows me to select multiple regions of interest (ROIs) on an image for later analysis. However, if I delete one of the ROIs before I'm finished, attempting to draw a new ROI fails. Here's a minimum working example:
figure
imagesc(randn(1000,1000));
while true % obviously I use a more sensible stop condition in my actual code
imrect();
end
If I run the above, delete one of the ROIs, then try to draw a new one, I get the following error:
Error using iptSetPointerBehavior>parseInputs (line 134)
First input argument, h, contains one or more invalid handles.
Error in iptSetPointerBehavior (line 118)
[h, pointerBehavior] = parseInputs(varargin{:});
Error in manageInteractivePlacement/resetChildPointerManagement (line 154)
iptSetPointerBehavior(cached_pointer_behavior{k,1},...
Error in manageInteractivePlacement (line 105)
resetChildPointerManagement();
Error in imrect>imrectAPI (line 275)
placement_aborted = manageInteractivePlacement(h_axes,h_group,@placeRect);
Error in imrect (line 82)
[h_group,draw_api] = imrectAPI(varargin{:});
Is this a bug or is this a behaviour that could've been anticipated and should be handled with a try/catch block? If the latter, what exactly should I do to allow the user to keep drawing ROIs after deleting a previous one? Clearing the deleted ROI from memory avoids the error but leads to extremely strange behaviour, as in the following example:
figure
imagesc(randn(1000,1000));
while true
try
imrect();
catch err
clear ans;
end
end
Also, note that while I've used imrect in the examples, this also affects other imroi subclasses including imfreehand and impoly.
  3 Comments
John Barrett
John Barrett on 13 Mar 2018
Thanks for your comment. However, the ability to delete ROIs is important to the application that prompted this question. While the workaround you suggest is feasible, it would disrupt the flow of the UI, so it's not ideal. If it's a bug though I'll file a bug report with MathWorks.
Marek
Marek on 15 Mar 2018
I image that drawing ROIs in loop and possibility to delete misplaced ROIs would be convenient to user and easy to code. I have exact same problem but with imfreehand. In the end I come out with three possible solution:
  1. like I mention before block delete option draw all ROI and then unblock delete option
  2. create uimenu that runs single ROI drawing method and assign accelerator e.g. Ctrl + D and just draw ROIs one by one
  3. whenever user press right button on some ROI you need to cancel current drawing method and then allow user to perform some action, after that return to your drawing method
Option 3 look to complicated so I stick with second solution. So in my ui user just draw one by one and can use key shortcuts to speed up workflow.
If you are stubborn and do not want any workaround you can try findjobj from file exchange. It finds java object that represent some ui element and allows to run some java code, which gives more possibilities.
I reported this ROI problem as a bug last month but technical support just send my bunch of useless example and ignored problem, but I guess more people need to report bug before then do something about that.

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!