This topic contains the following sections.
Some of the images that you work with may contain data that you want to ignore. For example, when you are defining a search pattern in Cognex.VisionPro.CNLSearch or Cognex.VisionPro.PMAlign, you may want to exclude some features from the training image. A mask is a CogImage8Grey that lets you specify which pixels of an image you wish to consider and which pixels you wish to ignore. Pixels in the mask are designated as either Care pixels or Don't Care pixels. In VisionPro, a mask image pixel with a value of zero is always a Don't Care pixel, and a mask image pixel with a value of 255 is always a Care pixel. Different tools may give additional meaning to the intervening values.
Think of a mask as a sheet of paper with holes in it superimposed on the image. The opaque paper corresponds to the Don't Care pixels; the holes correspond to the Care pixels. When you use a mask to train a pattern, the search tool will consider only the Care pixels and ignore any part of the image under the Don't Care pixels.

In addition to masks, you can also use regions to ignore portions of an image. Regions are often easier to specify, but they are limited to simple geometric shapes. For more information about using regions, see the Region and RegionMode properties that exist in many VisionPro tools
Note: VisionPro masks use different mask values than other Cognex products. In particular, you cannot use CVL masks with VisionPro and vice-versa.
All of the VisionPro search tools support masks to block unwanted parts of training images. PatMax also allows you to specify a mask to use in the search image. The CogHistogramTool lets you use a mask so you can generate a histogram for part of an image. If you do not supply a mask, the vision tool uses all of the image.
Although masks are standard VisionPro CogImage8Grey, the vision tools consider only their pixel data. The selected space name of a mask image is ignored.
A mask can be smaller than the underlying image. Any pixel in the underlying image that does not fall under the mask is treated as a Care pixel. By default, the mask is aligned with the upper left corner of the underlying image, but all of the tools that use masks let you provide integer x- and y-offsets to move the mask to a different part of the image. The offset is specified in the pixel space of the underlying image.
Cognex.VisionPro.PMAlign lets you specify a mask for both the TrainImageMask and the SearchImageMask
PatMax uses the following values in training image masks:
| Pixel Values | Meaning | Description |
| 0-63 | Don't Care | Features within the corresponding pixels in the training image are ignored. Features in the runtime image that fall within these pixels are also ignored |
| 64-127 | Don't Care But Score | Features within the corresponding pixels in the training image are ignored for the purposes of creating a search pattern, but when found in the search image are scored as clutter features. |
| 128-191 | Reserved | These values are reserved for Cognex use. |
| 192-255 | Care | Features within the corresponding pixels in the training image are included in the trained pattern. |
PatMax uses the following values in search image masks:
| Pixel Values | Meaning | Description |
| 0-127 | Don't Care | Features found within the corresponding pixels in the run-time search image are ignored. |
| 128-255 | Care | Features found within the corresponding pixels in the run-time search image are considered. |
Cognex.VisionPro.Blob lets you specify a mask for the InputImageMask.
| Pixel Values | Meaning | Description |
| 0 | Don't Care | Corresponding pixels in the input image are treated as background pixels. |
| 1-255 | Care | Corresponding pixels in the input image are treated normally. |
Cognex.VisionPro.CNLSearch lets you specify a mask for the TrainImageMask when you use a Algorithms.
| Pixel Values | Meaning | Description |
| 0 | Don't Care | Corresponding pixels in the input image are not trained. |
| 1-255 | Care | Corresponding pixels in the input image are trained. |
CogHistogram lets you specify a mask for the InputImageMask.
| Pixel Values | Meaning | Description |
| 0 | Don't Care | Corresponding pixels in the input image are ignored when generating the histogram. |
| 1-255 | Care | Corresponding pixels in the input image are considered when generating the histogram. |
You can use CogMaskGraphic to display a mask as a graphic object and superimpose it over an input or search image. You can specify the SetColorMap and SetTransparencyMap to use for a particular pixel value in the mask image.
VisionPro includes the Cognex Image and Mask Editor application that you can use to create masks. Note that this application is designed to create masks for several Cognex products. Be sure that you set the Mask Output Format to VisionPro or your masks may not work the way you expect.
Note: You can find the Cognex Image and Mask Editor in the imgedit folder of your VisionPro CD-ROM.
The Cognex Image and Mask Editor saves masks as standard bitmap (BMP) files. You can use the CogImageFileBMP class to read the bitmap file into a VisionPro CogImage8Grey. You can then use that image object as the mask.
This table summarizes the mask values for all of the VisionPro vision tools that support masking.
| Meaning | PatMax(Train Image) | PatMax(Search Image) | CNLSearch | Blob | Histogram |
| Don't Care | 0-63 | 0-127 | 0 | 0 | 0 |
| Don't Care But Score | 64-127 | ||||
| Reserved | 128-191 | ||||
| Care | 192-255 | 128-255 | 1-255 | 1-255 | 1-255 |