Use Wait Function After Drawing ROI
This example shows how to define a custom wait function that blocks the MATLAB® command line until you finish positioning a rectangle.
Display an image.
imshow('pears.png')
Draw a rectangle ROI in the top left corner of the image.
h = drawrectangle('Position',[1 1 100 100]);
Use a custom wait function to block the MATLAB command line while you interact with the rectangle. This example specifies a function called customWait
(defined at the end of the example).
While the command line is blocked, resize and reposition the rectangle so that it encompasses one pear. Double-click on the rectangle to resume execution of the customWait
function. The function returns the final position of the rectangle.
pos = customWait(h)
pos = 1×4
262.0000 36.0000 144.0000 145.0000
This is the custom wait function that blocks the program execution when you click an ROI. When you have finished interacting with the ROI, the function returns the position of the ROI.
function pos = customWait(hROI) % Listen for mouse clicks on the ROI l = addlistener(hROI,'ROIClicked',@clickCallback); % Block program execution uiwait; % Remove listener delete(l); % Return the current position pos = hROI.Position; end
This click callback function resumes program execution when you double-click the ROI. Note that event data is passed to the callback function as an images.roi.ROIClickedEventData
object, which enables you to define callback functions that respond to different types of actions. For example, you could define a callback function to resume program execution when you click the ROI while pressing the Shift key or when you click a specific part of the ROI such as the label.
function clickCallback(~,evt) if strcmp(evt.SelectionType,'double') uiresume; end end
See Also
drawrectangle
| Rectangle
| addlistener
| uiresume
| uiwait