# Pattern

Use a Pattern (powered by PatMax RedLine™) tool to create a trained pattern and then search for that pattern in successive images. You can configure the tool to search an image for the trained pattern regardless of angle or scale, or when the pattern appears partially obscured.

To set up the Pattern tool:

1. ROI The Region of Interest (ROI) is the area of the image where the vision tool operates.: Set the ROI to create Views The area of the image that the device operates on is called a view. A view can be the entire image, a user-defined rectangular area of the image, or the output of a tool, depending on the tool. from your images.

2. Train: Set training parameters. Click Train Model after you set the parameters.

3. Process: Set the parameters and click Process All.

   When processing finishes, detailed statistics about the performance of the tool are shown in the panel on the right side of the window.

How to train the Pattern tool

After the ROIThe Region of Interest (ROI) is the area of the image where the vision tool operates. step, proceed to the Train step.

1. Set the Training parameters.

   Note: The default settings work well only in cases where the image and pattern to be trained have good contrast and little or no background clutter, such as a textured surface. Even in cases where the image is clear and uncluttered, it is still useful to optimize the tool for speed, efficiency, and accuracy.
   Training Parameters

   Parameter | Description
   Coarse Granularity | Specifies the coarse granularity in pixels. The tool uses coarse granularity to find large features to find an approximate pattern match in a run-time image quickly (1 to 30; 2 = default). Note: When the Auto Select Coarse Granularity parameter is enabled, the Coarse Granularity parameter is not available.
   Auto Select Coarse | When enabled, automatically selects the pattern granularity size to be used during the course search phase. Coarse granularity is used to find large features to find an approximate pattern match in a run-time image quickly. Note: The Auto Select Coarse Granularity parameter is enabled by default.
   Feature Threshold | Specifies the minimum contrast of trained features. Decrease the value to train additional low contrast features, or increase it to ignore them (1 to 100; 20 = default).
   Fine Granularity | Specifies the fine granularity in pixels. Fine granularity is used to find small features to determine the pattern location precisely (1 to 10; 1 = default). Note: When the Auto Select Fine Granularity parameter is enabled, the Fine Granularity parameter is not available. The value for Fine Granularity cannot be greater than the value for Coarse Granularity.
   Auto Select Fine Granularity | When enabled, automatically selects the pattern granularity to be used during the fine search phase. Note: The Auto Select Fine Granularity parameter is enabled by default.
   Timeout | Specifies the amount of time, in seconds (0 to 300; 5 = default), that the tool searches for a valid pattern before execution is halted.
   Pattern Origin | Specifies the X and Y origin of the training pattern, as offsets from the center of the training region.
   X | Specifies the X offset from the center of the trained pattern.
   Y | Specifies the Y offset from the center of the trained pattern.
   Width | Specifies the width of the trained pattern.
   Height | Specifies the height of the trained pattern.
   Rotation | Specifies the rotation of the trained pattern.

2. Click Train Model.

How to verify the accuracy of the Pattern tool trained model

After training, set the Processing Options to accurately inspect the image dataset.

1. Set the appropriate processing parameters.

   Processing Parameters

   Parameter | Description
   Accept Threshold | Specifies the acceptance threshold, which is the lowest score of a valid instance. The score for a potential match must be greater than the value of the acceptance threshold or the match is not returned (0 to 100; default = 50).
   Accuracy Mode | Specifies the tradeoff between accuracy and execution speed. Fast: Lower accuracy/reliability and faster execution speed. Accurate: Higher accuracy/reliability and slower execution speed. Standard: The default ratio of accuracy/reliability and speed.
   Coarse Accept Threshold Fraction | Specifies the deviation from the Accept Threshold value as a fraction, which is used during the coarse search phase (0 to 100; default = 60). This parameter is useful when the Accept Threshold value cannot narrow down instances effectively, and the tool returns no match or too many matches. Note: In most cases, this setting does not need to be enabled. How Coarse Accept Percentage Works The Pattern tool first uses large features to find an approximate pattern match in a run-time image (coarse search phase), and then uses small features to determine the pattern location precisely (fine search phase). During both phases, the Accept Threshold value is used to narrow down found instances. Normal Flow (Coarse Accept Threshold Fraction is disabled) While rare, the Pattern may not return any matches because only low score instances are found during the coarse search phase. If this happens, the Accept Threshold setting can be lowered. However, the lower Accept Threshold value may result in returning too many matches. Returns No Match or Too Many Matches (Coarse Accept Threshold Fraction is disabled) In such cases, the Coarse Accept Threshold Fraction setting allows you to define the acceptance threshold value just for the coarse search phase. By using different acceptance threshold value for each search phase, the expected results can now be returned. Returning Expected Results (Coarse Accept Threshold Fraction is enabled)
   Coarse Accept Threshold Fraction Enabled | Specify whether or not configure if the Coarse Accept Threshold Fraction value is used during the coarse search phase.
   Contrast Fraction Threshold | Specifies the lowest contrast of a valid instance. The contrast for a potential match must be greater than the value of the Contrast Threshold or that instance is not be considered (0 to 100; default = 0). The Pattern tool contrast is the relative measure of contrast change between features in the trained pattern versus match features in search image, in percentage. Therefore, if feature contrast is similar or high to pattern contrast, reported Contrast is ~100. If feature contrast is lower than pattern contrast, reported Contrast is <100.
   Number to Find | Specifies the maximum number of pattern matches to return (1 to 1000; default = 1).
   Ignore Polarity | Specifies whether matches containing color-inverted features compared to the train pattern are recognized.
   Disabled | Do not match color-inverted features.
   Enabled | Consider edges that match with opposite polarities.
   Ignoring Polarity increases the variety of patterns that the Pattern tool finds. The figure below shows some examples of matched and mismatched polarities. If you configure the Pattern tool to ignore polarity, it finds all of the patterns shown in the figure. If you configure tool to consider polarity, it might not find the pattern in the bottom row, or it might find them but assign them lower scores than the patterns in the upper row.
   Score Using Clutter | Specifies whether missing or occluded pattern features reduces the response score(s).
   Disabled | Do not include the effect of clutter in score.
   Enabled | Include the effect of clutter in score.
   Timeout | Specifies the amount of time, in seconds (0 to 300; 5 = default), that the tool searches for a valid pattern before execution is halted.
   Xy Overlap | Specifies the expected position difference between multiple overlapping patterns in roughly the same X,Y location, as a percentage of the trained pattern size (0 to 100; default = 70). Note: Increasing this value allows finding multiple overlapping matches of the same pattern.
   Zone Angle | Specifies the allowable range of rotation when searching for patterns.
   Zone Scale | Specifies the allowable range of scaling when searching for patterns. The low and high values indicate how much smaller or bigger a pattern can be than the trained pattern.

2. After you set the parameters, click Process All.

3. Review the inspection results for your image data set. For more information, see Metrics and Statistics.