A region of interest (ROI) is a portion of an image that you want to
filter or operate on in some way. The toolbox supports a set of ROI
objects that you can use to create ROIs of many shapes, such circles,
ellipses, polygons, rectangles, and hand-drawn shapes. After creation,
you can use ROI object properties to customize their appearance and
functioning. In addition, the ROI objects support object functions and
events that you can use to implement interactive behavior. For example,
using events, your application can execute custom code whenever the ROI
changes position. As a convenience, the toolbox includes a parallel set
of convenience functions for ROI creation. For example, to create a
rectangular ROI, you can use images.roi.Rectangle
or
the corresponding convenience function drawrectangle
.
For more information about ROIs, see ROI Creation Overview.
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
. To create a
mask, use the createMask
object functions supported
by most of the ROI objects. You can also create a mask without requiring
an image using the poly2mask
function.
Starting in R2018b, a new set of ROI objects replaced the previous set of ROI objects. The new objects provide better performance and more functional capabilities, such as face color transparency. With the new objects, you can also receive notification of interactions with the object, such as clicks or movement, using events. Although there are no plans to remove the old ROI objects at this time, switch to the new ROIs to take advantage of the additional capabilities and flexibility. For more information on migrating to the new ROIs, see ROI Migration.
You can create ROI objects that represent ROIs of various shapes, including circles, ellipses, polygons, lines, polylines, rectangles, and hand-drawn shapes.
Starting in R2018b, a new set of ROI objects replaced the previous set of ROI objects.
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.
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.
Subsample or Simplify a Freehand ROI
This example shows how to subsample or reduce the number of points in a Freehand
ROI object.
Rotate Image Interactively Using Rectangle ROI
This example shows how to rotate an image by using a Rectangle ROI with a callback function that calls imrotate
when you move the ROI.
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
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.