# DataMatrix Code Recognition Method Based on Coarse Positioning of Images
## 4 Binarization Method Based on Grayscale Change Trend
### Outlier Detection and Correction
This means that the Euclidean distance can capture variations in all directions in DM codes, not just in a certain direction. Therefore, this paper chooses the Euclidean distance as the measurement method for distance. 2. The k-distance. If there are at least k points \(o^{\prime}\in C\{x\
eq p\}\) in dataset \(P\) that do not include \(p\), satisfying \(d(p,o^{\prime})\leq d(p,o)\), at most k\(-1\) points \(o^{\prime\prime}\in C\{x\
eq p\}\); not including \(p\) and satisfying \(d(p,o^{\prime\prime})\leq d(p,o)\), then the k-distance \(d_{k}(p)\) of point \(p\) refers to the distance between the k-farthest point from \(p\) in the dataset and \(p\). 3. The k-distance neighborhood. For dataset \(P\), the k-distance neighborhood of point \(p\) is denoted as \(N_{k}(p)\), and the definition of \(N_{k}(p)\) is shown in Equation (6): \[N_{k}(p)=\{o\in P|d(p,o)\leq d_{k}(p)\}.\] (6) In fact, the k-distance neighborhood of point \(p\) is a set of points that satisfy special properties. The points in the set satisfy that their distance to point \(p\) is less than or equal to the k-distance of point \(p\). 4. Reachability distance. For dataset \(P\), the reachability distance from point \(p\) to point \(o\) is denoted as \(r_{k}(p,o)\), and the definition of \(r_{k}(p,o)\) is shown in Equation (7): \[r_{k}(p,o)=max\{d_{k}(p),d(p,o)\}.\] (7) The reachability distance from point p to any point is at least equal to the k-distance of point \(p\). If a point belongs to the k-distance neighborhood of point \(p\), then the reachability distance from point \(p\) to this point is equal to the k-distance of point \(p\); if a point does not belong to the k-distance neighborhood of point \(p\), then the reachability distance from point \(p\) to this point is equal to the actual distance between the two points. 5. Local reachability density. For dataset \(P\), the local reachability density of point \(p\) is denoted as \(lrd_{k}(p)\), and the definition of \(lrd_{k}(p)\) is shown in Equation (8): \[lrd_{k}(p)=1/\left(\frac{\sum_{o\in N_{k}(p)}r_{k}(p,o)}{|N_{k}(p)|}\right),\] (8) where \(|N_{k}(p)|\) represents the number of points contained in the k-distance neighborhood of point \(p\). In fact, the local reachability density of point \(p\) represents the reciprocal of the average value of the reachability distance from all points in the k-distance neighborhood of point \(p\) to point \(p\). When the distance between point \(p\) and other points in its k-distance neighborhood is larger, the local reachability density of point \(p\) is smaller, indicating that the distribution of point \(p\) and its surrounding points is sparser. Conversely, the larger the local reachability density of point \(p\), the denser the distribution of point \(p\) and its surrounding points. It should be noted that there is an implicit premise in the definition of local reachability density, i.e., all points in the k-distance neighborhood of point \(p\) cannot be duplicate points. This is because if such duplicate points exist, the reachability distance calculated in local reachability density will be zero, causing local reachability density to become infinite. 6. Local outlier factor. For dataset \(P\), the LOF of point \(p\) is denoted as \(LOF_{k}(p)\), and the definition of \(LOF_{k}(p)\) is shown in Equation (9): \[LOF_{k}(p)=\frac{\sum_{o\in N_{k}(p)}lrd_{k}(o)}{|N_{k}(p)|lrd_{k}(p)},\] (9)where the LOF of point \(p\) represents the average of the ratio of the local reachability density of the neighborhood points \(N_{k}(p)\) of point \(p\) to the local reachability density of point \(p\). If the LOF is less than 1, it means that the local reachability density of point \(p\) is higher than that of its neighborhood points, so point \(p\) belongs to a dense point. If the LOF is equal to 1, it means that the local reachability density of point \(p\) is similar to that of its neighborhood points, so point \(p\) and its neighborhood points may belong to the same cluster.