Rectangle
Description
A Rectangle object labels a rectangle in a
Viewer object. The properties of the object control the appearance and
behavior of the rectangle 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 rectangle on an
imshow image display, use drawrectangle
instead.
![]()
Creation
You can create a Rectangle object in these ways:
Interactively draw a rectangle in a 2-D
Viewerobject. From the viewer toolbar, select the draw annotations icon
, then select the draw rectangle icon
. To draw the rectangle, click to place one corner of
the rectangle, drag to the opposite corner of the rectangle, and release. To export the
rectangle to the workspace as a Rectangleobject, right-click the edge of the rectangle 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.Rectanglefunction described here. After you create the ROI, you can display it by adding the object to theAnnotationsproperty of aViewerobject.
Description
r = images.ui.graphics.roi.Rectangle creates a
Rectangle object with default property values. Use
r to query and modify properties of the Rectangle
object after you create it.
r = images.ui.graphics.roi.Rectangle(Name=Value) sets one or more
writable properties using name-value
arguments.
Example: images.ui.graphics.roi.Rectangle(Position=[128 64 200 100])
creates a rectangle annotation with a width of 200 pixels and height of 100 pixels. The
upper-left corner of the rectangle is at the xy-coordinate (128,
64).
Properties
Object Functions
createMask | Create binary mask image from ROI |
Examples
Tips
The
uidrawandimages.ui.graphics.roi.Rectanglefunctions 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 rectangle on animshowimage display, usedrawrectangleinstead.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 rectangle icon
. To draw the rectangle, click to place one
corner of the rectangle, drag to the opposite corner of the rectangle, and
release. Hold Shift while you drag to draw a
square.Resize (reshape) annotation Drag a vertex on the corner of the rectangle to resize it in both dimensions, or drag a vertex on an edge of the rectangle to resize it in only one dimension. To preserve the aspect ratio while resizing, hold Shift while you drag.
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
