Optimize FindPatMaxRedLine
The first few parameters will be skipped since they are similar to most other vision tools. Beginning with the Pattern parameter, the following group of parameters will be discussed:
The Pattern parameter contains the cell address of the TrainPatMaxRedLine function containing the model to be found. It is also possible to train multiple models and use logic expressions to choose which model should be used at any given time. For example, if models of five different coins have been trained, and the goal is to find only the dimes in any image of coins. The logic lookup function Choose() can be used to select the cell containing the Dime model, and then the cell address of the Choose() function is inserted into the Pattern parameter field.
The Number to Find parameter specifies the maximum number of matching candidates the function returns. If there are more candidates found than the set value, the highest scoring candidates are returned in the results.
The Accept Threshold parameter specifies the minimum score that must be achieved by any candidate to be returned as a found result. This threshold applies to both the coarse and fine scores by default, unless changed in the Advanced Settings.
The parameters in FindPatMaxRedLine are almost identical to FindPatMaxPatterns, but with at least one notable difference: in the FindPatMaxRedLine tool there is a Coarse Acceptance Percentage parameter under Advanced Settings. This parameter allows the user to specify a different Accept Threshold for the initial coarse search than what is used for the fine search. This helps to eliminate false rejects in the coarse step. Also noteworthy is that while FindPatMaxRedLine is much faster, it also uses more processing memory. For very large job files where speed is not the primary concern, use the standard FindPatMaxPatterns instead.
The Ignore Polarity checkbox defines whether the pattern can be matched even if the polarity is reversed from the original trained polarity.
The Accuracy Mode parameter specifies the level of accuracy required by the search. Low Accuracy uses a faster algorithm, High Accuracy uses a finer scoring algorithm which requires more time. High Accuracy does not necessarily give you a better score, but does provide more accurate positioning of the found pattern.
The Clutter in Score checkbox defines whether clutter in the image should lower the final score. Clutter is defined as anything not trained in the pattern model, even if it is a valid feature of the part. Consider the trained model in the left image. In the right image the pins are not outlined in green because they are not part of the model, so they would be considered as clutter.

The question in this case is, do we care about the clutter? If we do not care whether the pins are there or not, and we only care about finding the circle, then we do not want the presence or absence of the pins to affect the final score. On the other hand, if we do not want the clutter features to be present, then we do want the score to be affected (i.e., lower) when they are present.
Since the model was trained without the pins present, when Clutter in Score is disabled, we get a score of 97.883 because all elements of the circle were found and we do not care about the pins, as shown in the left image. In the right image, Clutter in Score has been enabled, so the score drops to 72.236. By setting the Accept Threshold to 80, we can ensure that only patterns without pins will be found.

The alternative is to set the Accept Threshold level lower and let the pinned patterns be found, but then use an external logic test such as InRange() to reject any result below 80.
The Contrast Threshold parameter defines the minimum contrast a feature must have relative to its background to be considered a match. The default value of 20 rarely needs to be changed. However, if the desired features of the model have very good contrast of 50, while background clutter such as surface texture has low contrast of 30, then set the Contrast Threshold to 40. This allows the desired features to be found while ignoring the lower contrast clutter.
The Find Tolerances are very important and should always be adjusted. The default settings are rarely correct for any given application.
These settings are hard limits. The tool will not find results outside the ranges set for Angle and Scale. The purpose of these settings is to define the limits of what is considered a "perfect" match. In other words, if the Angle Start and Angle End are set to +/-15 degrees, then any candidate within that range can achieve a perfect score.
Note that these parameters have an effect on speed as well. The larger the ranges, the slower the function runs. This is because the function must search the entire specified range to ensure it has found the best candidate. If the actual parts are hard-fixtured for example, and will never experience any angular variation, it makes no sense to force the tool to search in a +/-15 degree range. In this case, set the Angle Start and Angle End both to 0. Similarly, if the parts are always the same size, it makes no sense to allow any Scale range, so leave both Scale Start and Scale End set to 100. On the other hand, if the parts are legitimately expected to vary in size by an expected tolerance of 10%, then set the Scale Start to 90 and Scale End to 110, but no more than that. All matching patterns within Scale Tolerances of +/- 10% are returned.
These parameters affect speed as well as score, sometimes very significantly. For maximum efficiency and accuracy, set the ranges to the minimum practical values that permit the pattern to be found and scored well.
The next parameter is XY Overlap. This parameter controls the ability of the tool to find candidates that overlap each other. Consider a bag of coins dumped randomly into a tray. Since many of the coins likely fall on top of other coins, this parameter can be used to allow the tool to locate partially occluded patterns (coins). This parameter is rarely modified from the default, but can be if needed.
The final parameters are under Advanced Settings and they are Use Coarse Percentage and Coarse Accept Percentage. This is useful when you want different Accept Thresholds for the fine search and for the coarse search. The Coarse Accept Percentage is expressed as a percentage of the primary Accept Threshold. For example, if the primary Accept Threshold is set to 80, and Coarse Accept Percentage is set to 60%, then the resulting Coarse Accept Threshold is 48. This helps to eliminate false rejects in the coarse step while retaining a higher threshold for the fine step.
Summary of FindPatMaxRedLine Optimizations
- Pattern: Reference a single TrainPatMaxRedLine cell or a logic cell that returns one of several choices.
- Number to Find: Set the maximum number of candidates to be found.
- Accept Threshold: Set the minimum score that produces an acceptable match, for Fine searches.
- Ignore Polarity: Check this box to find a pattern, even if the polarity is reversed.
- Accuracy Mode: Specifies the level of accuracy required in a result pose. Can be set to Low or High.
- Clutter in Score: Use to lower the score when unwanted details are found within or around the pattern.
- Contrast Threshold: Set the minimum contrast for features of interest. Lower contrast clutter will be ignored.
- Find Tolerances: Set the minimum ranges needed to find the correct patterns.
- Advanced Settings: Specify a different (lower) Accept Threshold for the coarse search step.