ROI Creation Overview

The toolbox provides a set of objects to create regions of interest of various shapes, including circles, ellipses, polygons, lines, polygons, rectangles, and hand-drawn shapes. You can also draw freehand shapes that get "assistance" from the underlying image, automatically following the contour of edges. In this figure, you see a polygonal ROI drawn over an image.

The following is a complete list of ROI objects currently supported.

ROI Objects

The toolbox includes a set of ROI objects that you can use to create ROIs of various shapes, including circles, ellipses, polygons, rectangles, and hand-drawn shapes. Using these objects, 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 objects interactively is to create the object and then call the draw object function to initiate interactive drawing of the shape.

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

    I = imread('pears.png');
    imshow(I)
  2. Create an elliptical ROI on the image. The example creates an elliptical ROI object, using theStripeColor parameter to customize the look of the edge. The convenience function, drawellipse, automatically call the draw object function to initiate drawing of the shape on the image.

    roi = images.roi.ellipse('StripeColor','m');
  3. Call the draw object function 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.

    draw(roi)

ROI Creation Convenience Functions

As a convenience, the toolbox provides a set of functions that you can use to create the ROI objects. With the ROI objects, such as images.roi.Rectangle, you create the object and then call the draw object function to initiate drawing the shape. Alternately, you can call the corresponding convenience function, such as drawrectangle. The convenience function creates the ROI object and then calls the draw object function automatically for you. Whatever way you use to create the ROI object, you use the same object properties, object functions, and event support to customize its behavior and functioning.

The basic workflow when using ROI convenience functions is use the function to create the object. The convenience function automatically calls the draw object method.

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

    I = imread('pears.png');
    imshow(I)
  2. Create the ROI. The example creates an elliptical ROI using the drawellipse convenience function. The example specifies theStripeColor parameter to customize the look of the edge.

    roi = drawEllipse('StripeColor','m');

Using ROIs in Apps Created with App Designer

You can use ROIs in apps created with App Designer, parenting an ROI in a UIAxes. You must explicitly specify the UIAxes 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 a UIAxes in an app (UIFigure).

  1. Create a UIAxes. When you call the uiaxes function, it creates a UIFigure automatically.

    uax = uiaxes;

  2. Create the ROI in the UIAxes. Call any of the ROI creation functions, such as drawcircle, or the ROI classes, such as images.roi.Circle. Specify the UIAxes as an argument. Move the cursor over the axes, and click and drag the mouse to draw the ROI. The shape of the cursor does not change when used with a UIAxes.

    h = drawcircle(uax);

    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