Create customizable polygonal ROI
creates a
roi
= drawpolygonPolygon
ROI object and enables interactive drawing of a
polygonal region-of-interest (ROI) on the current axes.
To draw the ROI, position the pointer on the image. The cursor changes to a fleur shape. Click to draw vertices of the polygon and drag to draw the lines between the vertices. To finish the ROI, double-click the mouse button. For more information about using the ROI, including keyboard shortcuts and context menu options, see Tips.
Note
drawpolygon
is a convenience function for creating a
Polygon
ROI object. If you create the ROI object
directly, calling Polygon
, you must call the draw
object
function to enable interactive drawing of the ROI. In contrast, the
drawpolygon
function creates the ROI object and calls
the draw
object function for you. Whichever way you
create the ROI, you use object properties, object functions, and event
notifications to customize its appearance and behavior. For more information
about using these capabilities, see Tips.
modifies the appearance and behavior of the ROI using one or more name-value pairs.
Unspecified name-value pairs are set to the default value.roi
= drawpolygon(___,Name,Value
)
The ROI supports the following interactivity, including keyboard shortcuts.
Behavior | Keyboard shortcut |
---|---|
Make drawn line snap at 15 degree angles. | Hold the Shift key while drawing. |
Finish drawing (close) the ROI. | Double-click, which adds a new vertex at the pointer position and draws a line to the first vertex to close the polygon. Press Enter, which adds a new vertex at the pointer position and draws a line to the first vertex to close the polygon. Right-click, which does not add a new vertex but closes the polygon from the previous vertex. Position pointer over the first vertex and click. |
Cancel drawing the ROI. | Press Esc. The function returns a valid ROI
object with an empty Position field. |
Add a new vertex to the ROI. | Position the pointer over the edge of the ROI and double-click. Position the pointer over the edge of the ROI, right-click, and select Add Vertex from the context menu. |
Remove the most recently added vertex but keep drawing. | Press Backspace. The function redraws the line from the previous vertex to the current position of the pointer. You can only back up to the first vertex you drew. |
Resize (reshape) the ROI | Position pointer over a vertex and then click and drag. Add a new vertex to the ROI and then click and drag. Remove a vertex. The ROI redraws the line connecting the two neighboring vertices. |
Move the ROI. | Position the pointer over the ROI (not on a vertex). The pointer changes to a fleur shape. Click and drag to move the ROI. |
Delete the ROI. | Position the pointer anywhere on the ROI and right-click.
Select Delete Polygon from the
context menu. You can also delete the ROI using the
delete object function. |
The
drawpolygon
function returns a Polygon
ROI object. After creation, use these capabilities of the
object to customize the appearance and behavior of the ROI.
Object properties — ROI objects support properties that modify their appearance or behavior. For example, to change the color of the roi
to yellow, set its Color
property, roi.Color = 'yellow'
.
Object functions — ROI objects support a set of object functions that operate on the ROIs. For example, if you want to pause the MATLAB command line after creating an ROI, call the wait
object function.
Event notifications — ROI objects can notify your code when certain events, such as being moved or clicked, happen to the ROI. To receive these notifications, use the addlistener
object function to set up listeners for specific events. In the listener, specify an event, such as 'ROIMoved'
, and a callback function that executes when the event occurs. When the ROI notifies your application through the listener, it returns data specific to the event. For example, with the 'ROIMoved'
event, the ROI object returns its previous position and its current position.
For an example of using event listeners with the Polygon
object, see Set Up Listener for Polygon ROI Events. For more
details about these capabilities, see the Polygon
object documentation.
drawassisted
| drawcircle
| drawcrosshair
| drawcuboid
| drawellipse
| drawfreehand
| drawline
| drawpoint
| drawpolyline
| drawrectangle
| Polygon