This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

ROI Creation Overview

The toolbox provides a set of classes to create regions of interest of various shapes, including circles, ellipses, polygons, lines, polylines, points, and rectangles. You can also draw freehand shapes and freehand shapes that snap to edges in the image. In this figure, you see a polygonal ROI drawn over an image.

ROI Creation Classes

The toolbox includes ten classes that support ROI creation. You use these classes to create ROIs of certain shapes on an axes. These classes have properties, methods, and events that provide flexibility to ROI creation. Using these classes, you can draw ROIs interactively, using the mouse, or programmatically by specifying information about the size and shape of the ROI. Once you create the ROI object, you can perform operations on the ROI such as creating a mask. You can also control aspects of its behavior and appearance and respond to events that occur in the ROI, such as mouse clicks and movement.

The basic workflow when using the ROI classes interactively is to instantiate an object of the class and then call the draw method.

  1. Read an image into the MATLAB workspace and display it in a figure.

    I = imread('pears.png');
  2. Instantiate an ROI object. The example creates an elliptical ROI on the image, using theStripeColor parameter to customize the look of the edge.

    h = images.roi.Ellipse('StripeColor','m');
  3. Call the draw method of the Ellipse object to draw the ROI on the axes. When you move the mouse pointer over the image, the cursor changes to a crosshairs. Click and move the cursor over the image to create the elliptical shape. You can move the ellipse and change the shape of the ellipse interactively.


If you draw the ROI programmatically, you do not need to call the draw method. For more information, look at the class reference page for the ROI shape you want to create, such as, images.roi.Circle.

ROI Creation Functions

As a convenience, the toolbox provides ten functions that let you draw ROIs without directly calling the ROI classes. These functions create instances of the ROI classes.

The basic workflow when using these ROI convenience functions interactively is to call the function. The function instantiates the class and calls the draw method to start interactive placement of the ROI. You can specify the value of many different properties when you create the object using convenience functions, such as LineWidth and Color.

Using ROIs in Apps Created with App Designer

You can use ROIs in apps created with App Designer. However, you must use a standard Axes object in your app. You cannot parent an ROI in a UIAxes. In addition, you must explicitly specify the axes when calling the ROI creation function, as an input argument or using the 'Parent' name/value pair. There are a few limitations when using ROIs in apps in this way:

  • The mouse cursor does not update when you hover over the ROI. The cursor is always an arrow.

  • The ROI does not change color when you hover over it.

  • The ROI right-click menu (UIContextMenu) is not supported.

The following code, while not a typical app-creation workflow, shows how to specify an ROI in an Axes in an app (UIFigure).

  1. Create a UIFigure.

    fig = uifigure;

  2. Create an Axes in the UIFigure. You can only create ROIs in an Axes object, not a UIAxes object.

    ax = axes(fig);

  3. Create the ROI in the Axes. Call any of the ROI creation functions, such as drawcircle, specifying the Axes as an argument. Move the cursor over the axes and click and drag the mouse to draw the ROI.

    h = drawcircle(ax);

    You can also use any of the ROI creation classes, such as images.roi.Circle, to create the ROI. If you use the classes, you must also call the draw function specifying the ROI object as an argument.

Related Examples

More About