# DataMatrix Code Recognition Method Based on Coarse Positioning of Images
## 3 Method of Adaptive Sampling Grid Partitioning
### Dividing Line Recognition  
Since there are peaks caused by wear, corrosion, geometric distortion, and background noise among the detected peaks, it is necessary to screen out the peaks representing the position of the dividing line from the detected peaks. This paper proposes a dividing line recognition method based on predicting the dividing line spacing. The dividing line spacing is predicted based on the detected adjacent peak spacing; the detected peaks are grouped based on the predicted dividing line spacing, and the position of the strongest peak in the group is defined as the dividing line position.  
Taking Figure 6a as an example, the histogram of horizontal adjacent peak spacing is shown in Figure 8.  
Since abnormal peaks caused by poor DM code image quality will reduce the adjacent peak spacing, an exponential weighted moving average algorithm is used to predict the dividing line spacing after sorting the adjacent peak spacing. The exponential weighted moving average algorithm [40] is a commonly used time series smoothing algorithm for smoothing data and trend analysis. It gives greater weight to recent observations and gradually decreases as the distance between observations and the current time point increases. Through this algorithm, different weights can be assigned to adjacent peak spacings after sorting, reducing the impact of abnormal peaks and predicting dividing line spacings. The calculation formula of the exponential weighted moving average algorithm is shown in Equation (4):  
\[y_{t}=\begin{cases}x_{0},\ t=0\\ \alpha x_{t}+(1-\alpha)y_{t-1},\ t>0\end{cases}, \tag{4}\]  
where the position of the current point is \(t\), the value of the current point is \(x_{t}\), the weighted average value at the current time is \(y_{t}\), the weighted average value at the previous time is \(y_{t-1}\), \(x_{0}\) represents the value of the first point, and \(\alpha\) is the smoothing coefficient, typically between 0 and 1. A larger \(\alpha\) gives more weight to the current point \(x_{t}\), making the estimate more responsive to recent changes. A smaller \(\alpha\) gives more weight to the previous weighted average \(y_{t-1}\), resulting in smoother estimates that are less responsive to recent fluctuations.  
One must then traverse the detected peaks. If the adjacent peak spacing is less than half of the predicted dividing line spacing, it is considered a peak in the same group. After  
Figure 8: Histogram of horizontal adjacent peak spacing in Figure 6a.  
grouping the peaks, if there is only one peak in a group of peaks, one must directly define the position of that peak as the dividing line position. If there are multiple peaks in a group of peaks and only one maximum peak value, then this maximum peak value is the position where the dividing line position is defined; if multiple peaks have the same maximum value, then the position where the first peak is located is defined as the dividing line position. Finally, one must traverse the dividing line positions. If the adjacent dividing line spacing is greater than twice the predicted dividing line spacing, a dividing line needs to be inserted until the adjacent dividing line spacing is less than twice the predicted dividing line spacing.  
The adaptive sampling grid division effects of Figures 4a and 6a are shown in Figure 9a,b.