Abort roipoly in GUIDE

1 visualizzazione (ultimi 30 giorni)
Xen
Xen il 17 Nov 2015
Commentato: Adam il 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.
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 Commento
Xen
Xen il 19 Nov 2015
Modificato: Xen il 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.

Accedi per commentare.

Risposta accettata

Adam
Adam il 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.
  2 Commenti
Xen
Xen il 19 Nov 2015
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 il 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.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by