Using Search MasksCognex VisionPro

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.

Search General Theory Using Masks CNLSearch using a mask image to train a pattern

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.

Tools that Use Masks

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.

PatMax

Cognex.VisionPro.PMAlign lets you specify a mask for both the TrainImageMask and the SearchImageMask

Training Image Mask Values

PatMax uses the following values in training image masks:

Table 1. PatMax Training Image Mask Values
Pixel ValuesMeaningDescription
0-63Don't CareFeatures within the corresponding pixels in the training image are ignored. Features in the runtime image that fall within these pixels are also ignored
64-127Don't Care But ScoreFeatures 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-191ReservedThese values are reserved for Cognex use.
192-255CareFeatures within the corresponding pixels in the training image are included in the trained pattern.
Search Image Mask Values

PatMax uses the following values in search image masks:

Table 2. PatMax Search Image Mask Values
Pixel ValuesMeaningDescription
0-127Don't CareFeatures found within the corresponding pixels in the run-time search image are ignored.
128-255CareFeatures found within the corresponding pixels in the run-time search image are considered.
Blob

Cognex.VisionPro.Blob lets you specify a mask for the InputImageMask.

Table 3. Blob Input Image Mask Values
Pixel ValuesMeaningDescription
0Don't CareCorresponding pixels in the input image are treated as background pixels.
1-255CareCorresponding pixels in the input image are treated normally.
CNLSearch

Cognex.VisionPro.CNLSearch lets you specify a mask for the TrainImageMask when you use a Algorithms.

Table 4. CNLSearch Training Image Mask Values
Pixel ValuesMeaningDescription
0Don't CareCorresponding pixels in the input image are not trained.
1-255CareCorresponding pixels in the input image are trained.
Histogram

CogHistogram lets you specify a mask for the InputImageMask.

Table 5. Histogram Input Image Mask Values
Pixel ValuesMeaningDescription
0Don't CareCorresponding pixels in the input image are ignored when generating the histogram.
1-255CareCorresponding pixels in the input image are considered when generating the histogram.
Displaying Masks

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.

Creating Masks

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.

Mask Value Summary

This table summarizes the mask values for all of the VisionPro vision tools that support masking.

Table 6. Mask Values
MeaningPatMax(Train Image)PatMax(Search Image)CNLSearchBlobHistogram
Don't Care0-630-127000
Don't Care But Score64-127    
Reserved128-191    
Care192-255128-2551-2551-2551-255