An image mask isolates parts of an image for processing. If a function has an image mask parameter, the function process or analysis depends on both the source image and the image mask.

An image mask is an 8-bit binary image that is the same size as or smaller than the inspection image. Pixels in the image mask determine whether corresponding pixels in the inspection image are processed. If a pixel in the image mask has a nonzero value, the corresponding pixel in the inspection image is processed. If a pixel in the image mask has a value of 0, the corresponding pixel in the inspection image is not processed.

When to Use

Use image masks when you want to focus your processing or inspection on particular regions in the image.

Concepts

Pixels in the source image are processed if corresponding pixels in the image mask have values other than zero. The following figure shows how a mask affects the output of the function that inverts the pixel values in an image. Figure A shows the inspection image. Figure B shows the image mask. Pixels in the mask with zero values are represented in black, and pixels with nonzero values are represented in white. Figure C shows the inverse of the inspection image using the image mask. Figure D shows the inverse of the inspection image without the image mask.

The Effect of an Image Mask

You can limit the area in which your function applies an image mask to the bounding rectangle of the region you want to process. This technique saves memory by limiting the image mask to only the part of the image containing significant information. To keep track of the location of this region of interest (ROI) in regard to the original image, Vision sets an offset. An offset defines the coordinate position in the original image where you want to place the origin of the image mask.

The following figure illustrates the different methods of applying image masks. Figure A shows the ROI in which you want to apply an image mask. Figure B shows an image mask with the same size as the inspection image. In this case, the offset is set to [0, 0]. A mask image also can be the size of the bounding rectangle of the ROI, as shown in figure C, where the offset specifies the location of the mask image in the reference image. You can define this offset to apply the mask image to different regions in the inspection image.

  1. Region of Interest
  2. Image Mask

the following figure illustrates the use of a mask with two different offsets. Figure A shows the inspection image, and figure B shows the image mask. Figure C and Figure D show the results of a function using the image mask given the offsets of [0, 0] and [3, 1], respectively.