前言:
针对PatMax 的高级应用和原理,在这一节继续进行说明:这一节主要考虑的是PatMax模板匹配的原理:
How PatMax Finds Patterns in an Image PatMax 模板匹配原理
1 Run-time Space
When you search for a PatMax pattern in a run-time image, you define the run-time space that PatMax uses. The run-time space is determined by the degrees of freedom you enable, and the range of values to consider within each degree of freedom.
PatMax identifies likely candidates within the run-time space, then determines the transformation that best describes the transformation from the trained pattern geometry to the transformed pattern geometry in the run-time image.
【案,run-time image ,其实就是实时捕获图片。run-time space 则是在执行PatMax,需要先决定自由度,有关自由度的定义参考上一篇博客,PatMax的介绍(2)。】
【案,自由度的设定中,我们会定义好自由度的阈值,比如每个自由度的识别的范围。然后, PatMax会在run-time space 来识别可能的候选的特征进行匹配。也就是依据自由度阈值来进行训练好(理解为预设)模板和实时捕获图片的匹配情况。】
2 Pattern Granularity 模板粒度
PatMax locates pattern matches in the run-time space by first searching only for the large features. After locating one or more pattern matches, it uses smaller features to determine the precise transformation between the trained pattern and the pattern match in the run-time image.
By default, PatMax uses the same range of granularities that it computed when it trained the pattern to detect features in the run-time image.
【案,PatMax在进行 模板匹配的时候,先进行最大特征的匹配。在找到1个或者多个匹配的最大特征后,再进行小特征的匹配来提高匹配的精度。这个大,小的特征就是模板粒度。】
3 PatMax的两种Run Mode模式:
PatMax supports two run modes for locating the pattern in each acquired image.
3.1 Search Image Mode
By default, PatMax uses Search Image mode and searches the entire image for the pattern it is trained to find.
3.2 Refine Start Pose mode
PatMax also supports Refine Start Pose mode, which limits the search for the pattern to within a few pixels of a defined starting position, typically supplied by another vision tool. Using Refine Start Pose mode, PatMax does not use its coarse granularity settings to search the image for larger features, and instead moves to a refined search for the smaller features assuming they are located within an extremely narrow range of the given starting position.
【案,就是一种是全图搜索,另外一种是直接定义一个区域,进行小范围的小特征的搜索】
4 两种图像处理模式:
4.1 standard mode
4.2 High Sensitivity Mode
Image quality can have a significant affect on PatMax's success in finding features in images. Clear, sharp, high contrast images generally yield the best results while low contrast and noisy images can be problematic. To better enable PatMax to handle this range of image quality, two execution modes are provided. For good images with low noise and high contrast, you should run the tool in standard mode, the normal mode of operation. If your images are noisy or have low contrast you may improve your results by running the tool in high sensitivity mode which will generally require more training time and more execution time. Figure 10 shows examples of good and problematic images. Note that high sensitivity mode performance may be worse than standard mode for patterns with small features. Cognex recommends standard mode for most applications.
图像质量对PatMax的匹配有决定作用。清晰、尖锐、高对比度的图像一般有最好的结果。为了能够更好的处理低质量的图片,提供了两个不同的处理模式。standard mode和high sensitivity mode。
4.2.1 Sensitivity Parameter 敏感参数
When you use high sensitivity mode you can also set the sensitivity training parameter which allows you to specify your image quality. The sensitivity parameter is a number in the range 1.0 through 10.0 that specifies the amount of noise rejection PatMax applies to run-time images. If the sensitivity parameter is set to 1.0, minimum noise rejection is applied. If the sensitivity parameter is set to 10.0 PatMax applies the maximum noise rejection. Since portions of the pattern may appear as random noise, actual pattern features may be lost. Best results are usually achieved by using the default of 2.0. Lower sensitivity parameter values have less of an affect on training time and execution time whereas higher values tend to increase these times.
If you are having problems when using the default value of 2.0, and you suspect the cause is low contrast or noisy images, you can experiment by changing the sensitivity parameter to determine an optimum setting. Increase the sensitivity parameter to make PatMax less sensitive to random noise, and decrease the sensitivity parameter to make PatMax more sensitive to the pattern. If this helps you should find your optimal setting in the range 1.0 through 5.0. It is very unlikely that a setting above 5.0 will produce an optimal result.
【这应该是对噪点的设定阈值,范围为 1 到 10 。 然后,默认值为2。 高设定阈值,比如10,会导致实际的模板参数的缺失,同时导致处理时间的花费增加。】
【当在默认的阈值2.0发生错误的时候,低对比度或者太多的噪点也许是一个原因,这时候回,可以适当的调整阈值。增加阈值,会减少算子对随机噪点的敏感度,反之增加。不建议采用5.0以上的设定值】
6 Pattern Weights 模板权重
When you use PatMax shape training, you supply a collection of individual shape models. Each of these shape models can be assigned a weighting factor that is used when running the tool to compute a score for how well the trained model matches the likeness found, as described in the section Assigning Weights. Shape models with larger weighting factors have more effect on the score.
【在使用形态的模板训练的时候。这时候提供一组独立的模板形态的集合。每一种形态集都可以被赋予一种加权,从而提高模板搜索的匹配度】
7 Pattern Transformations 模板变换
When you train a pattern with PatMax using either shape description or an image, PatMax creates an internal representation of the pattern's geometry. PatMax also initializes the pattern origin to a value that you specify. When PatMax returns the location of a pattern instance in a run-time image, it does so in terms of the pattern origin.
Note: In addition to specifying the pattern origin as a simple point, you can also specify a generalized pattern origin in the form of a transformation object. The use of a generalized pattern origin is described in the section Generalized Pattern Origin.
【显然, 模板的训练有两种方向,1 形态 2 图像本身。 PatMax会构建内部的模板的几何表述,这点前面的章节我们已经了解。PatMax同样会初始化一个原始模板(用户可以设置)。在PatMax返回一个模板实例的位置的时候,当然,是在这个初始化的原始模板的定义下。
那么模板的变换的概念意义是什么?笔者理解就是从模板的几何表述中,抽象出我们再配置中定义出来的变换值】
如图,【pattern origin 到底是原始模板还是模板中心点?】默认的坐标原点的值为,(70,70)点,图上十字这个点。 这里pattern origin 应该是模板的一个坐标元原点。
7.1 Pattern Transformations and Shape Training 模板变换和形态训练:
When you train PatMax using image training, it uses the selected space of the training image to relate the features in the image and the pattern origin you specify, to the root space of the training image.For shape training, you must provide information that relates the shape models you supply to the root space of a hypothetical training image. You can provide this information in either of two ways.
- You can provide a training image with an associated coordinate space tree that defines the selected space of each of the shape models you are training.
- You can provide a CogTransform2D object that provides a pixel from shape model transformation.
PatMax requires the information provided using these methods so that it can compute the appropriate granularity limits for pattern training.
Note: Keep in mind that the features in the trained pattern are not the same as the shapes you provide for training. If, for example, you provided a shape that was extremely small (less than 1 pixel in size), there would be no point in training that shape as a feature, since it would not be resolved in any run-time image.
【模板的图像训练的坐标空间可以有三种:1 被测的图像空间 2 指定的模板原点,也可以理解为原始的。】
【模板的形态训练,你必须提供形态模式相关的信息来构建坐标系。这些信息包括(或的关系):
- 被测图像的相关坐标空间。
- 一个包括形态变换的a CogTransform2D object对象。
PatMax用于在模板训练时候,提供并计算近似的模板的粒度限制。
7.2 Pattern Transformation Result模板变换的结果:
When you run PatMax, it returns a transformation that describes how the trained pattern maps into the found instance. You can use the information in this transformation in two ways:
- As a transformation object that you can use to convert any location from the trained pattern to the corresponding location in the run-time image. You can use the transformation object to transform points between the selected space of the trained pattern (translated by any nonzero pattern origin) and the selected space of the run-time image.
- As individual values for the ordinary degrees of freedom (the location of the pattern origin) and individual values for each of the generalized degrees of freedom that you have enabled
【模板变换,就是模板的特征匹配可以适应自由度的变换。而模板变换的结果通过一下两点表述:1 变换对象从训练的模板的位置变换到一个我们定义的坐标系中的位置(坐标系的定义在上一小节已经介绍)。2 得到分别独立的自由度的变换值。(我们知道,在模板特征匹配的时候,我们可以从6个基本的自由度定义,选取我们关心的几个自由度,这样,在模板变换的时候,我们关心的几个自由度的值是可以同时被计算出来的。
上图展示了模板变换的两个方面。1 位置变换,我们看到训练的模板在新的坐标系下,坐标原点变换到Pattern origiin的变换位置。 2 就是计算这个坐标变换,带来的自由度变化【分别是X缩放不变,Y缩放压缩了一倍,而角度自由度则旋转了+135度。
7.3 Generalized Pattern Origin 生成的原始模板
As described in the preceding section, PatMax returns a transformation object that describes how the pattern in the run-time image is different from the trained pattern. The returned transformation object describes the transformation between the trained pattern and the pattern in the run-time image, as shown in Figure 13.
一般标准的模板变换,是从训练的模板到实时的图像模板:如下:
也支持,先做逻辑的变换,再和实时的图像进行变换。
In some cases, you may want to apply a transformation to the trained pattern before you search for the pattern in a run-time image. You apply such a transformation by supplying a generalized pattern origin. PatMax applies the transformation you supply to the trained pattern before it searches for the pattern in the run-time image. When it returns a pattern location result, it returns the transformation between the trained, transformed, pattern and the pattern in the run-time image.
有时候,你可能想在进行实时的图像匹配搜索前,先做一些变换。这有点和逻辑传递相似。
You typically supply a generalized pattern origin to compensate for known scale or rotation changes in the trained pattern. If you supply a generalized pattern origin you should keep the following points in mind:
- PatMax will return results that describe the difference between the trained pattern after it has been transformed by the generalized pattern origin and the pattern in the run-time image.
- Any zone ranges and nominal values that you specify are interpreted with respect to the transformed trained pattern.
- Supplying a generalized pattern origin has no effect on the speed, accuracy, or number of results produced by PatMax.
- The x- and y-translation components of a generalized pattern origin are equivalent to the simple (point) origin.
通常逻辑产生(而不是输入图像)的一个原模板坐标原点( pattern origin )(主要是缩放、转动),PatMax总会同样
系列文章集表:
VisionPro - 基础 - 00 模板匹配技术和在VP中的使用 - PMAlign - PatMax - (1)-CSDN博客
VisionPro - 基础 - 00 模板匹配技术和在VP中的使用 - PMAlign - PatMax - (2)-CSDN博客1