# Irregular Workpiece Template-Matching Algorithm Using Contour Phase
## 3 Algorithm Principle
### Contour Feature Vector Computing Based on Rotating Radius Cluster  
The rotational radius cluster of a workpiece is the set of the ordered edge point-center-point distances on the workpiece contour. If the workpiece is circular, as shown in Figure 2a, \(\mathrm{O(x,y)}\) is the center of mass of the circular workpiece, \(\mathrm{A(x,y)}\) is a point on the contour of the workpiece, and \(|\mathrm{OA}|\) denotes the radius of the workpiece. With point \(\mathrm{O}\) as the center of rotation, starting from point \(\mathrm{A}\), the rotation is 360 degrees, and each radius is expanded in an orderly manner, and the workpiece profile obtained is a flat straight line. The result is shown in Figure 2b. \begin{table}
\begin{tabular}{c c c c c c c} \hline \hline
**Category** & **M1** & **M2** & **Area** & **Circumference** & **Ratio of Long to** & **Radius** & **Radius** \\  & & & & & **Short Radius** & **Mean** & **Variance** \\ \hline A & 0.30242455 & 0.00825412 & 125,959 & 2292 & 4.429 & 232.49 & 87.62 \\ B & 0.17034508 & 0.00001640 & 362,931 & 2368 & 1.763 & 341.89 & 44.11 \\ B-Mirror & 0.17034508 & 0.00001640 & 362,931 & 2368 & 1.763 & 341.89 & 44.11 \\ C & 0.18838271 & 0.00157881 & 248,166 & 1983 & 2.684 & 290.29 & 62.25 \\ D & 0.25531456 & 0.03709374 & 212,668 & 1902 & 3.585 & 278.40 & 94.46 \\ D-Mirror & 0.25531456 & 0.03709374 & 212,668 & 1902 & 3.585 & 278.40 & 94.46 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Base feature vectors for template shaped workpieces. For an irregular workpiece, as shown in Figure 3a, \(\mathrm{O}(\mathrm{x},\mathrm{y})\) is the center of mass of the irregular workpiece, \(\mathrm{A}(\mathrm{x},\mathrm{y})\) is a point on the contour of the workpiece, and \(\left|\mathrm{OA}\right|\) is one radius of the workpiece. With point \(\mathrm{O}\) as the center of rotation, starting from point \(\mathrm{A}\), the rotation is 360 degrees, and each radius is expanded in an orderly manner, and the workpiece contour is a curved contour with interlaced peaks and valleys, as shown in Figure 3b. It can be seen that when the workpiece is circular, the only basis for distinguishing different workpieces is the difference in radius. When reasoning to the irregular workpieces, with the same initial starting point \(\mathrm{A}(\mathrm{x},\mathrm{y})\), the cumulative difference of the unfolded profile curve at each rotation angle can be used as a criterion for determining whether the target workpiece and the template one can be matched. Since the contour curves of different irregular workpieces unfolded according to the radius must be different, the contour curves of shaped workpiece image unfolding can be used as the basis for stencil matching. Usually, the target workpiece has a rotation angle relative to the template one, so their initial point \(\mathrm{A}(\mathrm{x},\mathrm{y})\) is not consistent. In other words, the outline curve of the target workpiece and that of the template have a certain phase difference, as Figure 4 shows:  
Figure 3: Graphical radius of irregular workpiece. (**a**) Irregular piece, (**b**) Curve graph. Figure 2: Graphical radius of round workpiece. (**a**) Round piece, (**b**) Curve graph. To sum up, the details about the algorithm of irregular workpiece template matching based on the contour phase difference are as follows:  
* Phase difference matching calculation  
Assume that there is a template workpiece (\(X\)), and the distance from all its contour points to the center of mass is recorded as an array \(X_{[i]},i=0,\;1,\;2,\ldots,\;n\). Under the same conditions, an image of the target workpiece \(Y\) is captured, and the distance from all its contour points to center of mass is recorded as an array \(Y_{[j]},j=0,\;1,\;2,\ldots,m\). The number of pixels on the profile of the template workpiece and the target one represent \(n\) and \(m\) respectively, and if \(m\
eq n\), the arrays with more pixel points need to be isometric sparse processed.