# Count Patterns

The Count Patterns tool allows you to count the instances of a trained pattern that occur within a defined search region.

To add the Count Patterns tool to your job:

1. Open the Inspect tool palette, expand the Counting tool group, and select the Count Patterns tool.

2. In the dialog, define the search region by resizing and repositioning the Search box on the acquisition display screen. You can change the shape of the box using the Search Shape dropdown on the right. The available shapes are Rectangle, Circle, Annulus, and Polygon.

   You can reduce the search region size to improve processing time, but make sure that the search region is large enough to contain the target pattern on all acquisitions.

3. Define the model region by resizing and repositioning the Model box inside the search region. You can change the shape of the box using the Model Shape dropdown on the right. The available shapes are Rectangle, Circle, Annulus, and Polygon.

   For best results, make sure that the model region fits the target pattern you want to train as closely as possible. The training happens when you confirm your settings and click OK.

4. You can also add a subregion to your model region to mask out irrelevant or confusing features by right clicking on the acquisition display screen, and selecting Add Subregion > Shape in the dropdown menu that appears. By default, the subregion is added to the model region, but you can change it to subtract by right clicking on the acquisition screen, and selecting Subregion Operation > Subtract in the dropdown menu.

5. Click OK.

To adjust search space settings:

Move the start and end sliders or adjust the Angle Start and Angle End parameters to account for possible rotation in the acquired images. The Count Patterns tool only recognizes the trained pattern within the defined angles of rotation.

If you want the Count Patterns tool to search for multiple instances of the trained pattern, adjust the Number to Find parameter accordingly.

To change the trained pattern:

If you want to change the trained pattern, you can do so using the Trained Model settings. Click on Show Model Region to show the model region on the acquisition display screen.

When the Show Model Region setting is enabled, you can reposition or resize the model region as before, but you cannot change the region shape in this view. You can also add a subregion as before by right clicking on the acquisition display screen.

Once you have changed the model region according to your needs, click Train to change the trained pattern to your new selection.

To adjust the tool thresholds:

If the Count Patterns tool is not adequately identifying your trained model in your images, you can adjust the thresholds to broaden or narrow down the pattern matches.

Adjust the Accept Threshold to change the acceptance threshold for finding features in your images, such as patterns, circles, and edges.

- Decrease the threshold to accept both strong matches and weaker matches.

- Raise the threshold to only accept stronger matches and ignore weaker matches.

To adjust the Accept Threshold:

- Use the slider.

- Or enter a numerical value into the box.

The Contrast Threshold setting defines the amount of difference in contrast that the Find Pattern tool accepts. Lower the Contrast Threshold for a narrower contrast range, or raise the Contrast Threshold for a broader contrast range.

To adjust range limits:

Toggle the Normal/Inverted toggle to change the way the tool result is generated. If set to Normal, the tool produces a passing result if the number of pattern matches falls between the defined minimum and maximum values. If set to Inverted, the tool produces a passing result if the number of pattern matches falls outside the defined minimum and maximum values.

Adjust the valid range by changing the Minimum and Maximum number of pattern matches using the sliders or by providing the numerical values in the boxes below the slider.

Click Set Min/Max to use automatically calculated minimum and maximum number of pattern matches. The default minimum and maximum values are both equal to the current number of pattern matches within the defined region when you add the tool or click the Set Min/Max button.

You can also enable advanced tool settings if your job requires more complex configuration. For more information on the advanced tool settings that are available, see Advanced Tool Settings.