Contour extraction method based on adaptive ellipse edge detection and fast fitting algorithm

CN118799590BActive Publication Date: 2026-08-21CHANGZHOU MICROINTELLIGENCE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410989105.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-23
Publication Date
2026-08-21
Estimated Expiration
2044-07-23

AI Technical Summary

Technical Problem

对于图像背景条纹较多的情况,提取的待拟合数据点集合会有干扰,降低准确性

Benefits of technology

本发明的有益效果是,实现了工业图像中椭圆图形的精确定位,通过寻找图形边缘点,并使用拟合点精确得到椭圆的参数方程,所提供的高精度参考点可用于图像的配准校正和目标定位等,本发明算法对于强边缘、弱边缘的表现有很强的鲁棒性;同时能够准确筛选内点、并剔除外点,得到鲁棒的、准确的、精确的椭圆方程;本发明运行时间短,效率高,精度高,鲁棒性强,通用性好,拥有可扩展性,为图像检测提供很好的帮助。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118799590B_ABST
    Figure CN118799590B_ABST
Patent Text Reader

Abstract

The application discloses a contour extraction method based on an adaptive ellipse edge detection and fast fitting algorithm, obtains an image region where an ellipse is located, and gives a search center, a search direction, a search frame position and size and a search space, and in the search space, from the search center to the search space boundary, according to the search direction, the whole search path of the search frame in the form of a ray is determined; all pixel values in the search frame are obtained; the gray values of all pixel points in the search frame are obtained; the obtained pixel values are clustered into two categories by using K-Means clustering; the ellipse is fitted by using a least square method; the point set far from the ellipse boundary is removed, and the point set close to the ellipse boundary, that is, the best inner point set, is left, so that the least square ellipse fitting is completed; and the last point set fitting result is drawn by using key coefficients of an ellipse equation obtained by the least square algorithm. The application can accurately find the positions of strong edges and weak edges of the ellipse, can autonomously screen inner points and can accurately fit the ellipse equation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the technical field of image detection, and in particular to a contour extraction method based on adaptive elliptical edge detection and a fast fitting algorithm. Background Technology

[0002] Industrial images contain a variety of geometric shapes, such as rectangles, polygons, circles, and ellipses. These shapes provide precise reference points (e.g., geometric centers) for image registration, correction, and target localization. Therefore, finding the edge positions of these geometric shapes and fitting accurate mathematical equations based on them is crucial for image detection. However, in images with numerous background stripes, the extracted set of data points for fitting can be interfering, reducing accuracy. This is especially true for regularly distributed stripe data. Summary of the Invention

[0003] The present invention aims to solve at least one of the technical problems existing in the prior art.

[0004] To address this, this invention proposes a contour extraction method based on adaptive ellipse edge detection and a fast fitting algorithm. It adopts a general algorithm for locating ellipses, which can accurately find the positions of strong and weak edges of the ellipse, and can autonomously select interior points and accurately fit the ellipse equation.

[0005] A contour extraction method based on adaptive elliptical edge detection and fast fitting algorithm according to an embodiment of the present invention includes the following steps: Step 1: Obtain the image region where the ellipse is located, and give the search center, search direction, search box position and size, and search space. Within the search space, starting from the search center to the boundary of the search space, determine the entire search path of the ray-shaped search box according to the search direction. Step 2: Obtain all pixel values ​​within the search box: Obtain the grayscale values ​​of all pixels within the search box; Step 3: Use K-Means clustering to cluster the obtained pixel values ​​into two categories: K-Means clustering is used to determine the edge points of the ellipse. K-Means clustering is used to cluster the gray values ​​of the pixels in the search box into two categories: one category is the set of pixel values ​​and pixel coordinates with smaller pixel values, and the other category is the set of pixel values ​​and pixel coordinates with larger pixel values. Step 4: Fit the ellipse using the least squares method; Step 5: Remove points that are far from the ellipse boundary and keep the set of points that are close to the ellipse boundary, i.e. the optimal set of interior points, to complete the least squares ellipse fitting. Step 6: Use the key coefficients of the ellipse equation obtained by fitting with the least squares algorithm to draw the final set of points.

[0006] According to one embodiment of the present invention, the first step includes the following steps: Step 1.1: Use a camera to acquire a grayscale image of the area in the workpiece where the ellipse needs to be precisely located; Step 1.2: Determine the search center, search range, and search box size within the ellipse; Step 1.3: Search outwards from the search center to determine the center position and rotation angle of the search box.

[0007] According to one embodiment of the present invention, the third step includes the following steps: Step 3.1: Evaluate whether the statistical characteristics of the two data categories, the distance between the class centers, and the ratio of the number of classes meet the constraint that the search box spans the edge. If the constraint is met, record the center of the search box as the edge point of the ellipse. If the constraint is not met, update the center position and rotation angle of the search box to prepare for the next search. Step 3.2: Determine if all search paths have been completed. If not all search paths have been completed, return to step 1.3; When all search paths are completed, the random combination of five points selected from all ellipse edge points is checked to see if it is less than the exhaustive threshold. If the random combination of five points selected from all ellipse edge points is less than the exhaustive threshold, a set of five non-collinear points is extracted in sequence, which is the set of data points to be fitted. If the random combination of five points selected from all ellipse edge points is greater than or equal to the exhaustive threshold, a set of five non-collinear data points is randomly selected from all ellipse edge points, which is the set of data points to be fitted. Step 3.3: Determine all combinations of fitted sets.

[0008] According to one embodiment of the present invention, in step 3.1, the geometric center point of the search box that simultaneously satisfies two conditions is denoted as the edge point of the ellipse, wherein the two conditions are: The first condition, and the proportion of the number of data points in each of the two clustered categories to the total number of data points in the search box, are both 49% to 51%. The second condition is that the cluster centers of the two classes are significantly different, that is, the Euclidean distance between the two cluster centers is greater than a certain threshold, which is 0.5 to 1.2 times the distance between the cluster centers of the two pixel values.

[0009] According to one embodiment of the present invention, the fourth step includes the following steps: Step 4.1: Extract a set of valid points for fitting the ellipse to be fitted, and fit the ellipse using the least squares method. Step 4.2: Determine whether the fitted ellipse meets the constraints. If the fitted ellipse does not meet the constraints, the current fitted set combination is updated, the next fitting is prepared, and the process returns to step 4.1. When it is determined that the fitted ellipse meets the constraints, Newton's method is used to iteratively calculate the projection points of each remaining ellipse edge point onto the fitted ellipse. Step 4.3: Calculate the shortest distance (distance from the edge point to its projection point) from each remaining ellipse edge point to the fitted ellipse, and set it as the support error. Determine whether the support error of each remaining ellipse edge point is less than the set threshold. When the support error of each remaining ellipse edge point is determined to be less than the set threshold, the ellipse edge point is added to the support set of the current fitting set. If the support error of each remaining ellipse edge point is greater than or equal to the set threshold, the support set of the current fitted set will not be updated. Step 4.4: Refit the ellipse using least squares based on the current fitted set and its support set.

[0010] According to one embodiment of the present invention, the fifth step includes the following steps: Step 5.1: Calculate the projection points of the current fitted set and its supporting set onto the fitted ellipse; Step 5.2: Calculate the distance from all points in the current fitted set and its supporting set to their projection points, and denot it as the overall error.

[0011] According to one embodiment of the present invention, the sixth step includes the following steps: Step 6.1: Determine whether all combination calculations have been completed or whether the number of iterations has been reached. If it is determined that not all combination calculations have been completed and the number of iterations has not been reached, then return to step 4.2 to update the current fitting set combination and prepare for the next fitting. Once it is determined that all combination calculations have been completed or the number of iterations has been reached, the errors of all fitted sets and their support sets are determined. Step 6.2: The combination containing the minimum error and the largest support set is the optimal fit.

[0012] According to one embodiment of the present invention, the specific steps of the second step are: Let the search center be... Point, number The intersection of the search path and the search space boundary is , , The number of search paths. If the sum of the vertical axis and the integer is a positive integer greater than or equal to 1, then the sum of the vertical axis and the integer is greater than or equal to 1. Parallel, and the geometric center of the search box is along the search path. Move the search box and remember it as... , , For line segments The number of pixels in the upper part, It is a positive integer greater than or equal to 1, retrieve the search box. The grayscale values ​​of all pixels within the range are denoted as: .

[0013] According to one embodiment of the present invention, in the fourth step, the general equation of the ellipse is: (1) The meanings of the symbols in formula (1) are as follows: The set of formal parameters representing the general form of the equation of an ellipse; , , , and The x and y coordinates represent the equation of the ellipse; make , Therefore, the general equation of an ellipse can be written as: (2) The meanings of the symbols in formula (2) are as follows: This indicates that valid coordinate operations are combined into vector form, which facilitates the subsequent formula description in matrix algebra. The least squares fit can then be expressed as: (3) (4) The symbols in formulas (3) and (4) represent the following meanings: for Matrix; The transpose operator for matrices; The parameter matrix representing the conic section; (5) The meanings of the symbols in formula (5) are as follows: Represents the square of the x-coordinate of the set of points to be fitted; This represents the product of the x and y coordinates of the set of points to be fitted. The ordinate of the set of points to be fitted is squared. The x-coordinates of the set of points to be fitted; The ordinate represents the set of points to be fitted; Constraints The constraint condition for the ellipse is, i.e. If it does not satisfy the condition, it may be the equation of a conic section. for The matrix: (6) According to one embodiment of the present invention, the Lagrange function can be constructed to solve the above problem: (7) Setting its partial derivative to 0, we have: (8) If remember Then the original problem can be transformed into solving for eigenvalues. and eigenvectors The problem; but if the matrix After splitting, the complexity of matrix inversion can be reduced and a stable numerical solution can be obtained. Therefore, let: (9) The meanings of the symbols in formula (9) are as follows: The matrix to be orthogonally decomposed. , , express The three elements of the matrix are estimates of the variance in the horizontal and vertical axes; They are respectively Matrix; (10) The meanings of the symbols in formula (10) are as follows: The parameter matrix representing the conic section; (11) The meanings of the symbols in formula (11) are as follows: They are respectively Matrix; We can obtain: (12) Treating the above expression as a linear equation in two variables, we can eliminate... Then we can obtain information about solving for the eigenvalues. and eigenvectors The problem needs to be solved. Then solve using the constraints. Finally, the coefficients of the general equation of an ellipse can be obtained: (13) The beneficial effects of this invention are that it achieves precise positioning of elliptical shapes in industrial images. By finding the edge points of the shape and using the fitted points, the parametric equation of the ellipse is accurately obtained. The high-precision reference points provided can be used for image registration correction and target positioning. The algorithm of this invention has strong robustness to both strong and weak edges. At the same time, it can accurately filter interior points and remove exterior points to obtain a robust, accurate, and precise ellipse equation. This invention has a short running time, high efficiency, high accuracy, strong robustness, good versatility, and scalability, providing great assistance for image detection.

[0014] Other features and advantages of the invention will be set forth in the following description, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention are realized and obtained through the structures particularly pointed out in the description and the drawings.

[0015] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description

[0016] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0017] Figure 1 This is a flowchart of the present invention; Figure 2 This is a schematic diagram of detecting strong edge points; Figure 3 This is a schematic diagram of detecting normal edge points; Figure 4 This is a schematic diagram for detecting weak edge points; Figure 5 This is a schematic diagram illustrating the calculation of geometric distance error based on orthogonal nearest neighbor points; Figure 6 This is the final detection and fitting result of the present invention. Figure 1 ; Figure 7 This is the final detection and fitting result of the present invention. Figure 2 ; Figure 8 This is the final detection and fitting result of the present invention. Figure 3 ; Figure 9 This is the final detection and fitting result of the present invention. Figure 4 ; Figure 10 This is the final detection and fitting result of the present invention. Figure 5 ; Figure 11 This is the final detection and fitting result of the present invention. Figure 6 . Detailed Implementation

[0018] 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, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0019] The contour extraction method based on adaptive elliptical edge detection and fast fitting algorithm of the present invention will be described in detail below with reference to the accompanying drawings.

[0020] See Figure 1 The contour extraction method based on adaptive elliptical edge detection and fast fitting algorithm of the present invention includes the following steps: Step 1: Obtain the image region containing the ellipse, and given the search center, search direction, search box position and size, and search space, determine the entire search path of the ray-shaped search box from the search center to the search space boundary, based on the search direction. Step 1 includes the following steps: Step 1.1: Use a camera to acquire a grayscale image of the area in the workpiece where the ellipse needs to be precisely located; Step 1.2: Determine the search center, search range, and search box size within the ellipse; Step 1.3: Search outwards from the search center to determine the center position and rotation angle of the search box.

[0021] Step 2: Obtain all pixel values ​​within the search box: Obtain the grayscale values ​​of all pixels within the search box; the specific steps of step 2 are: Let the search center be... Point, number The intersection of the search path and the search space boundary is , , The number of search paths. If the sum of the vertical axis and the integer is a positive integer greater than or equal to 1, then the sum of the vertical axis and the integer is greater than or equal to 1. Parallel, and the geometric center of the search box is along the search path. Move the search box and remember it as... , , For line segments The number of pixels in the upper part, It is a positive integer greater than or equal to 1, retrieve the search box. The grayscale values ​​of all pixels within the range are denoted as: .

[0022] Step 3: Use K-Means clustering to cluster the obtained pixel values ​​into two categories: K-Means clustering is used to determine the edge points of the ellipse. K-Means clustering is used to cluster the grayscale values ​​of the pixels within the search box into two categories: one category contains the set of pixel values ​​and pixel coordinates with smaller pixel values, and the other category contains the set of pixel values ​​and pixel coordinates with larger pixel values. Step 3 includes the following steps: Step 3.1: Evaluate whether the statistical characteristics, cluster center distance, and cluster number ratio of the two data types satisfy the constraint that the search box spans the edge. If the constraint is satisfied, record the center of the search box as the edge point of the ellipse. If the constraint is not satisfied, update the center position and rotation angle of the search box to prepare for the next search. In step 3.1, the geometric center point of the search box that simultaneously satisfies two conditions is recorded as the edge point of the ellipse. The two conditions are: the first condition is that the proportion of the number of data points of the two clusters to the total number of data points in the search box is 49% to 51%; the second condition is that the cluster centers of the two types are significantly different, that is, the Euclidean distance between the two cluster centers is greater than a certain threshold, which is 0.5 to 1.2 times the distance between the cluster centers of the two pixel values.

[0023] Step 3.2: Determine if all search paths have been completed. If not all search paths have been completed, return to step 1.3; When all search paths are completed, the random combination of five points selected from all ellipse edge points is checked to see if it is less than the exhaustive threshold. If the random combination of five points selected from all ellipse edge points is less than the exhaustive threshold, a set of five non-collinear points is extracted in sequence, which is the set of data points to be fitted. If the random combination of five points selected from all ellipse edge points is greater than or equal to the exhaustive threshold, a set of five non-collinear data points is randomly selected from all ellipse edge points, which is the set of data points to be fitted. Step 3.3: Determine all combinations of fitted sets.

[0024] The specific steps of step 3 are: [The text abruptly ends here, likely due to an incomplete sentence or a formatting error.] The data points are clustered into two classes using K-Means clustering. The K-Means clustering algorithm selects initial data points belonging to each class, calculates the cluster center of each class, and calculates all data points belonging to the current class based on the current cluster center. This process is repeated until the cluster centers tend to stabilize and converge. In this invention, K-Means clustering is used to determine the edge points of the ellipse. If the search box spans both sides of the edge and its geometric center is above the edge, two points can be determined: 1. The proportion of data points in each of the two clustered classes to the total number of data points in the search box is approximately 50%; 2. The difference between the cluster centers of the two classes is significant, i.e., the Euclidean distance between the two cluster centers is greater than a certain threshold. The geometric center point of the search box that simultaneously satisfies the above two conditions is recorded and denoted as the edge point of the ellipse. express, This method is applicable not only to the extraction of strong edge points but also to the extraction of weak edge points. In contrast, traditional methods that rely on pixel grayscale gradients only perform well in strong edge scenes and cannot be robust in weak edge scenes.

[0025] Step 4: Fit the ellipse using the least squares method; Step 4 includes the following steps: Step 4.1: Extract a set of valid points for fitting the ellipse to be fitted, and fit the ellipse using the least squares method. Step 4.2: Determine whether the fitted ellipse meets the constraints. If the fitted ellipse does not meet the constraints, the current fitted set combination is updated, the next fitting is prepared, and the process returns to step 4.1. When it is determined that the fitted ellipse meets the constraints, Newton's method is used to iteratively calculate the projection points of each remaining ellipse edge point onto the fitted ellipse. Step 4.3: Calculate the shortest distance (distance from the edge point to its projection point) from each remaining ellipse edge point to the fitted ellipse, and set it as the support error. Determine whether the support error of each remaining ellipse edge point is less than the set threshold. When the support error of each remaining ellipse edge point is determined to be less than the set threshold, the ellipse edge point is added to the support set of the current fitting set. If the support error of each remaining ellipse edge point is greater than or equal to the set threshold, the support set of the current fitted set will not be updated. Step 4.4: Refit the ellipse using least squares based on the current fitted set and its support set; The specific steps of step 4 are: a series of noisy data points of the ellipse have been obtained. , Then, based on these points, the equation of the ellipse is fitted. Let the general equation of the ellipse be: (1) The meanings of the symbols in formula (1) are as follows: The set of formal parameters representing the general form of the equation of an ellipse; , , , and The x and y coordinates represent the equation of the ellipse; make , Therefore, the general equation of an ellipse can be written as: (2) The meanings of the symbols in formula (2) are as follows: This indicates that valid coordinate operations are combined into vector form, which facilitates the subsequent formula description in matrix algebra. The least squares fit can then be expressed as: (3) (4) The symbols in formulas (3) and (4) represent the following meanings: for Matrix; The transpose operator for matrices; The parameter matrix representing the conic section; (5) The meanings of the symbols in formula (5) are as follows: Represents the square of the x-coordinate of the set of points to be fitted; This represents the product of the x and y coordinates of the set of points to be fitted. The ordinate of the set of points to be fitted is squared. The x-coordinates of the set of points to be fitted; The ordinate represents the set of points to be fitted; Constraints The constraint condition for the ellipse is, i.e. If it does not satisfy the condition, it may be the equation of a conic section. for The matrix: (6) To solve the above problem, we can construct the Lagrange function: (7) Setting its partial derivative to 0, we have: (8) If remember Then the original problem can be transformed into solving for eigenvalues. and eigenvectors The problem; but if the matrix After splitting, the complexity of matrix inversion can be reduced and a stable numerical solution can be obtained. Therefore, let: (9) The meanings of the symbols in formula (9) are as follows: The matrix to be orthogonally decomposed. , , express The three elements of the matrix are estimates of the variance in the horizontal and vertical axes; They are respectively Matrix; (10) The meanings of the symbols in formula (10) are as follows: The parameter matrix representing the conic section; (11) The meanings of the symbols in formula (11) are as follows: They are respectively Matrix; We can obtain: (12) Treating the above expression as a linear equation in two variables, we can eliminate... Then we can obtain information about solving for the eigenvalues. and eigenvectors The problem needs to be solved. Then solve using the constraints. Finally, the coefficients of the general equation of an ellipse can be obtained: (13) It is worth noting that the data points used need to be normalized before fitting in order to reduce the amount of computation and improve the stability of numerical calculation. The solution results need to be inversely normalized.

[0026] Step 5: Remove points far from the ellipse boundary, leaving only the set of points close to the ellipse boundary, i.e., the optimal set of interior points, to complete the least-squares ellipse fitting. Step 5 uses the optimal set of interior points and support points to perform least-squares fitting, including the following steps: Step 5.1: Calculate the projection points of the current fitted set and its supporting set onto the fitted ellipse; Step 5.2: Calculate the distance from all points in the current fitted set and its supporting set to their projection points, and denot it as the overall error.

[0027] Step 5 involves the following steps: Since outliers exist in the data points, directly using least squares fitting often results in significant errors. Therefore, during the fitting process, both inliers and outliers are considered for selection. The inlier set is iteratively expanded to support the reasonableness of the fitting result. Then, all inliers and support points are used to evaluate the performance of the fitting result. Finally, the optimal set of inliers and support points is used for least squares fitting to increase the accuracy and stability of the fitting result. Specifically, in determining whether a point is an inlier, the algebraic distance error of the general equation of the ellipse is not used as the standard; instead, geometric distance error is used as the indicator. This enhances the robustness of the fitting result and improves its accuracy.

[0028] Geometric distance error can be detected through any point to the orthogonal nearest point on the ellipse Description of straight-line distance, According to geometric theory, the line connecting any point to its orthogonal neighbor on the ellipse is parallel to the normal at that orthogonal neighbor. Therefore, this constraint can be solved iteratively using Newton's method. (Geometric distance error) It can be represented as: (14) It should be noted that, to maintain the simplicity of the formula, subscripts are omitted. ,but and , It is a one-to-one correspondence. Among them, The weight matrix is ​​positive definite; the default value is the identity matrix. For ease of calculation, the general equation of the known ellipse is transformed into a parametric equation. , respectively representing the geometric centers of the ellipse coordinates and Coordinates, major and minor semi-axes, and the rotation angle of the ellipse. Introducing the rotation angle around the center of the ellipse. Rotation Coordinate system after angle Then the coordinates after rotation can be obtained as follows: (15) Therefore, the parametric equation of the rotated ellipse can be written as: (16) From any point after rotation and its orthogonal neighboring points If the connecting lines are parallel to the normals at orthogonal neighboring points, then we can obtain... Thus we get: (17) Using Newton's method, we can obtain: (18) Wherein, the partial derivative is: (19) Generally, the number of iterations for Newton's method here can be set to 10, and the initial value can be directly used from the sample point itself. While using geometric distance error as the criterion for determining interior points, it also provides other known priors as conditions for selecting targets. For example, if the prior knowledge is that the fitted figure is a standard circle, then constraints are imposed on the major and minor semi-axes, i.e. Therefore, this invention takes into account versatility and has excellent scalability.

[0029] Step 6: Obtain the fitting results of the set of all interior points after expanding the support points; Step 6, obtaining the fitting results of the set of all interior points after expanding the support points, includes the following steps: Step 6.1: Determine whether all combination calculations have been completed or whether the number of iterations has been reached. If it is determined that not all combination calculations have been completed and the number of iterations has not been reached, then return to step 4.2 to update the current fitting set combination and prepare for the next fitting. Once it is determined that all combination calculations have been completed or the number of iterations has been reached, the errors of all fitted sets and their support sets are determined. Step 6.2: The combination containing the minimum error and the largest support set is the optimal fit; The specific steps of step 6 are as follows: Obtain the fitting results of all interior point sets after expanding the support points. First, calculate the number of interior points in each interior point set and the geometric distance error of its respective least squares fitting. Select the interior point set with the largest number of interior points among all interior point sets. If the number of interior points is equal, select the interior point set with the smaller geometric distance error as the optimal interior point set. Finally, obtain the best fitting result from the optimal interior point set.

[0030] See Figure 2 This is a schematic diagram of strong edge point detection. The red dots in the diagram are edge points extracted using the algorithm of this invention.

[0031] See Figure 3This is a schematic diagram of normal edge point detection. The red dots in the diagram are edge points extracted using the algorithm of this invention.

[0032] See Figure 4 This is a schematic diagram of weak edge point detection. The red dots in the diagram are edge points extracted using the algorithm of this invention.

[0033] See Figure 5 This diagram illustrates the calculation of geometric distance error based on orthogonal nearest neighbors. The solid red dots represent the found edge points, the purple ellipse is a fitted ellipse, and the hollow green dots are the orthogonal nearest neighbors of the corresponding solid red dots. The green line represents the correspondence. The geometric distance error between point pairs is the straight-line distance between them, which is the length of the green line. Filtering based on geometric distance error accurately identifies interior points and eliminates interference from exterior points, resulting in more accurate fitting results.

[0034] The contour extraction method based on adaptive elliptical edge detection and fast fitting algorithm of this invention uses K-Means clustering to cluster the gray values ​​of local regions, accurately detecting edge points through statistical physical meaning. It uses region features instead of gradient features of individual pixels, and is well applicable to both sharp and clear strong edges and blurred and gradually fading weak edges, conforming to human visual perception and exhibiting strong robustness in detection. When using least squares fitting, it continuously expands the set of interior points by trying to filter interior and exterior points to improve and support the accuracy of the fitting results, eliminates interference points in the data points, and filters interior points by geometric distance error with orthogonal nearest neighbors, which is more accurate than directly using the algebraic distance error of parametric equations. It also provides extended support for filtering interior points based on priors, sets feasible regions, and improves fitting efficiency and accuracy.

[0035] See Figure 6 , Figure 7 , Figure 8 , Figure 9 , Figure 10 and Figure 11 Red indicates the points to be fitted; the yellow curve represents the resulting elliptical curve fitted using the set of red points; green indicates the center of the ellipse's equation. The fitting result is judged by whether the boundary between the gray and white areas coincides with the drawn yellow line; the greater the overlap, the better the fit. See... Figure 10 The fitting results are relatively good. See Figure 11 The fitting results have a certain degree of robustness, and the proposed algorithm performs relatively well.

[0036] The above are merely preferred embodiments of the present invention, but the scope of protection of the present invention is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in the present invention, based on the technical solution and inventive concept of the present invention, should be covered within the scope of protection of the present invention.

Claims

1. A contour extraction method based on adaptive elliptical edge detection and a fast fitting algorithm, characterized in that, Includes the following steps: Step 1: Obtain the image region where the ellipse is located, and give the search center, search direction, search box position and size, and search space. Within the search space, starting from the search center to the boundary of the search space, determine the entire search path of the ray-shaped search box according to the search direction. Step 2: Obtain all pixel values ​​within the search box: Obtain the grayscale values ​​of all pixels within the search box; Step 3: Use K-Means clustering to cluster the obtained pixel values ​​into two categories: K-Means clustering is used to determine the edge points of the ellipse. K-Means clustering is used to cluster the gray values ​​of the pixels in the search box into two categories: one category is the set of pixel values ​​and pixel coordinates with smaller pixel values, and the other category is the set of pixel values ​​and pixel coordinates with larger pixel values. The third step includes the following steps: Step 3.1: Evaluate whether the statistical characteristics of the two data categories, the distance between the class centers, and the ratio of the number of classes meet the constraint that the search box spans the edge. If the constraint is met, record the center of the search box as the edge point of the ellipse. If the constraint is not met, update the center position and rotation angle of the search box to prepare for the next search. The geometric center point of the search box that simultaneously satisfies two conditions is denoted as the edge point of the ellipse. These two conditions are: The first condition, and the proportion of the number of data points in each of the two clustered categories to the total number of data points in the search box, are both 49% to 51%. The second condition is that the cluster centers of the two classes are significantly different, that is, the Euclidean distance between the two cluster centers is greater than a certain threshold, which is 0.5 to 1.2 times the distance between the cluster centers of the two pixel values. Step 3.2: Determine if all search paths have been completed. If not all search paths are completed, search outwards from the search center to determine the center position and rotation angle of the search box; When all search paths are completed, the random combination of five points selected from all ellipse edge points is checked to see if it is less than the exhaustive threshold. If the random combination of five points selected from all ellipse edge points is less than the exhaustive threshold, a set of five non-collinear points is extracted in sequence, which is the set of data points to be fitted. If the random combination of five points selected from all ellipse edge points is greater than or equal to the exhaustive threshold, a set of five non-collinear data points is randomly selected from all ellipse edge points, which is the set of data points to be fitted. Step 3.3: Determine all combinations of fitted sets; Step 4: Fit the ellipse using the least squares method; Step 4 includes the following steps: Step 4.1: Extract a set of valid points for fitting the ellipse to be fitted, and fit the ellipse using the least squares method. Step 4.2: Determine whether the fitted ellipse meets the constraints. If the fitted ellipse does not meet the constraints, the current fitted set combination is updated, the next fitting is prepared, and the process returns to step 4.

1. When it is determined that the fitted ellipse meets the constraints, Newton's method is used to iteratively calculate the projection points of each remaining ellipse edge point onto the fitted ellipse. Step 4.3: Calculate the shortest distance from each remaining ellipse edge point to the fitted ellipse, and set it as the support error. Determine whether the support error of each remaining ellipse edge point is less than a set threshold. When the support error of each remaining ellipse edge point is determined to be less than the set threshold, the ellipse edge point is added to the support set of the current fitting set. If the support error of each remaining ellipse edge point is greater than or equal to the set threshold, the support set of the current fitted set will not be updated. Step 4.4: Refit the ellipse using least squares based on the current fitted set and its support set; Step 5: Remove points that are far from the ellipse boundary and keep the set of points that are close to the ellipse boundary, i.e. the optimal set of interior points, to complete the least squares ellipse fitting. Step 6: Use the key coefficients of the ellipse equation obtained by fitting with the least squares algorithm to draw the final set of points.

2. The contour extraction method based on adaptive elliptical edge detection and fast fitting algorithm according to claim 1, characterized in that, The first step includes the following steps: Step 1.1: Use a camera to acquire a grayscale image of the area in the workpiece where the ellipse needs to be precisely located; Step 1.2: Determine the search center, search range, and search box size within the ellipse; Step 1.3: Search outwards from the search center to determine the center position and rotation angle of the search box.

3. The contour extraction method based on adaptive elliptical edge detection and fast fitting algorithm according to claim 1, characterized in that, Step 5 includes the following steps: Step 5.1: Calculate the projection points of the current fitted set and its supporting set onto the fitted ellipse; Step 5.2: Calculate the distance from all points in the current fitted set and its supporting set to their projection points, and denot it as the overall error.

4. The contour extraction method based on adaptive elliptical edge detection and fast fitting algorithm according to claim 3, characterized in that, Step 6 includes the following steps: Step 6.1: Determine whether all combination calculations have been completed or whether the number of iterations has been reached. If it is determined that not all combination calculations have been completed and the number of iterations has not been reached, then return to step 4.2 to update the current fitting set combination and prepare for the next fitting. Once it is determined that all combination calculations have been completed or the number of iterations has been reached, the errors of all fitted sets and their support sets are determined. Step 6.2: The combination containing the minimum error and the largest support set is the optimal fit.

5. The contour extraction method based on adaptive elliptical edge detection and fast fitting algorithm according to claim 1, characterized in that, The specific steps of step 2 are as follows: Let the search center be... Point, number The intersection of the search path and the search space boundary is , , The number of search paths. If the sum of the vertical axis and the integer is a positive integer greater than or equal to 1, then the sum of the vertical axis and the integer is greater than or equal to 1. Parallel, and the geometric center of the search box is along the search path. Move the search box and remember it as... , , For line segments The number of pixels in the upper part, It is a positive integer greater than or equal to 1, retrieve the search box. The grayscale values ​​of all pixels within the range are denoted as: .

6. The contour extraction method based on adaptive elliptical edge detection and fast fitting algorithm according to claim 5, characterized in that, In step 4, the general equation of the ellipse is: (1) The meanings of the symbols in formula (1) are as follows: The set of formal parameters representing the general form of the equation of an ellipse; and The x and y coordinates represent the equation of the ellipse; make , Therefore, the general equation of an ellipse can be written as: (2) The meanings of the symbols in formula (2) are as follows: This indicates that valid coordinate operations are combined into vector form, which facilitates the subsequent formula description in matrix algebra. The least squares fit can then be expressed as: (3) (4) The symbols in formulas (3) and (4) represent the following meanings: for Matrix; The transpose operator for matrices; The parameter matrix representing the conic section; (5) The meanings of the symbols in formula (5) are as follows: Represents the square of the x-coordinate of the set of points to be fitted; This represents the product of the x and y coordinates of the set of points to be fitted. The ordinate of the set of points to be fitted is squared. The x-coordinates of the set of points to be fitted; The ordinate represents the set of points to be fitted; Constraints The constraint condition for the ellipse is: If it does not satisfy the condition, it may be the equation of a conic section. for The matrix: (6)。 7. The contour extraction method based on adaptive elliptical edge detection and fast fitting algorithm according to claim 6, characterized in that: To solve the above problem, we can construct the Lagrange function: (7) Setting its partial derivative to 0, we have: (8) If remember Then the original problem can be transformed into solving for eigenvalues. and eigenvectors The problem; but if the matrix After splitting, the complexity of matrix inversion can be reduced and a stable numerical solution can be obtained. Therefore, let: (9) The meanings of the symbols in formula (9) are as follows: The matrix to be orthogonally decomposed. , , express The three elements of the matrix are estimates of the variance in the horizontal and vertical axes; They are respectively Matrix; (10) The meanings of the symbols in formula (10) are as follows: The parameter matrix representing the conic section; (11) The meanings of the symbols in formula (11) are as follows: They are respectively Matrix; We can obtain: (12) Treating the above expression as a linear equation in two variables, we can eliminate... Then we can obtain information about solving for the eigenvalues. and eigenvectors The problem needs to be solved. Then solve using the constraints. Finally, the coefficients of the general equation of an ellipse can be obtained: (13)。

Citation Information

Patent Citations

  • Vehicle-mounted screen structural member ellipse feature detection method and device, and medium

    CN118212205A

  • Estimating interval anisotropy parameter for pre-stack depth migration using a least-sqares method

    US20190235113A1