AssistedFreehand
R2026bAssisted freehand region of interest
Description
An AssistedFreehand object specifies the shape and position of an
axes-based hand-drawn region of interest (ROI), where the line drawn automatically follows
edges in the underlying image. You can customize the appearance and interactive behavior of
the ROI.
Axes-based ROIs enable you to draw and edit regions of interest
on images displayed using imshow or in MATLAB® axes. Axes-based ROIs offer maximum customization of appearance and behavior,
including line width, marker style, and edge color. Use axes-based ROIs for fine-grained control
over ROI appearance, integration with existing axes-based apps, or access to the assisted
freehand, crosshair, or cuboid ROI types. For a comparison of axes-based ROIs with other ROIs,
see Choose Approach to Annotate ROIs in Images.

For more information about using this ROI, including keyboard shortcuts, see Tips.
Creation
There are two ways to create an AssistedFreehand object. For more
information, see Create Axes-Based ROIs.
Use the
drawassistedfunction. Use this function when you want to create the ROI and set the appearance in a single command. You can specify the shape and position of the ROI interactively by drawing the ROI over an image using the mouse.Use the
images.roi.AssistedFreehandfunction described here. Use this function when you want to specify the appearance and behavior of the ROI before you specify the shape and position of the ROI. After creating the object, you can specify the shape and position interactively by using thedrawfunction.
Syntax
Description
creates an
roi = images.roi.AssistedFreehandAssistedFreehand object with default properties.
creates the ROI on the axes specified by roi = images.roi.AssistedFreehand(ax)ax.
sets writeable properties of the ROI using one or more name-value arguments.roi = images.roi.AssistedFreehand(___,Name=Value)
Example: images.roi.AssistedFreehand(Color="y") creates a yellow
colored AssistedFreehand object.
Input Arguments
Properties
Object Functions
addlistener | Create event listener bound to event source |
beginDrawingFromPoint | Begin drawing ROI from specified point |
bringToFront | Bring ROI to front of Axes stacking order |
createMask | Create binary mask image from ROI |
draw | Begin drawing ROI interactively |
inROI | Query if points are located in ROI |
reduce | Reduce density of points in ROI |
wait | Block MATLAB command line until ROI operation is finished |
Examples
More About
Tips
To draw the ROI interactively using the
drawordrawassistedfunction, position the pointer on the image, click and release to place the first vertex (waypoint). Then move the pointer to draw a line. As you draw, the line automatically follows the edges of objects in the image. Double-click to finish the ROI.The ROI supports the following interactivity, including keyboard shortcuts.
Behavior Keyboard shortcut Remove the most recently added waypoint but keep drawing. Press Backspace. The function redraws the line from the previous waypoint to the current position of the pointer. You can only back up to the first waypoint you drew. Cancel drawing the ROI. Press Esc. The function returns a valid ROI object with an empty Positionproperty.Finish drawing (close) the ROI. Double-click, which adds a point at the pointer position and draws a line connecting this point to the first point drawn, closing the ROI.
Right-click, which draws a line connecting the last point to the first point drawn.
Position the pointer over the first point and click.
Press Enter, which draws a line connecting the last point to the first point drawn.
Resize (reshape) the ROI. Position pointer over a waypoint and then click and drag. No assistance (snapping to edges) is available in this mode.
Add a waypoint. Position the pointer on an edge of the ROI, right-click, and select Add Waypoint. You can also position the pointer on an edge of the ROI and double-click.
Remove a waypoint. Position the pointer on a waypoint, right-click, and select Remove Waypoint.
Move the ROI. Position the pointer over the ROI. The pointer changes to the fleur shape. Click and drag to move the ROI. Delete an ROI. Position the pointer on the ROI (not on a vertex), right-click, and select Delete Freehand from the context menu. You can also delete the ROI programmatically using the deletefunction.

![{"String":"Figure contains an axes object. The axes object contains 2 objects of type image, images.roi.assistedfreehand.","Tex":[],"LaTex":[]}](../../examples/images/CreateAssistedFreehandROIExample_02.png)
