Often your search model contains regions that you need MIL to ignore when searching for the model in the target image. These regions might be noise pixels or simply regions that have nothing to do with what you are searching.
For instance, in a machine guidance application, a mechanical device might need to know where mounting holes are located on a circuit board so that screws can be properly inserted. In this case, a mounting hole would be the search model and the circuit board would be the target image.
In the above image, the search model contains too much of the actual board; it might not match holes in different areas of the board.
In such cases, parts of the search model can be masked by setting pixel values in certain regions to "don't care" pixels. MIL then ignores these regions when searching for occurrences of the model.
In our example, you would need to mask the edges of the search model, as follows:
The unmasked region of the search model now more closely resembles the pattern for which to search; it is more circular in shape and contains little of the actual board.
To create a mask:
Allocate an image that is of the same size as the model image. This new image is the mask image.
Clear the mask image to one pixel value. This is the background color of the mask image.
Set the "don't care" pixels in the mask image to a specific value, different from the background. This is the foreground color of the mask image. There are numerous ways of doing this. For example, you can use one of the Mgra...() functions.
To establish which pixels to set to "don't care", you can refer to a copy of the model image obtained using MpatCopy() with M_DEFAULT.
Call MpatSetDontCare(), specifying the mask image along with the foreground color used to draw the "don't care" pixels. This function sets the model's "don't care" pixels.
View the mask using MpatDraw() with M_DRAW_DONT_CARE. Alternatively, you can call MpatCopy() with M_DONT_CARE.
When you change the "don't care" pixels of a model, you should preprocess the search model again.