Optimize TrainPatMaxRedLine

It is assumed you are already familiar with configuring spreadsheet functions, so the first four parameters are not discussed here. Beginning with the Pattern Origin parameter, the default Offset Row and Offset Column (0,0) places the pattern origin at the geometric center of the Pattern Region. Any Offset row or column entered moves the origin away from the center by the specified amount.

Consider the following square pattern. In the first image the default Offset Row and Offset Column (0,0) is used, but in the second image the Offset Row and Offset Column is set to (14,14), to place the origin at the center of the larger connector. In either case, the FindPatMaxRedLine function then reports the location of the origin crosshairs as the location of the found pattern.

The next settings are Auto Select Coarse and Auto Select Fine checkboxes. When checked, the function runs with the default settings, which is usually not desirable. Uncheck both boxes and adjust the Coarse Granularity and Fine Granularity manually. Coarse Granularity and Fine Granularity are extremely important parameters which are almost always overlooked or ignored, yet they provide one of the best optimizations available. The default values are used when Auto Select Coarse and Auto Select Fine are enabled. If Auto Select Coarse and Auto Select Fine are selected, it tries to calculate granularities that minimize background noise while still finding the pattern. It tries to model all relevant features while ignoring the clutter. Consider the following model created with the default Coarse Granularity and Fine Granularity:

Now assume that the goal is to simply locate the position of this Data Matrix code, but not to find an exact match because it will be different on every part. To accomplish this, we need fewer Fine Granularity details. To determine the optimal settings, we start with both Coarse Granularity and Fine Granularity set to 10, then alternate between decrementing both settings until a crude outline is recognizable, as shown below. In this case, a Coarse Granularity of 4 is used. The pattern is crude, but contains enough information to recognize a roughly square shape.

Now set the Fine Granularity to 2 to improve the model slightly, but not too much. The idea is to get as much detail as possible around the perimeter of the square without adding too much detail in the interior. Here is the result:

The end result is a pattern model that is very robust. Note that even if none of the interior details are matched in any future image, the majority of the pattern is the perimeter outline which, in this example, is all we care about.

The purpose of this example is to illustrate that the Coarse Granularity and Fine Granularity can be used to restrict the model elements primarily to those features that matter most, but in some cases it may be impossible to restrict all of the unwanted features. Even so, excellent results can be obtained. The following image contains a different Data Matrix code, yet achieved a score above 85.018 with the above model. The reason for this is that 100% of the perimeter details were matched, and by sheer luck a number of the "unwanted" interior features also matched.

Even if almost none of the interior had matched, the score would been above 85 as shown in the image below. In other words, with an appropriate Accept Threshold this model could produce virtually a 100% success rate on any similar Data Matrix code.

One additional benefit of manually optimizing the Coarse Granularity and Fine Granularity parameters is that it allows the function to run faster. The lower the Coarse Granularity and Fine Granularity values are, the longer it takes to process the image. So when speed is important, set the Coarse Granularity and Fine Granularity as high as possible, but low enough to ensure an accurate match.

The examples in this section have good contrast, so the Feature Threshold was left at the default setting of 20. However, in cases where low contrast clutter such as surface texture is present, it is beneficial to increase the contrast setting to a level that ignores the surface texture, but not the features of interest.

The final parameter to be discussed here is the Reuse Training Image checkbox. When enabled, it saves the training image. This allows all the parameters discussed above to be modified later without reloading the training image. However, if the Fixture or Pattern Region are modified in any way, a new training image is saved, so be sure to reload the original training image in this case.

Summary of TrainPatMaxRedLine Optimizations

  • Pattern Origin: Modify the Offset Row and Offset Column so the function returns location information relative to a feature of interest.
  • Coarse Granularity and Fine Granularity: Use these parameters to reduce unwanted features or clutter in the model and to speed up processing time, larger numbers are faster and will reduce processing time.
  • Feature Threshold: Default setting is 20. Reduce this setting for desireable features that are only slightly darker or lighter than the background.
  • Reuse Training Image: Enable this while experimenting with different iterations of the above parameters to avoid the need to reload the training image each time.