## 1 Introduction
Essentially, a single processing configuration cannot simultaneously achieve satisfactory reconstruction in areas with heightened contrast and areas with poor contrast within the same image. As a result of these findings, two potential strategies were proposed: the formulation of an adaptive procedure for contour detection and the development of scanning devices with controlled directional illumination. The present work focuses on implementing the first of the aforementioned strategies by devising a procedure for edge detection that is tailored for non-uniform contrast patterns. The premise is that the location of a layer contour point can be determined by comparing the local grayscale pattern surrounding its theoretical position with a pre-existing reference pattern. Accordingly, we utilized a series of orientable test artefacts with contours at various layer-to-background distances while also allowing for setting different contour-to-illumination orientation angles. The test artefacts are digitized using a coordinate measuring machine (CMM) to accurately determine the position of individual contour points. A digital image is captured using a CIS, enabling the calculation of contour point positions in pixel coordinates from the CMM data. Subsequently, local grayscale patterns corresponding to the location of each contour point are extracted and grouped in a gradient reference pattern (GRP) database. Then, when characterizing the contour of a manufactured part, its approximate location can be predicted from the CAD file. Accordingly, the approximate positions of individual tentative contour points can be established beforehand in the digital image captured with the CIS. A set of one-dimensional regions of interest (ROIs) can then be defined around those tentative contour points. Finally, a set of candidate patterns (CPs) are extracted from the ROIs, and their similarity to the correspondent GRP is subsequently evaluated. The most similar CP for a given tentative contour point will then be used to determine the exact location of the actual contour point. This procedure provides precise identification of contour point locations in the target layer and is less susceptible to being influenced by local characteristics of the contrast pattern. The proposed method diverges from conventional approaches in three significant aspects:* Contour point identification relies on data obtained from test artefacts measured with a CMM, whereas conventional approaches stand alone, and the dimensional accuracy of contour reconstruction is not even relevant. * Edge detection is customized through adaptive processing that considers the local characteristics of the layer-to-background pattern. This approach differs from methods that process entire images with a single algorithm configuration. * Each local search yields a single contour point, differing from the multiple candidates typically provided by most edge-detection algorithms. In summary, the approach presented in this work has been tailored to overcome the limitations of conventional algorithms, such as Canny or Prewitt, in situations where the layer-to-background contrast is highly uneven. While reported errors in related works are in the range of tenths of a millimeter [43; 44], our goal is to reduce these discrepancies for MEX/P parts through the optimization of conventional algorithms [29]. This means lowering quantification errors to below 50 um in non-uniform contrast scenarios. The subsequent sections of this paper are structured as follows: after the introduction in Section 1, Section 2 provides a general overview of the proposed adaptive edge-detection algorithm (AEDA); the method for constructing the reference database is outlined in Section 3; Section 4 elucidates how contour points are identified in a manufactured part; a practical example of the proposed procedure is presented in Section 5; the results are discussed in Section 6; and, finally, Section 7 summarizes the conclusions of this work.