Abort roipoly in GUIDE

1 次查看(过去 30 天)
Xen
Xen 2015-11-17
评论: Adam 2015-11-19
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.
axes(handles.axes_image);
[~, 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 个评论
Xen
Xen 2015-11-19
编辑:Xen 2015-11-19
Anyone? I don't need a full solution/code, maybe a suggestion on what things might work and I should look at. Thanks again.

请先登录,再进行评论。

采纳的回答

Adam
Adam 2015-11-19
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.
  2 个评论
Xen
Xen 2015-11-19
It's strange because earlier I tried pressing ESCAPE automatically before calling roipoly in the slider's callback and didn't work (by evoking java.awt.Robot class, this generally works in other cases). So I assumed ESCAPE doesn't work, but now I checked manually pressing the key and for some reason it works! It can be a bit confusing until I get used to it, and still gives me those errors in the command window, but is a solution.
So thanks Adam.
Adam
Adam 2015-11-19
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.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by