ROI-Based Processing

Define and operate on regions of interest (ROI)

A region of interest (ROI) is a portion of an image that you want to filter or perform some other operation on. You can create ROIs of many shapes using the high-level ROI functions, such as drawcircle or drawpolygon. You can also use ROI creation classes, such as images.roi.Circle or image.roi.Polygon. The ROI classes support properties, methods, and events that you can use to customize the behavior of the ROI.

A common use of an ROI is to create a binary mask image. In the mask image, pixels that belong to the ROI are set to 1 and pixels outside the ROI are set to 0. The ROI classes and functions support a createMask method. You can define more than one ROI in an image. Commonly, ROIs are groups of contiguous pixels but you can also define ROIs by intensity values, in which case the regions are not necessarily contiguous.


expand all

drawassistedCreate freehand ROI on image with assistance from image edges
drawcircleCreate customizable circular ROI
drawcuboidCreate customizable cuboidal ROI
drawellipseCreate customizable elliptical ROI
drawfreehandCreate customizable freehand ROI
drawlineCreate customizable linear ROI
drawpointCreate customizable point ROI
drawpolygonCreate customizable polygonal ROI
drawpolylineCreate customizable polyline ROI
drawrectangleCreate customizable rectangular ROI
createMaskCreate binary mask image from ROI
inROIQuery if points are located in ROI
bringToFrontBring ROI to the front of the Axes stacking order
roipolySpecify polygonal region of interest (ROI)
poly2maskConvert region of interest (ROI) polygon to region mask
regionfillFill in specified regions in image using inward interpolation
inpaintCoherentRestore specific image regions using coherence transport based image inpainting
roicolorSelect region of interest (ROI) based on color
roifilt2Filter region of interest (ROI) in image


expand all

images.roi.AssistedFreehandAssisted freehand region of interest
images.roi.CircleCircular region of interest
images.roi.CuboidCuboidal region of interest
images.roi.EllipseElliptical region of interest
images.roi.FreehandFreehand region of interest
images.roi.LineLine region of interest
images.roi.PointPoint region of interest
images.roi.PolygonPolygonal region of interest
images.roi.PolylinePolyline region of interest
images.roi.RectangleRectangular region of interest
drawBegin drawing ROI interactively
beginDrawingFromPointBegin drawing ROI from specified point


Filter ROIs and Create Masks

Overview of ROI Filtering

To filter a region of interest (ROI), first define a mask to separate the ROI from the background, then apply the filter to the ROI only.

Create a Binary Mask

A binary mask classifies image pixels as belonging to either the region of interest or the background.

Sharpen Region of Interest in an Image

This example shows how to use masked filtering to increase the sharpness of a specific region of interest.

Apply Custom Filter to Region of Interest in Image

This example shows how to define your own function and mask to filter a region of interest.

Fill Region of Interest in an Image

The process of filling a region of interest involves replacing all pixels in the region by interpolating inward from the boundary of the region.

Create Interactive ROIs Using Callback Functions

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.

Subsample or Simplify a Freehand ROI

This example shows how to subsample or reduce the number of points in a Freehand ROI object.

Use Polyline to Create An Angle Measurement Tool

This example shows the steps need to create a three-point measurement tool using a Polyline ROI

Measure Distances in an Image

This example shows how to use line ROIs to measure distances in an image.

Use Wait Function After Drawing ROI

This example shows how to define a custom wait function that blocks the MATLAB® command line until you finish positioning a rectangle.

Featured Examples