What is the equivalent of the function 'wait' after using 'imellipse' for the new function 'drawcircle' (version R2018b)?

21 views (last 30 days)
I am trying to use the new function 'drawcircle' to select a ROI and perform some analysis on a set of images.
Before, with the function 'imellipse', it was possible to interactively place an ellipse by clicking and dragging, then use wait to block the MATLAB® command line and finally double-click on the ellipse to resume execution of the MATLAB command line. See code below.
imshow('coins.png')
h = imellipse;
position = wait(h)
The function 'imellipse' still works but I would like to use the new function 'drawcircle' and do exactly the same. I can't seem to be able to find the solution to block and resume the execution of the command line. Therefore, my code is running to the end without taking into account the position of the modified ROI.

Accepted Answer

Matt J
Matt J on 18 Feb 2019
Edited: Matt J on 18 Feb 2019
Here's a (ch)easy workaround using the waitfordoubleclick.m file attached
drawcircle; waitfordoubleclick
You may have to adjust the clickInterval parameter in the file to your personal comfort.
  1 Comment
DJR
DJR on 18 Feb 2019
Edited: DJR on 18 Feb 2019
Thanks for that, it works perfectly fine! I am surprised there isn't an alternative to 'wait', it is probably just an omission (or I missed it). It defeats the purpose of having an interactive ROI otherwise.
Thanks again!

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 18 Feb 2019
I always hated that confirmation step. It was not obvious to users how to "accept" the shape and continue on. I guess you could put drawcircle in a loop and ask users if they want to draw it again or continue
subplot(1, 2, 1);
imshow('eight.tif'); % Display coins demo image.
title('Original Image -- DRAW HERE', 'FontSize', 20);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
promptMessage = sprintf('Do you want to Continue with the program,\nor redraw the circle?');
titleBarCaption = 'Continue?';
again = true;
while again
uiwait(helpdlg('Draw a circle'));
hROI = drawcircle();
% hROI.Deletable = true;
% waitfor(hROI);
% Get binary image and center coordinates.
mask = hROI.createMask();
centroidxy = hROI.Position
% See if user want this one or wants to redraw.
buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Redraw', 'Continue');
if contains(buttonText, 'Continue')
break; % Continue with the rest of the program after the while loop.
else
% Delete the unwanted image.ROI object.
delete(hROI);
end
end
subplot(1, 2, 2);
imshow(mask);
uiwait(helpdlg('Done!'));
title('Binary Image Mask', 'FontSize', 20);
I think there is a way to adjust it before continuing if you specify the callback, or use waitfor() or something like that.

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!