Abort roipoly in GUIDE

3 views (last 30 days)
Xen on 17 Nov 2015
Commented: Adam on 19 Nov 2015
I created a GUI with axes that show the "slices" of a 3D matrix ( vol); a slider is used for skipping through the slices. In the slider's callback function I use roipoly to show each slice and manually segment an area from each slice.
function slider_draw_Callback(hObject, eventdata, handles)
% Get the current slice number.
slicen = round(get(hObject, 'Value'));
% Show the sliceand start drawing using roipoly.
[~, x, y] = roipoly(vol(:, :, slicen));
... some analysis with x, y...
Now, when I draw a polygon in each slice the roipoly works fine and saves x, y without issues. If I want to skip the 1st slice and draw something in the 2nd, roipoly is still "running" (crosshair visible) but can't draw anything when I click in the axes/image, giving me an eror in command window:
Error using waitfor
Error while evaluating figure WindowButtonMotionFcn
This is expected as roipoly needs a polygon to be drawn for it to be closed and then evoked again when I scroll to the next slice. How can I abort and restart roipoly when I press the slider buttons, essentially giving me the option to draw whenever I want? I've tried using uiwait/uiresume but can't make it work. Thanks.
  1 Comment
Xen on 19 Nov 2015
Edited: Xen on 19 Nov 2015
Anyone? I don't need a full solution/code, maybe a suggestion on what things might work and I should look at. Thanks again.

Sign in to comment.

Accepted Answer

Adam on 19 Nov 2015
I've only really used impoly, imroi and similar before myself. They actually return an object representing the active polygon which can be deleted, etc when required.
Even there though I tend to use a push button that I have to press if I want to draw on my image. Then only under the pushbutton does an impoly get created to draw on the image. Pressing 'Esc' can then cancel this if I change my mind.
So now having looked at roipoly, pressing 'Esc' seems to cancel this too so you probably can still do it under your slider callback rather than needing a separate button and just press Esc on a slice where you do not wish to actually draw.
Adam on 19 Nov 2015
It's a while since I used java.awt.Robot so I don't know if all it's actions get interpreted the same as keyboard equivalents when it comes to callbacks.
If you are putting it in the code though it suggests that you want to always miss this out for slice one, in which case wrapping the call to roipoly up in an if statement based on the slice number should also do the job.
Using 'Escape' I was assuming you made the decision whether or not to draw on the image at run time.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by