A sub-pixel edge detection method based on Zernike moment guided Gaussian fitting
By using a Gaussian fitting method guided by Zernike moments, the positioning deviation and robustness problems of the Zernike moment method in sub-pixel edge detection in the existing technology are solved, and edge detection with higher accuracy and noise resistance is achieved, which can adapt to different lighting and contrast conditions.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- NATIONAL INSTITUTE OF METROLOGY CHINA
- Filing Date
- 2026-04-23
- Publication Date
- 2026-06-12
AI Technical Summary
The existing Zernike moment method has problems in subpixel edge detection, such as the ideal model not matching reality, threshold setting relying on experience, and difficulty in balancing noise resistance and accuracy, resulting in positioning errors and poor robustness.
A Gaussian fitting method guided by Zernike moments is adopted. Pixel-level edge detection is performed using the Canny operator. The Zernike moment calculation template and Otsu's method are combined to automatically set the threshold. Gaussian fitting is performed along the gradient direction for accurate localization. The Levenberg-Marquardt nonlinear least squares method is used to optimize the fitting parameters, and the coefficient of determination R2 is introduced as a confidence index for adaptive screening.
It improves the accuracy and noise resistance of edge detection, enhances the environmental adaptability of the algorithm, and significantly improves the accuracy and robustness of subpixel localization.
Smart Images

Figure CN122199591A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of image processing and computer vision technology, specifically relating to a sub-pixel edge detection method based on Zernike moment-guided Gaussian fitting. Background Technology
[0002] With the rapid development of industrial vision measurement technology, the requirements for image edge detection accuracy have increased from pixel level to sub-pixel level. In applications such as high-precision camera calibration, 3D reconstruction, and industrial dimensional measurement, the positioning accuracy of feature points (such as the center of a circular marker) directly determines the final accuracy of the entire measurement system.
[0003] Currently, mainstream sub-pixel edge detection technologies are mainly divided into three categories: moment methods, fitting methods, and interpolation methods. Among them, methods based on Zernike moments are widely used due to their good rotation invariance and noise resistance. However, existing technologies have the following shortcomings: (1) The ideal model does not match reality: The traditional Zernike moment method derives subpixel positions based on an ideal step edge model, that is, it assumes that the gray value at the edge jumps instantaneously from the background value to the target value. However, in the actual imaging process, due to factors such as optical diffraction, lens defocusing and sensor sampling, the real edge usually presents a gray-level transition band of a certain width, which is not an ideal step change. Directly applying the step model will lead to systematic positioning errors.
[0004] (2) Threshold setting depends on experience: When the traditional Zernike moment method is used to filter edge points, it involves grayscale threshold. k t and spacing threshold l t Key parameters, such as edge detection thresholds, are often set based on human experience. Fixed empirical thresholds are difficult to adapt to changes in images under different lighting conditions and contrast levels, easily leading to missed or false edge detections, resulting in poor algorithm robustness.
[0005] (3) It is difficult to balance noise resistance and accuracy: the simple Gaussian fitting method has insufficient fitting stability in noisy environments and is easily affected by outliers; while the simple Zernike moment method has limited positioning accuracy for blurred edges and is difficult to meet the requirements of high-precision measurement. Summary of the Invention
[0006] This invention aims to overcome the shortcomings of existing technologies and provides a sub-pixel edge detection method based on Zernike moment-guided Gaussian fitting to solve the positioning deviation problem of traditional step model caused by edge blurring, thereby improving the accuracy, noise resistance and automation of edge detection.
[0007] A sub-pixel edge detection method based on Zernike moment-guided Gaussian fitting includes the following steps: S1, pixel-level coarse edge detection: Input the image to be detected, set the high and low thresholds of the Canny operator based on the image's grayscale distribution, and use the Canny edge detection operator to perform pixel-level edge extraction to obtain an initial edge point set. P 0{( x 0, y 0)}; S2, calculated based on the edge direction of the Zernike moment: A 7×7 pixel Zernike moment calculation template is constructed and convolved with the image to calculate the Zernike moment values at each pixel-level edge point. Based on the rotation invariance of Zernike moments, the edge orientation angles are then determined. ; Calculate edge normal distance l and grayscale difference k The Otsu method is introduced to calculate the grayscale threshold. k t For each candidate edge point, if the grayscale difference k Greater than the threshold k t and normal distance l satisfy l ≤ l t ,in , N If the value is the template size, then it is determined to be a valid edge point; S3, precise localization using Gaussian fitting along the gradient direction, specifically: S3.1, Directional Sampling: Based on the gradient direction angle at the edge point i Calculate the corresponding unit direction vector ( u x , u y ),in: Then, using the valid edge points obtained in step S2 ( x 0, y Centered on 0), with its gradient direction angle Determined unit direction vector ( u x , u y The path is defined as follows: Equally spaced samples are taken on both sides of the normal direction. The sampling points are: In the formula, ( ) represents the pixel coordinates of the point to be sampled, and the sampling step size is Δ. s Typically, 1 pixel is used, and the number of sampling points is... k Take 2 N +1, the sampling range covers the edge transition zone.
[0008] S3.2, Gray-level interpolation: Because images are discrete, pixel values are generally defined on an integer grid. The gray-level value at a sampling location is estimated using the four nearest neighbors and bilinear interpolation. Assume: In the formula, The floor symbol is ( ). )for( The result of rounding down, ( )for( The decimal part of the number corresponds to its four neighboring pixels: In the formula, , , as well as Given the gray values of the four integer pixels surrounding the sampling point, the gray-level distribution sequence can be calculated using the bilinear interpolation formula. I ( i ): S3.3, Gradient Calculation: Calculate the first-order discrete gradient of the sampled grayscale sequence to obtain the gradient distribution sequence. G ( i ): The approximate location of the maximum gradient is: S3.4, Gaussian model fitting: The gradient distribution is fitted using a Gaussian function; Based on gradient distribution G ( i ),exist s * A local fit is performed at the point, and the fitted function follows a Gaussian distribution: in, a For gradient magnitude, b This refers to the peak position, i.e., the sub-pixel offset. c Standard deviation; The Levenberg-Marquardt nonlinear least squares method is used to fit the sampling points and solve for the optimal parameters. b fit The initial values for the fit are set to... a 0= G ( s peak ), b 0= s peak , c 0= N / 3, the objective function is: ; S3.5, Adaptive confidence screening based on goodness-of-fit: After the nonlinear least squares fitting is completed, a statistical coefficient of determination is introduced. R 2 As a confidence index, it adapts to the noise level under different lighting and contrast conditions; S3.6, Sub-pixel coordinate calculation: Calculate the filtered offsets. b fit Applied to the original edge points, the refined sub-pixel edge coordinates are obtained: ( x 0, y 0) represents the original pixel edge point, ( x r , y r ) represents refined sub-pixel edge points, u x , u y () is the direction unit vector S4, Repeat steps: Repeat steps S2 to S3 until all initial edge points have been processed, and output a sub-pixel level edge point set.
[0009] Further, step S2 specifically includes: S2.1, Construct a 7×7 pixel Zernike moment calculation template, where the three basic Zernike moments include Z 00 , Z 11 and Z 20 ; S2.2, perform a convolution operation between the above calculation template and the image to calculate the Zernike moment values at each pixel-level edge point; based on the rotation invariance of Zernike moments, the relationship between the moment values before and after image rotation satisfies ,in Let be the rotation angle; let the rotated image be about . x If axially symmetric, then the moments after rotation The imaginary part is 0, thus the edge direction angle can be solved. : S2.3, Calculate the edge normal distance l and grayscale difference k For an ideal two-dimensional edge model, the following can be derived using Zernike moments: in, l This represents the normal distance from the origin to the edge. k Indicates the magnitude of the grayscale jump on both sides of the edge; S2.4, Introducing the Otsu method to calculate the grayscale threshold. k t The Otsu algorithm is used to analyze the global gray-level histogram of an image, calculate the maximum inter-class variance, and determine the optimal gray-level threshold. k t For each candidate edge point, if the grayscale difference... k Greater than the threshold k t and normal distance l satisfy l ≤ l t ,in , N If the template size is used, then it is determined to be a valid edge point.
[0010] Further, step S3.5 specifically includes: S3.5.1, Calculate the sum of squared residuals SSE For each edge point that has completed the fitting, calculate its observed gradient sequence G. obs ( s i ) and Gaussian fitting curve G fit ( s i Sum of squared residuals between: S3.5.2, Calculate the total sum of squares SST : Calculate the observed gradient sequence relative to its mean Total volatility: S3.5.3, Calculate the coefficient of determination R 2 Construct a normalized goodness-of-fit index: S3.5.4, Dynamic Judgment and Removal: Set confidence threshold The range is 0.90~0.98; like If the confidence level of a point is deemed high, its fitted sub-pixel offset is retained. b fit Used for subsequent coordinate calculations; like If the confidence level of a point is deemed low, that point is removed and will not be included in subsequent circle center fitting or line connection.
[0011] In summary, due to the adoption of the above technical solution, the beneficial effects of the present invention are: 1. Higher positioning accuracy: This invention overcomes the systematic bias caused by the traditional Zernike moment method based on the ideal step model by fitting the gray-level gradient distribution of the real edge transition zone with a Gaussian function.
[0012] 2. Enhanced noise robustness: This invention utilizes the rotational invariance of Zernike moments to provide precise gradient direction guidance, effectively constraining the search path of Gaussian fitting and avoiding interference from noise points in the fitting process.
[0013] 3. Adaptive parameter selection: This invention introduces the Otsu method to automatically calculate the grayscale threshold. k t This avoids the uncertainty of human experience setting, enabling the algorithm to automatically adjust the screening criteria according to image quality, and has stronger environmental adaptability in different lighting conditions and different contrast scenes. Attached Figure Description
[0014] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly described below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort, wherein: Figure 1 This is a flowchart of the method of the present invention; Figure 2 This is a schematic diagram illustrating the construction of the 7×7 pixel Zernike moment calculation template of this invention; Figure 3 This is a schematic diagram of the grayscale distribution curve and its Gaussian fitting result of the present invention; Figure 4 This is a schematic diagram of the circular calibration plate pattern in Embodiment 1 of the present invention. Detailed Implementation
[0015] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0016] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.
[0017] It should be noted that the labels and letters in the following figures represent similar items, therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.
[0018] A sub-pixel edge detection method based on Zernike moment-guided Gaussian fitting is performed according to the following steps: Step 1: Pixel-level coarse edge detection Input the image to be detected, and use the Canny edge detection operator to perform pixel-level edge extraction to obtain an initial edge point set. P 0{( x 0, y 0)}. The high and low thresholds of the Canny operator can be automatically set according to the grayscale distribution of the image or adjusted manually.
[0019] Step 2: Calculate edge directions based on Zernike moments 2.1 As Figure 2 The diagram illustrates the construction of a 7×7 pixel Zernike moment calculation template. Compared to the traditional 5×5 template, the 7×7 template provides higher resolution for edge parameter calculation. This invention relates to three basic Zernike moments: Z 00 , Z 11 and Z 20 Its 7×7 template coefficients are obtained by discrete integration.
[0020] 2.2 Perform convolution operation between the above template and the image to calculate the Zernike moment values at each pixel-level edge point. Based on the rotation invariance of Zernike moments, the moment values before and after image rotation satisfy the following relationship: ,in Let be the rotation angle. Suppose the rotated image is about... x If axially symmetric, then the moments after rotation The imaginary part is 0, from which the edge direction angle can be solved. : 2.3 Calculate the edge normal distance l and grayscale difference k For an ideal two-dimensional edge model, the following can be derived using Zernike moments: in, l This represents the normal distance from the origin to the edge. k This indicates the magnitude of the grayscale jump on both sides of the edge.
[0021] 2.4 Introducing the Otsu method to automatically calculate the grayscale threshold k t Traditional threshold selection relies on human experience. This invention utilizes the Otsu algorithm to analyze the global gray-level histogram of the image, calculate the maximum inter-class variance, and thus adaptively determine the optimal gray-level threshold. k t For each candidate edge point, if its grayscale difference... k Greater than the threshold k t and normal distance l satisfy l ≤ l t ( , N If the template size is used, then it is determined to be a valid edge point.
[0022] Step 3: Accurate localization using Gaussian fitting along the gradient direction 3.1 Directional Sampling: First, based on the gradient direction angle at the edge point... i Calculate its corresponding unit direction vector ( u x , u y ),in: Then, using the effective edge points obtained in the second step ( x 0, y Centered on 0), with its gradient direction angle Determined unit direction vector ( u x , u yThe path is defined as follows: Equally spaced samples are taken on both sides of the normal direction. The sampling points are: In the formula, ( ) represents the pixel coordinates of the point to be sampled, and the sampling step size is Δ. s Typically, 1 pixel is used, and the number of sampling points is... k Take 2 N +1, the sampling range covers the edge transition zone.
[0023] 3.2 Gray-level Interpolation: Because images are discrete, pixel values are generally defined on an integer grid. Therefore, the gray-level value at the sampling location is estimated using the four nearest neighbors and bilinear interpolation. Assumptions: In the formula, The floor symbol is ( ). )for( The result of rounding down, ( )for( The decimal part of the number corresponds to its four neighboring pixels: In the formula, , , as well as Given the gray values of the four integer pixels surrounding the sampling point, the gray-level distribution sequence can be calculated using the bilinear interpolation formula. I ( i ): 3.3 Gradient Calculation: Calculate the first-order discrete gradient of the sampled grayscale sequence to obtain the gradient distribution sequence. G ( i ): Theoretically, the approximate location of the maximum gradient is: 3.4 Gaussian model fitting: as shown Figure 3 As shown, this invention proposes using a Gaussian function to fit the gradient distribution, instead of the step model used in traditional methods. To obtain refined sub-pixel edges, based on the gradient distribution... G ( i ),exist s * A local fit is performed at the point, and the fitted function follows a Gaussian distribution: in,a For gradient magnitude, b This refers to the peak position, i.e., the sub-pixel offset. c The standard deviation is denoted as .
[0024] The Levenberg-Marquardt nonlinear least squares method is used to fit the sampling points and solve for the optimal parameters. b fit The initial values for fitting can be set as follows: a 0= G ( s peak ), b 0= s peak , c 0= N / 3, the objective function is: 3.5 Adaptive Confidence Screening Based on Goodness-of-Fit: After the nonlinear least squares fitting is completed, this method does not directly use a fixed threshold to judge the validity of edge points, but introduces the coefficient of determination from statistics. R 2 As a confidence level indicator, it adapts to noise levels under different lighting and contrast conditions. The specific implementation is as follows: (1) Calculate the sum of squared residuals ( SSE For each edge point that has completed the fitting, calculate its observed gradient sequence G. obs ( s i ) and Gaussian fitting curve G fit ( s i Sum of squared residuals between: (2) Calculate the total sum of squares. SST ): Calculate the observed gradient sequence relative to its mean. Total volatility: (3) Calculate the coefficient of determination ( R 2 Construct a normalized goodness-of-fit index: (4) Dynamic judgment and elimination: Set confidence threshold (The preferred range is 0.90~0.98, and more preferably 0.95).
[0025] like If the confidence level of a point is deemed high, its fitted sub-pixel offset is retained.b fit Used for subsequent coordinate calculations.
[0026] like If the confidence level of a point is deemed low, that point is removed and will not be included in subsequent circle center fitting or line connection.
[0027] 3.6 Sub-pixel coordinate calculation: Calculate the filtered offsets. b fit Applied to the original edge points, the refined sub-pixel edge coordinates are obtained: ( x 0, y 0) represents the original pixel edge point, ( x r , y r ) represents refined sub-pixel edge points, u x , u y ) is a unit vector of direction.
[0028] Step 4: Repeat the above steps Repeat steps two and three until all initial edge points have been processed, and output a sub-pixel level edge point set.
[0029] Example 1 This embodiment applies the method of the present invention to monocular camera calibration, verifying its effectiveness under real imaging conditions. The experimental platform includes a 12-megapixel industrial camera (resolution 2448×2048, equipped with an 8mm fixed-focus lens) and a circular array calibration board measuring 320mm×240mm (e.g., Figure 4 (As shown).
[0030] First, images of the calibration board were captured in different spatial poses, totaling 20 images. For example... Figure 1 The process shown employs the method of this invention to extract sub-pixel edges of circular feature points in each image. The specific steps are as follows: (1) The Canny operator extracts pixel-level edges; (2) Calculate edge direction using 7×7 Zernike rectangular template, and use Otsu automatic threshold filtering; (3) Sample along the gradient direction and obtain grayscale values using bilinear interpolation; (4) Gaussian fitting is used to solve the sub-pixel offset to obtain refined edge points; (5) Calculate the coordinates of the center of the circle by least squares ellipse fitting.
[0031] The extracted center coordinates were substituted into Zhang Zhengyou's calibration method for intrinsic parameter calculation, and the reprojection error was calculated as the evaluation index. Five repeated experiments were conducted, with 20 new images captured each time.
[0032] Table 1 shows the statistics of the average reprojection error for the five experiments: Table 1 Comparison of single-target calibration results using different methods (unit: pixel) Experimental results show that the average reprojection error of the calibration method of this invention is 0.039 pixels, which is significantly better than other comparative methods, proving that the present invention can effectively improve the camera calibration accuracy.
[0033] The above description constitutes an embodiment of the present invention. The foregoing descriptions are preferred embodiments of the present invention. Unless there is a clear contradiction or a prerequisite for a particular preferred embodiment, the preferred embodiments can be arbitrarily combined and used. The embodiments and specific parameters described are merely for clearly illustrating the verification process of the invention and are not intended to limit the scope of patent protection of the present invention. The scope of patent protection of the present invention is still determined by its claims. Similarly, any equivalent structural changes made based on the description and drawings of the present invention should also be included within the scope of protection of the present invention.
Claims
1. A sub-pixel edge detection method based on Zernike moment-guided Gaussian fitting, characterized in that, Includes the following steps: S1, pixel-level coarse edge detection: Input the image to be detected, set the high and low thresholds of the Canny operator based on the image's grayscale distribution, and use the Canny edge detection operator to perform pixel-level edge extraction to obtain an initial edge point set. P 0{( x 0, y 0)}; S2, calculated based on the edge direction of the Zernike moment: A 7×7 pixel Zernike moment calculation template is constructed and convolved with the image to calculate the Zernike moment values at each pixel-level edge point. Based on the rotation invariance of Zernike moments, the edge orientation angles are then determined. ; Calculate edge normal distance l and grayscale difference k The Otsu method is introduced to calculate the grayscale threshold. k t For each candidate edge point, if the grayscale difference k Greater than the threshold k t and normal distance l satisfy l ≤ l t ,in , N If the value is the template size, then it is determined to be a valid edge point; S3, precise localization using Gaussian fitting along the gradient direction, specifically: S3.1, Directional Sampling: Based on the gradient direction angle at the edge point i Calculate the corresponding unit direction vector ( u x , u y ),in: ; Then, using the valid edge points obtained in step S2 ( x 0, y Centered on 0), with its gradient direction angle Determined unit direction vector ( u x , u y The path is defined as follows: Equally spaced samples are taken on both sides of the normal direction. The sampling points are: ; in,( ) represents the pixel coordinates of the point to be sampled, and the sampling step size is Δ. s Take 1 pixel, number of sampling points k Take 2 N +1, the sampling range covers the edge transition zone; S3.2, Gray-level interpolation: Since images are discrete, pixel values are generally defined on an integer grid. Therefore, the gray-level value at the sampling location is estimated using the four nearest neighbors and bilinear interpolation. Assume: ; in, The floor symbol is ( ). )for( The result of rounding down, ( )for( The decimal part of the result corresponds to four neighboring pixels: ; in, , , as well as Given the gray values of the four integer pixels surrounding the sampling point, the gray-level distribution sequence can be calculated using the bilinear interpolation formula. I ( i ): ; S3.3, Gradient Calculation: Calculate the first-order discrete gradient of the sampled grayscale sequence to obtain the gradient distribution sequence. G ( i ): ; The approximate location of the maximum gradient is: ; S3.4, Gaussian model fitting: The gradient distribution is fitted using a Gaussian function; Based on gradient distribution G ( i ),exist s * A local fit is performed at the point, and the fitted function follows a Gaussian distribution: ; in, a For gradient magnitude, b This refers to the peak position, i.e., the sub-pixel offset. c Standard deviation; The Levenberg-Marquardt nonlinear least squares method is used to fit the sampling points and solve for the optimal parameters. b fit The initial values for the fit are set to... a 0= G ( s peak ), b 0= s peak , c 0= N / 3, the objective function is: ; S3.5, Adaptive confidence screening based on goodness-of-fit: After the nonlinear least squares fitting is completed, a statistical coefficient of determination is introduced. R 2 As a confidence index, it adapts to the noise level under different lighting and contrast conditions; S3.6, Sub-pixel coordinate calculation: Calculate the filtered offsets. b fit Applied to the original edge points, the refined sub-pixel edge coordinates are obtained: ; ( x 0, y 0) represents the original pixel edge point, ( x r , y r ) represents refined sub-pixel edge points, u x , u y () is the direction unit vector S4, Repeat steps: Repeat steps S2 to S3 until all initial edge points have been processed, and output a sub-pixel level edge point set.
2. The sub-pixel edge detection method based on Zernike moment-guided Gaussian fitting according to claim 1, characterized in that, Step S2 specifically involves: S2.1, Construct a 7×7 pixel Zernike moment calculation template, where the three basic Zernike moments include Z 00 , Z 11 and Z 20 ; S2.2, perform a convolution operation between the above calculation template and the image to calculate the Zernike moment values at each pixel-level edge point; based on the rotation invariance of Zernike moments, the relationship between the moment values before and after image rotation satisfies ,in Let be the rotation angle; let the rotated image be about . x If axially symmetric, then the moments after rotation The imaginary part is 0, thus the edge direction angle can be solved. : ; ; S2.3, Calculate the edge normal distance l and grayscale difference k For an ideal two-dimensional edge model, the following can be derived using Zernike moments: ; in, l This represents the normal distance from the origin to the edge. k Indicates the magnitude of the grayscale jump on both sides of the edge; S2.4, Introducing the Otsu method to calculate the grayscale threshold. k t The Otsu algorithm is used to analyze the global gray-level histogram of an image, calculate the maximum inter-class variance, and determine the optimal gray-level threshold. k t For each candidate edge point, if the grayscale difference... k Greater than the threshold k t and normal distance l satisfy l ≤ l t ,in , N If the template size is used, then it is determined to be a valid edge point.
3. The sub-pixel edge detection method based on Zernike moment-guided Gaussian fitting according to claim 1, characterized in that, Step S3.5 specifically includes: S3.5.1, Calculate the sum of squared residuals SSE For each edge point that has completed the fitting, calculate its observed gradient sequence G. obs ( s i ) and Gaussian fitting curve G fit ( s i Sum of squared residuals between: ; S3.5.2, Calculate the total sum of squares SST : Calculate the observed gradient sequence relative to its mean Total volatility: ; S3.5.3, Calculate the coefficient of determination R 2 Construct a normalized goodness-of-fit index: ; S3.5.4, Dynamic Judgment and Removal: Set confidence threshold The range is 0.90~0.98; like If the confidence level of a point is deemed high, its fitted sub-pixel offset is retained. b fit Used for subsequent coordinate calculations; like If the confidence level of a point is deemed low, that point is removed and will not be included in subsequent circle center fitting or line connection.