Specify ROI as Binary Mask
A binary mask defines a region of interest (ROI) of an image. Mask pixel values of
1
indicate image pixels that belong to the ROI. Mask pixel values
of 0
indicate image pixels that are part of the background.
Depending on the application, an ROI can consist of contiguous or discontiguous groups of pixels. A contiguous region is a single group of connected pixels. A contiguous ROI could represent a single object in an image, such as one car in an image of a street scene, or the body tissue in a medical image. For example, a discontiguous ROI could represent all pixels corresponding to water in an aerial photograph, or all tumorous cells in a medical image.
Image Processing Toolbox™ supports many options to create a binary mask. Here are some common approaches, although this selection is not exhaustive.
Create Mask Using Thresholding
A common way to create a mask from an image is to classify each pixel based on the intensity value of the pixel. For example, pixels in a region of interest can appear brighter than the background or have a different color than the background. Various functions and apps enable you to apply thresholding to grayscale, indexed, and color images.
Operation | Description | Sample Output (Input Image, Binary Mask, and Masked ROI) |
---|---|---|
Single threshold | The ROI consists of grayscale pixels whose intensity is
above (or below) a specified threshold. You can create a binary
mask representing the ROI using mathematical operations or
functions such as For an example, see Correct Nonuniform Illumination and Analyze Foreground Objects. |
|
Range of intensity or index values | The ROI consists of grayscale pixels whose intensity is within a
range of values. You can create a binary mask representing the ROI
using mathematical operations or by using the roicolor function.
This function also supports indexed images, in which case the mask
specifies pixels with specific index values corresponding to colors
in a colormap. |
|
Range of color values | The ROI consists of the pixels in a color image whose color channels are within a range of values. You can create a binary mask from an RGB image using the Color Thresholder app. This app enables you to interactively select the range of values for the three color channels based on different color spaces. |
|
Grayscale flood fill | The ROI consists of connected pixels of similar intensity
value. You specify a seed point and tolerance. Perform a flood
fill operation of a grayscale image using the |
|
Color flood fill | The ROI consists of connected pixels of similar color value. You specify a seed point and tolerance. Perform a flood fill operation on a color image using the Image Segmenter app. |
|
Create Mask Based on Position
You can specify an ROI based on the position of pixels in an image. For example, you can define an ROI consisting of pixels within an ROI shape that you draw, or within a rectangular patch whose location is specified using array indexing.
Operation | Description | Sample Output (Input Image, Binary Mask, and Masked ROI) |
---|---|---|
Create geometrical or freehand shape using ROI objects | The ROI consists of all pixels whose position is within a
geometrical or a hand drawn shape. First, you create an ROI
object, then you create a binary mask using the For an example, see Create Binary Mask Using an ROI Function. |
|
Create polygonal shape using polygon tool | The ROI consists of all pixels within a polygonal shape.
You can draw the shape interactively in the polygon tool by
using the |
|
Create mask from polygon coordinates | The ROI consists of all pixels whose position is within a
polygon. You can create this binary mask by specifying the
vertices of the polygon using the |
|
Create Mask Using Automated and Semi-Automated Segmentation Algorithms
Some image segmentation algorithms predict an ROI based on features in the image and a coarse estimate of the location of the ROI. For example, the active contours technique iteratively refines a mask that you provide towards object boundaries. A benefit of automated and semi-automated segmentation algorithms is that they can detect intricate ROI boundaries with high fidelity given an imprecise initial location estimate.
The Image Segmenter and Volume Segmenter apps enable automated and semi-automated segmentation techniques. You can also segment images into ROI and background using a variety of functions in the toolbox. For more information about available segmentation techniques, see Image Segmentation.
Operation | Description | Sample Output (Input Image, Binary Mask, and Masked ROI) |
---|---|---|
Graph cut | The graph cut algorithm estimates an ROI using iterative
graph-based segmentation. You specify and refine the ROI using seed
pixels for both the ROI and the background. Graph cut functionality
is enabled by the grabcut function and the Image Segmenter
app. |
|
Lazy snapping | The lazy snapping algorithm estimates an ROI using graph-based
segmentation. You specify an initial mask or pixel coordinates for
both the ROI and the background. Lazy snapping functionality is
enabled by the lazysnapping
function. |
|
Active contours | The active contours (snakes) algorithm estimates an ROI using a
region growing technique. You specify an initial mask around the
object boundaries. Active contour functionality is enabled by the
activecontour
function and the Image Segmenter
app. |
|
See Also
Color Thresholder | Image Segmenter | Volume Segmenter