| MIL 10 User Guide
| Customize Help

Steps to performing a pattern search



See also
Availability
Not available in MIL-Lite

Available in MIL

The following steps provide a basic methodology for using the MIL Pattern Matching module:

  • Load or grab a model source image.

  • Define the model from the model source image. For information on defining a model, see the Defining a model section later in this chapter.

  • Optionally, specify a range for angular search. For information on specifying a range, see the Rotation section later in this chapter.

  • Optionally, mask any irrelevant areas of the model using MpatSetDontCare() to set the model's "don't care" pixels. For more information, see the Masking the model section later in this chapter.

  • Specify the model's search constraints. For more information, see the Search constraints section later in this chapter.

  • Preprocess the model, using MpatPreprocModel(). For information on preprocessing the model, see the Preprocess the search model section later in this chapter.

  • Allocate a result buffer to store the results of your search, using MpatAllocResult().

  • Grab a target image. Optionally, process it to improve its quality.

  • Find instances of the model in the target image using MpatFindModel(). The search is performed according to the defined search constraints.

    You can also search for several models that are of the same size and that use the same search region in the same image, using MpatFindMultipleModel(). This function finds occurrences of the specified models in the given image, and returns the position of each occurrence for each model or of the best matches from the group of models. Note that in the former case, you have to allocate and specify a result buffer for each model that is being sought. In the latter case, you have to allocate and specify a single result buffer. If you have to search for several different models, this is more efficient.

  • Read the search results. To read results, use MpatGetNumber() and MpatGetResult() to get the number of model occurrences found in the target, and the required results, respectively. You can use MpatDraw() to draw the occurrences' bounding box and/or a cross at the occurrences' reference position.

    The coordinates resulting from a search return the reference position of the model, relative to the center of the top-left pixel of the target image. To find the equivalent coordinates in the model source image, use MpatInquire() with M_ORIGINAL_X and M_ORIGINAL_Y.

  • Free all your allocated objects, using MpatFree().

In general, the first seven steps are performed once, while steps 8 through 11 are repeated as required. Note, in practice, models are usually saved on disk, using MpatSave(); therefore steps 1 through 6 are often replaced by a single step that restores a saved model from disk, using MpatRestore().