Advanced Pattern Matching Concepts
- Updated2025-11-25
- 13 minute(s) read
Introduction
Advanced pattern matching contains low-level learning and matching options that enable you to customize the pattern matching algorithm to your specific machine vision application. In order to be useful to a broad audience, a pattern matching algorithm needs to process numerous diverse template images and search images. Determining a set of default advanced pattern matching options that is optimal for all possible applications is improbable. However, you can customize the IMAQ Vision pattern matching algorithm for your application by configuring several advanced options that affect the speed and accuracy of pattern matching.
When To Use
If the pattern matching portion of your application is not working as expected, make sure you have defined a template with the following qualities:
- Good feature detail,
- Adequate positional data,
- Sufficient background information,
- Appropriate level of asymmetry (for rotation-invariant matching).
You can change the template slightly to remove excessive background information or include additional feature information. You may also consider restricting the angle ranges, if possible, or defining a search region. In addition, make sure your application is running in optimal lighting conditions and that you are acquiring quality images. Nonuniform lighting and poor image quality adversely affect other image processing algorithms as well as pattern matching. If you have suitable template images and search images but want to improve the speed and/or accuracy of the pattern matching process, you can configure the advanced pattern matching options.
Pattern Matching Phases
Pattern matching consists of two stages: a learning stage, which is usually performed offline, and a matching stage. For the purpose of discussing advanced pattern matching options and the consequences of changing the default values, this document divides the matching stage into the following four phases.
Most advanced options influence only one phase of the pattern matching process. In most cases, you control one phase of the pattern matching process using multiple advanced options.
Guidelines for Using Advanced Options
If you still require better results after configuring the advanced match options, try changing the advanced learn options. The advanced learn options allow you to manage the amount of data used in different segments of the matching process. You have control of the number of data points and/or the angular accuracy of the data points while the algorithm selects the points.
The results you get from changing the advanced learn options vary significantly from one template to the next. At times, changing the options might produce undesired results. For example, requesting more data points for a template could result in less accurate matches because too many data points cause the algorithm to sample image noise. This scenario is not unusual or unexpected.
Advanced Match Options
The following list describes the advanced options you can configure for the match process.
Advanced Learn Options
The following list describes the advanced options you can configure for the learning process.
Options at a Glance
This section illustrates how the advanced pattern matching options effect the accuracy, speed, and risk of pattern matching in your application. The following illustration shows the impact that each advanced match option has on the accuracy and speed of the matching process.
The following figure shows the impact that each learn option has on the accuracy and speed of the matching process.
The following figure illustrates the risk of getting unexpected results when configuring the advanced match and learn options. The risk levels shown for each option correspond to setting more aggressive values for the option.
Optimizing for Accuracy
Many advanced options impact the accuracy of match results. Accuracy may refer to the following:
- Order in which multiple matches are returned,
- Number of matches returned,
- Match location(s) returned.
Each of these conditions requires a different usage of the advanced options. In general, if you find a match with a lower score than expected or an inaccurate position, use subpixel refinement to improve the results. First, set Enable Subpixel Accuracy to 1 (TRUE) to increase accuracy. Then, increase the number of subpixel iterations with Subpixel Iterations if you need additional improvement.
If only one of several matches is inaccurate, you can set Subpixel Tolerance to the pixel accuracy desired, which is normally between 0.1 and 0.5. By setting this value, the pattern matching algorithm spends time improving only those matches outside the specified tolerance instead of refining all matches for the given number of iterations. When providing a tolerance, set Subpixel Iterations to 0 (default) to allow the refinement process choose when to stop, or set Subpixel Iterations to a maximum iteration to cap the amount of refinement performed when the tolerance is unreachable.
Altering subpixel refinement options is the last phase of the matching process you can manipulate to improve accuracy. If altering subpixel refinement options does not result in the expected match accuracy, you can adjust one or more of the following options. Determining which options to adjust varies among applications, but the following categorization of options provides a general order in which to proceed.
- Basic match options—Shift/rotation invariance, Minimum Contrast,
Rotation Angle Ranges:
- Low risk relative to other advanced options.
- Can significantly impact match results by impacting the entire match process.
- Advanced match options used in the intermediate and final phases of the match
process—Intermediate Angular Accuracy, Match List
Reduction Factor:
- Usually low risk because they occur during pixel-level refinement,
- Impact on match speed is reduced because these options affect a later match phase.
- Advanced match options used in the initial phase of the match process—
Initial Match List Length, Initial Step
Size:
- Higher risk because these options alter match selection from the start,
- Slower match speed when more conservative values are selected because of additional
processing required.Note Changing Initial Step Size is not recommended because the template contains the optimal initial step size to use. If you want to perform an exhaustive search for the template, you can set this option to 1, but doing so significantly reduces matching speed.
- Advanced match option defining the match process—Search Strategy:
Aggressive, Balanced (default), and Conservative:
- High risk because changing this option alters most advanced match options and sometimes alters the initial search approach.
- Conservative works like Balanced but is more rigorous during the initial phase, causing match speeds to double in many cases.
- Aggressive uses a different initial searching technique, so resulting matches may differ significantly from the other strategies. Use the Aggressive option when searching on very rectangular templates or when many of the distinguishing characteristics are not in the center of the template.
- Advanced learn options used during the subpixel refinement phase—Subpixel
Sample Size, Subpixel Sample Size Factor:
- High risk relative to other advanced match options; low risk relative to other advanced learn options.
- By default, Subpixel Sample Size is based on the size of the template, in pixels. The following Tables show the relationship between template size and Subpixel Sample Size. The first table depicts the sizes for Shift-Invariant Matching while the second table depicts the sizes for Rotation-Invariant Matching.
| Template Size (in pixels) | Subpixel Sample Size |
| greater than or equal to 600 | 60 |
| greater than or equal to 2400 | 120 |
| greater than or equal to 9600 | 240 |
| greater than or equal to 42000 | 420 |
| greater than or equal to 160000 | 600 |
| Template Size (in pixels) | Subpixel Sample Size |
| greater than or equal to 200 | 60 |
| greater than or equal to 1200 | 120 |
| greater than or equal to 4800 | 240 |
| greater than or equal to 16800 | 420 |
| greater than or equal to 60000 | 600 |
| greater than or equal to 160000 | 840 |
- Advanced learn options used during the final phase of matching—Final Sample
Size, Final Sample Size Factor, Final
Angular Accuracy:
- High risk relative to other advanced match options; medium risk relative to other advanced learn options.
- Final sample is used in the final phase of the match process and contains data for refining match locations to within a pixel or degree of accuracy. This sample includes, but is not limited to, locations around edges in the template.
- By default, the final sample produces an angular accuracy of 1°. If you do not require this level of accuracy, you can increase the Final Angular Accuracy value, which reduces accuracy, reduces the template size, and increases the match speed. The accuracy value is always rounded down to a value that divides 360 evenly.
- Advanced learn options used during the initial phase of matching—Initial
Sample Size, Initial Sample Size Factor,
Initial Angular Accuracy :
- Among the highest risk advanced options because they affect the entire match process from start to finish.
- Initial sample contains representatives from regions having roughly the same pixel values.
- By default, the initial sample produces an angular accuracy of 6°. This initial accuracy default is necessary to find matches in the final phase of matching with an accuracy of 1°. If you set the final accuracy to be less accurate, you can increase the Initial Angular Accuracy value to reduce accuracy, as well. The accuracy value is always rounded down to a value that divides 360 evenly.