|On this page…|
A region of interest (ROI) is a portion of an image that you want to filter or perform some other operation on. You define an ROI by creating a binary mask, which is a binary image that is the same size as the image you want to process with pixels that define the ROI set to 1 and all other pixels set to 0.
You can define more than one ROI in an image. The regions can be geographic in nature, such as polygons that encompass contiguous pixels, or they can be defined by a range of intensities. In the latter case, the pixels are not necessarily contiguous.
This section describes how to create binary masks to define ROIs. However, any binary image can be used as a mask, provided that the binary image is the same size as the image being filtered. For example, suppose you want to filter the grayscale image I, filtering only those pixels whose values are greater than 0.5. You can create the appropriate mask with this command: BW = (I > 0.5).
You can use the createMask method of the imroi base class to create a binary mask for any type of ROI object — impoint, imline, imrect, imellipse, impoly, or imfreehand. The createMask method returns a binary image the same size as the input image, containing 1s inside the ROI and 0s everywhere else.
The example below illustrates how to use the createMask method:
img = imread('pout.tif'); h_im = imshow(img); e = imellipse(gca,[55 10 120 120]); BW = createMask(e,h_im);
You can reposition the mask by dragging it with the mouse. Right click, select copy position, and call createMask again.
BW = createMask(e,h_im);
The mask behaves like a cookie cutter and can be repositioned repeatedly to select new ROIs.
Using the createMask method of ROI objects you can create a binary mask that defines an ROI associated with a particular image. To create a binary mask without having an associated image, use the poly2mask function. Unlike the createMask method, poly2mask does not require an input image. You specify the vertices of the ROI in two vectors and specify the size of the binary mask returned. For example, the following creates a binary mask that can be used to filter an ROI in the pout.tif image.
c = [123 123 170 170]; r = [160 210 210 160]; m = 291; % height of pout image n = 240; % width of pout image BW = poly2mask(c,r,m,n); figure, imshow(BW)
You can use the roicolor function to define an ROI based on color or intensity range. For more information, see the reference page for roicolor.