前言:
本机继续对VP的PatMax 算子进行说明:本节讲非线性变形的模板匹配。
Non-Linear Pattern Deformation
By default, PatMax requires that each boundary point in the instance of a pattern found in a run-time image closely correspond to a boundary point in the trained pattern. PatMax can match and identify any change that can be described by a linear geometric transformation (assuming you specify the appropriate degrees of freedom and zones).
When patterns exhibit nonlinear geometric changes, PatMax can fail to find them, or it can return a low score or inaccurate location information. There are two ways PatMax can work with patterns that exhibit nonlinear geometric change.
- In cases with a small amount of deformation, you can specify a nonzero elasticity value (in pixels) that specifies how much non-linear deformation PatMax will tolerate.
- In cases with substantial deformation, can use the PatFlex algorithm to locate and match patterns and return information about the deformation of the found pattern instance.
Each of these two methods is described in this section.
【在之前的几节,我们提到模板匹配的6个自由度匹配。同时解释了模板匹配的两种模式,基准标记和范围标记(ZONE)。然而,这些都是考虑的线性的几何变换。】
对于非线性的模板匹配,康耐视提供了两个思路:
- 对于小的形变,通过设定一个非零的弹性值(像素级)来定义PatMax的非线性的冗余度。
- 确实是有非线性形变,这时候需要通过 PatFlex 算子定位和匹配模版。
1 Elasticity 非零的弹性值的使用:
You can specify the degree to which you will allow PatMax to tolerate nonlinear deformation by specifying an elasticity value. You specify the elasticity value in pixels.
In general, you should specify a nonzero elasticity value if you expect inconsistent variation in patterns in run-time images.
You should keep the following points in mind when specifying a nonzero elasticity value:
- Specifying a nonzero elasticity value does not affect PatMax's execution speed.
- Increasing the elasticity value does not decrease PatMax's accuracy. However, location information returned about additional object instances that are found as a result of increasing the elasticity value can be less accurate.
- If the elasticity value is too low, you will see low scores and your application may fail to find patterns in the run-time image and/or the positions will be incorrect or unstable.
- If the elasticity value is too high, PatMax may match false instances and may return inaccurate or unstable results.
In general, you should start with an elasticity value of 0; if necessary, increase the value slowly until you obtain satisfactory results.
【案,从官网表述看康耐视的elasticity算法,不是很好用。设定的阈值完全需要根据实际的情况进行调整】
2 PatFlex Algorithm
2.1 常见的非线性形变
扭曲匹配算法大约支持一些常见的非线性形变:
- 球形 spherical
- 圆柱形 cylindrical
- 表面扭曲形 surface flex distortion
2.2 How PatFlex Reports Deformation Information PatFlex的算子原理
When you use the PatFlex algorithm, the tool detects changes in the features of the pattern independently, and then constructs a special type of transformation that maps between the trained pattern and the pattern instance found in the run-time image, as show in Figure 20.
Because the PatFlex algorithm locates features independently, it can tolerate (and return information about) an arbitrary deformation.
The special nonlinear transformation that PatFlex computes can be used in two ways.
- You can use it to generate an unwarped version of the run-time image. You can then perform additional operations on this unwarped image.
- You can use it to display a deformed grid graphic that provides a graphical representation of the deformation.
【PatFlex 的作用还是比较厉害的,首先他是独立的不影响其他的算子。然后,1 你可以用它直接把扭曲的图像给纠正回来 2 可以生成一个扭曲的网格图,来表征被测图片发生了哪些形变扭曲。】
2.3 PatFlex 的一些参数:
If you use the PatFlex algorithm, you have the opportunity to specify several parameters.
- The expected (training time) and maximum (run time) deformation rate
- The deformation fit (perspective or surface flex)
- The number of control points
- The smoothing value
- The refinement mode
Each of these parameters is discussed in this section.
2.3.1 Expected and Maximum Deformation Rate 【期望和最大扭曲率】
这是两个可以在配置算子时候,设定的扭曲程度的参数。
Different instances of a trained pattern can exhibit different amounts of deformation. The PatFlex algorithm expresses the degree of pattern deformation as the pattern's deformation rate. A pattern's deformation rate is a value in the range 0.0 through 1.0. A value of 0.0 indicates no deformation, while a value of 1.0 indicates a highly deformed pattern.
The deformation rate represents the percentage of variance between the undeformed location of a control point in the run-time image and the found location of the control point. Figure 21 provides a visual guide for estimating pattern deformation
【案,上图显示了不同扭曲程度下,图片的扭曲的实际情况】
2.3.2 Control Points
You can specify the number of control points that PatFlex uses to map the pattern. By default, PatFlex creates a grid of control points evenly spaced across your pattern. In most cases this produces a satisfactory balance of reasonable execution time and accurate representation of the pattern's deformation.
If you expect high-frequency deformation, such as a crumpled piece of paper, you may need to increase the number of control points.
【控制位点,是PatFlex进行模型匹配的时候,用户设定的一些关键点,PatFlex通过这些设定的关键点进行模型匹配。注意,点越多,匹配精度越好,但是,执行时间更长。】
2.3.3 Smoothness Value 平滑值:
PatFlex creates a nonlinear transformation that describes the difference between the trained control points and the control points found in the run-time image. PatFlex refines this transformation so that you can use it to map any point between the trained pattern and the run-time image (CVL only) or create an unwarped version of the run-time image.
The smoothness value determines how closely PatFlex fits this transformation to the found control point locations. A smoothness value of 0.0 indicates that the transformation is to be perfectly fitted to the control points. A smoothness value of infinity indicates that the transform is an affine transform (does not incorporate any of the nonlinear deformation).
In most cases, the default value of 3.0 is appropriate. If too small a smoothness value is specified, the resulting transformation may be perfectly accurate for the control points, but less accurate for intervening points, as shown in Figure 22.
Figure 22. Effect of different smoothness values
平滑值是用来衡量PatFlex的扭曲变换的结果的。越低匹配的越完美。【当然,如果要对模板匹配特性执行完美的话,平滑值设定越高,图像的扭曲纠偏就约完美,如上图,很大的平滑值设定会将一个扭曲的图片展平为一个未被扭曲的图片。】
用模式设定值,可以更快捷的设定扭曲变形。
2.4 PatFlex Performance 的效果
The PatFlex algorithm generally requires substantially more time for both training and searching, than the other PatMax algorithms. Also, as you increase the number and size of the enabled degrees of freedom, PatFlex may require significant amounts of time to run. Finally, specifying large numbers of control points will increase search times. The maximum deformation rate (specified at run time) has a similar effect on performance; the larger the maximum deformation rate, the longer the search may take.
Increasing the expected deformation rate (specified at training time) can increase training time, but it has only a small affect on search time.
【首先,PatFlex 是 PatMax 算子的一部分。PatFlex的主要弱点,应该主要是运行效率。跟多的自由度和图像的大小,会影响执行时间。】
上一节,我们已经提到平滑值的设定,在进行模型匹配的时候,我们先训练,再查找。如果我们设定较高的平滑值来进行扭曲纠正,会占用很多训练的时间。但是算法在执行模板搜索的时候受到的影响不大】
2.5 PatFlex Results
In addition to returning a transformation that describes the pattern deformation, the PatFlex algorithm also returns all of the standard PatMax results, such as the pattern score and a linear transformation describing the result's pose. The returned pose represents a best-fit linear approximation
【PatFlex 也会返回一些线性的纠偏结果】
Perspective PatMax for Perspective Distortion
The PMAlign tool supports Perspective PatMax for locating 2D features that display various degrees of planar perspective distortion, as shown in the following figure: