# DataMatrix Code Recognition Method Based on Coarse Positioning of Images
## 4 Binarization Method Based on Grayscale Change Trend
### Outlier Detection and Correction  
Outliers are considered to be points that are significantly different from other observations in the dataset or that do not conform to expected normal behavior [42; 43]. Traditional outlier detection methods include the statistics-based Pauta criterion [44], the distance-based K-nearest neighbor algorithm [45], and the density-based LOF algorithm [46]. As for the Pauta criterion, it actually does not only require an assumption about the distribution of the data but also requires that the number of points used for outlier detection is large enough. When the number of points is less than or equal to 10, the Pauta criterion fails. To balance the efficiency of the algorithm, the number of divisions for a single grid cannot be too high, as depicted in Figure 9, so it does not meet the requirements of the Pauta criterion for data volume. As for the distance-based K-nearest neighbor algorithm, it calculates the distance between each point in the dataset and its K-nearest point to detect outliers. However, different k values have a significant impact on the results of this algorithm. If the selected k value is too small, it will cause the outlier detection results of the algorithm to be easily affected by noise. Conversely, it will cause the outlier detection results to be easily affected by distant points. The results obtained by performing outlier detection based on this algorithm may have some flaws. Density-based outlier detection methods use local density information to detect outliers. The basic idea is to treat points that appear in low-density areas as outliers and points that appear in high-density areas as normal points [47]. The LOF algorithm is the most representative density-based outlier detection method. The core method of the algorithm is to compare the local density deviation between the target point and neighboring points and determine whether the target point is an outlier by calculating the ratio of local density deviation [48]. Since the LOF algorithm incorporates neighboring points while calculating target points, and since the ratio of local density deviation of target points contains information about neighboring points, its accuracy is relatively high. Therefore, this paper uses the LOF algorithm to detect outliers. The relevant definitions and calculation methods of the LOF algorithm are as follows:  
1. Distance between sample points. There are many ways to measure the distance between points, and the commonly used distance measurement method can be defined by the Minkowski distance [49]. For a dataset \(P\), the distance between point \(p\) and point \(o\) is denoted as \(d(p,o)\), and the Minkowski distance formula is shown in Equation (5): \[d(p,o)=\left\{\sum_{i=1}^{n}|p_{i}-o_{i}|^{q}\right\}^{\frac{1}{q}}\] (5) when the value of \(q\) in the Minkowski distance expression is 1, it is called the Manhattan distance, which is used to calculate the orthogonal-side distance between two points. When the value of \(q\) in the Minkowski distance expression is 2, it is called the Euclidean distance [50], which is used to calculate the straight-line distance between two points in Euclidean space. When the value of \(q\) in the Minkowski distance expression tends to infinity, it is called the Chebyshev distance, which is used to calculate the maximum absolute value of the difference between coordinate values. The Chebyshev distance focuses on the maximum deviation in a single dimension and is not sensitive to coordinated changes across multiple directions. The Manhattan distance captures the cumulative horizontal and vertical deviations by summing the differences in each dimension, making it unable to directly reflect the true magnitude of diagonal changes. The Euclidean distance can directly measure the linear distance between two points, providing an accurate measure regardless of whether the deviation occurs horizontally, vertically, or diagonally.