## 3 Methodology
### Surface Defect Detection  
Defect detection was performed in two stages: coarse detection and fine extraction. The former leveraged the deviation of normal vectors and curvature within an adaptive neighborhood to identify potential defects, albeit often accompanied by partial false positives. Specifically, for a given point \(p\), if the angular deviation between its normal vector and the average normal vector of its adaptive neighbors exceeded a predefined threshold \(\alpha_{i}\), the point was marked as defective. Regarding curvature, the mean \(\mu\) and standard deviation \(\sigma\) of the curvature values of the adaptive neighborhood surrounding point \(p\) were first computed. A threshold was then defined as \(\mu+\beta\sigma\). If the curvature at point \(p\) exceeded this threshold, the point was marked as a defect. The candidate defect points obtained from coarse detection constituted the union of these two sets. Subsequently, macroscopic defects were extracted by analyzing the residuals of curve fitting. In the x-direction, a linear fit was applied to obtain a profile that satisfied Equation (13). A certain number of profiles along this direction were selected, and their slopes were averaged to yield \(S\). Given that the spacing of points along the x-direction was constant, specifically 0.005 mm, the height difference \(\Delta z_{i,i\pm 1}\) between any two points was calculated as 0.0055. When fitting data along the y-direction, a standard profile equation was first obtained, and the remaining profiles were subsequently aligned with this reference by applying a vertical shift equal to \(\Delta z_{i,i\pm 1}\). Next, for each fitted y-direction profile, the residual \(\Delta z\) in the z-direction between the original data and the fitted curve was calculated. Conventionally, points are identified as defects when the residual exceeds a predetermined threshold. However, we adopted a more robust approach by converting the z-direction residuals into a probability density using kernel density estimation (KDE) [84],a non-parametric statistical method. The primary advantage of KDE is its flexibility in capturing the true underlying data distribution without assuming a specific parametric form. The corresponding mathematical expression is as follows:  
\[f(\Delta_{z})=\frac{1}{nh}\sum_{i=1}^{n}\frac{1}{\sqrt{2\pi}}e^{-\frac{(\frac{ \Delta_{z}-\Delta_{ii}}{n})^{2}}{2}} \tag{18}\]  
where \(n\) represents the sample size (number of residuals), and \(h\) denotes the bandwidth (smoothing parameter) determined by [PERSON]'s rule of thumb [85]:  
\[h=1.06\epsilon n^{-1/5} \tag{19}\]  
where \(\epsilon\) represents the standard deviation of the residuals \(\Delta_{z}\). Using Equation (18), we obtained the probability density corresponding to each residual. A lower probability density indicates a larger residual, suggesting a higher likelihood of a defect. We then ranked these probability densities in ascending order and set a quantile threshold for defect identification. For instance, by selecting the 5 th percentile, the residuals falling within the lowest 5% of the probability density distribution were classified as defects. For macro defects, they were characterized by larger residuals. However, with the continuous improvement in manufacturing processes, large macro defects are less common in actual products, meaning they occupy a smaller percentage of the total. Consequently, the quantile threshold could be set to a lower value. This approach allowed us to accurately detect macro defects with minimal false positives. We then applied this method to the candidate defect points previously identified by normal vector and curvature deviation filtering. These points exhibited smaller residuals, but there remained a certain disparity between the residuals of defect and non-defect points. By slightly increasing the quantile threshold, we could effectively minimize false positives while retaining smaller defects with some depth.