Polygon
Description
A Polygon object labels closed polygons in a
Viewer object. The properties of the object control the appearance and
behavior of the polygon annotation.
Viewer-based ROIs provide high-performance interactions with images and volumes you
display in a Viewer object using imageshow and
volshow, respectively. To draw a polygon on an
imshow image display, use drawpolygon
instead.
![]()
Creation
You can create a Polygon object in one of these ways:
Interactively draw a polygon within a 2-D
Viewerobject. From the viewer toolbar, select the draw annotations icon
, then select the draw polygon icon
. To draw the polygon, click to place vertices.
Double-click the last vertex to complete the polygon. To export the polygon to the
workspace as a polygonobject, right-click the edge of the polygon, and select Export annotation to workspace.Use the
uidrawfunction to interactively draw the ROI in a specified viewer and create the ROI object.Use the
images.ui.graphics.roi.Polygonfunction described here. After you create the ROI, you can display it by adding the object to theAnnotationsproperty of aViewerobject.
Description
p = images.ui.graphics.roi.Polygon creates a
Polygon object with default property values. Use
p to query and modify properties of the object after you
create it.
p = images.ui.graphics.roi.Polygon(Name=Value) sets one or
more writable properties using
name-value arguments.
Example:
images.ui.graphics.roi.Polygon(Position=[1 1; 10 1; 30 30; 1 20])
creates a polygon with four vertices at xy-coordinates of (1, 1),
(10, 1), (30, 30), and (1, 20).
Properties
Object Functions
createMask | Create binary mask image from ROI |
Examples
Tips
The
uidrawandimages.ui.graphics.roi.Polygonfunctions create ROIs to display in aViewerobject. Viewer-based ROIs provide high-performance interactions with images and volumes you display in aViewerobject usingimageshowandvolshow, respectively. To draw a polygon on animshowimage display, usedrawpolygoninstead.The ROI supports this interactivity, including keyboard shortcuts.
Behavior Interaction Add annotation From the viewer toolbar, select the draw annotations icon
, then select the draw polygon icon
. To draw the polygon, click to place
vertices.Make drawn line snap at 15 degree angles Hold Shift while drawing. Remove most recently added vertex, but continue drawing Press Backspace. The function redraws the line from the previous vertex to the current position of the pointer. You can only remove vertices added after the first vertex. Finish drawing annotation Double-click, which adds a new vertex at the pointer position, connecting the previous vertex to the first vertex.
Right-click, which finishes drawing the polygon without adding a new vertex.
Click the first vertex.
Cancel drawing annotation Press Esc. Add a new vertex to annotation Double-click the edge of the ROI.
Resize (reshape) annotation Drag an existing vertex.
Add a new vertex to the polygon and drag it.
Double-click an existing vertex to remove it. The ROI redraws the line connecting the two neighboring vertices. If a polygon has only three vertices, you cannot remove additional vertices in this way.
Move annotation Hold Ctrl and drag the ROI. Edit annotation label Right-click the ROI. From the context menu, select Edit label. When the label text highlights, type new text for the label. To finish editing, click outside the label. Remove annotation Right-click the ROI and choose Remove annotation from the context menu. Select Remove all annotations to remove all annotations in the viewer.
Version History
Introduced in R2026a
