A shape prior constraint improved chan-vese model method for measuring inner diameter of a guide rod

CN123015371APending Publication Date: 2026-10-30ZHONGBEI UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610939045.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-06-26
Publication Date
2026-10-30

AI Technical Summary

Technical Problem

传统Chan-Vese模型假设分段恒定灰度,在光照不均匀条件下性能较差,且对初始轮廓放置高度敏感,不同初始化可能导致截然不同的分割结果;同时,水平集函数需要周期性重新初始化,计算成本高昂

Benefits of technology

[0054]1.本发明通过边缘梯度模板匹配结合贪心提前终止和金字塔搜索策略,实现导向杆的快速鲁棒粗定位,对光照变化、表面划痕和金属反射具有强抗干扰能力;自适应卡尺方法利用粗定位边缘信息引导,自动生成均匀分布的锚点并提取亚像素边缘点,消除了传统卡尺方法需要反复手动选择区域的低效问题,为主动轮廓模型提供高质量的初始轮廓。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123015371A_ABST
    Figure CN123015371A_ABST
Patent Text Reader

Abstract

The application discloses a shape prior constraint improved Chan-Vese model method for measuring the inner diameter of a guide rod, and belongs to the technical field of machine vision measurement. The method performs fast coarse positioning through edge gradient template matching to obtain a preliminary positioning area of the inner diameter of the guide rod, uses edge information of the preliminary positioning area to guide adaptive caliper extraction of sub-pixel edge points, and eliminates manual parameter tuning; the sub-pixel edge points are used as geometric shape prior to initialize and constrain a hybrid driven Chan-Vese model, the hybrid driven Chan-Vese model integrates GAC edge guidance and weak anchor point constraint to suppress over-segmentation of a high reflection area and reliably capture a weak edge to obtain a high-precision segmentation contour; a two-stage robust circle fitting method combining RANSAC coarse outlier removal and dynamic weighted least square optimization is used on the segmentation contour to compensate for fitting deviation caused by non-uniform point distribution to obtain accurate measurement parameters of the inner diameter of the guide rod. The application significantly improves the precision and robustness of the inner diameter measurement of the guide rod under the conditions of strong metal reflection and uneven gray scale, and the average absolute error is 91.8 microns, which meets the precision requirements of online detection of the automobile guide rod.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of machine vision measurement technology, and in particular to an improved Chan-Vese model method for measuring the inner diameter of a guide rod using shape prior constraints. Background Technology

[0002] The inner diameter accuracy of automotive guide rods directly determines assembly clearance and motion stability, making it a key parameter affecting product quality. Existing technologies, such as traditional contact measurement methods like manual gauges or coordinate measuring machines, suffer from low efficiency and poor adaptability, making them unsuitable for online inspection. Non-contact vision measurement methods offer advantages such as speed, flexibility, and ease of automation, but they face two major challenges in industrial environments: first, unreliable low-gradient, weak edge segmentation due to strong metallic reflection and uneven grayscale; and second, severe system fitting bias caused by non-uniform edge point distribution.

[0003] Existing technologies for active contour models in industrial inner diameter detection have significant shortcomings. The traditional Chan-Vese model assumes piecewise constant gray levels, performs poorly under uneven illumination conditions, and is highly sensitive to the initial contour placement; different initializations can lead to drastically different segmentation results. Furthermore, the level set function requires periodic re-initialization, resulting in high computational costs. While existing improved models have made progress in adapting to uneven gray levels, initialization robustness, and noise suppression, they still cannot simultaneously resolve the contradiction between capturing weak edges under strong reflections and avoiding over-segmentation of non-target regions.

[0004] In the circle fitting stage, the traditional least squares method is highly sensitive to non-uniformly distributed edge points. The contour extracted under non-uniform lighting inevitably exhibits high-frequency jagged features and non-uniform point distribution, leading to unacceptable fitting bias. These errors propagate to the circle fitting stage, introducing system parameter deviations, distorting the inner diameter measurement results, and rendering the roundness assessment ineffective. Summary of the Invention

[0005] This invention provides an improved Chan-Vese model method for measuring the inner diameter of a guide rod using shape prior constraints to solve the problems mentioned in the background art.

[0006] To achieve the above objectives, this invention provides an improved Chan-Vese model method for measuring the inner diameter of a guide rod using shape prior constraints, comprising:

[0007] S1. Obtain the original image of the guide rod, and perform rapid coarse positioning through edge gradient template matching to obtain the preliminary positioning area of ​​the guide rod's inner diameter;

[0008] S2. Based on the edge information of the initially located area, guide the adaptive caliper to extract the sub-pixel edge point set, which serves as the geometric shape prior;

[0009] S3. Initialize and constrain the hybrid-driven Chan-Vese model with the sub-pixel edge point set. The hybrid-driven Chan-Vese model integrates the CV global region term, GAC edge guidance term, and weak anchor point constraint term to perform high-precision edge optimization segmentation.

[0010] S4. The segmented contour point set is fitted with a two-stage robust circle fitting. First, RANSAC is used to coarsely remove outliers to obtain the initial circle parameters. Then, dynamic weighted least squares optimization is used to compensate for the fitting deviation of the non-uniform point distribution, and finally the accurate measurement parameters of the guide rod inner diameter are obtained.

[0011] In a preferred embodiment, acquiring the original image of the guide rod and performing rapid coarse positioning through edge gradient template matching to obtain a preliminary positioning area for the inner diameter of the guide rod includes:

[0012] Perform Canny edge detection on the original image to extract edge contours and calculate pixel gradient magnitude and direction;

[0013] Construct a similarity metric based on the dot product of gradient vectors, and calculate the degree of alignment of the gradient directions of corresponding edge points between the template and the candidate sub-image;

[0014] A greedy early termination strategy and a multi-resolution pyramid search strategy are adopted, combined with SIMD parallel acceleration, to quickly locate the position and attitude of the guide rod.

[0015] In a preferred embodiment, the step of employing a greedy early termination strategy and a multi-resolution pyramid search strategy, combined with SIMD parallel acceleration, to quickly locate the position and attitude of the guide rod includes:

[0016] The cumulative similarity is dynamically monitored, and the evaluation of the current candidate is terminated in advance when the maximum possible contribution of the remaining points cannot make the total score reach the preset threshold.

[0017] Construct an image pyramid, perform fast coarse search in the low-resolution layer, and perform fine localization in the high-resolution layer;

[0018] It employs multi-threaded parallel matching and SIMD vector operations to process multiple pixels and vectors simultaneously, thus accelerating the matching process.

[0019] In a preferred embodiment, the step of guiding the adaptive caliper to extract sub-pixel edge point sets based on the edge information of the initially located region includes:

[0020] Generate evenly distributed anchor points along the initially positioned inner diameter contour.

[0021] At each anchor point, a rectangular caliper region is constructed along the local gradient direction, wherein the caliper direction is perpendicular to the edge tangent.

[0022] Gray-scale projection analysis is performed within each caliper region, and the optimal sub-pixel edge points are extracted through Gaussian smoothing, first derivative calculation, and non-maximum suppression.

[0023] In a preferred embodiment, generating uniformly distributed anchor points along the initially positioned inner diameter profile includes:

[0024] Extract the highest and lowest points of the preliminary positioning contour, and use the line connecting the two points as a reference baseline;

[0025] Rotate the baseline at fixed angular intervals with the midpoint of the baseline as the center of rotation, and the intersection with the contour is the anchor point;

[0026] Linear interpolation is performed on missing anchor points to ensure uniform distribution along the circumference.

[0027] In a preferred embodiment, the step of initializing and constraining the hybrid-driven Chan-Vese model with the sub-pixel edge point set to perform high-precision edge optimization segmentation includes:

[0028] Connect the sub-pixel edge point sets into a closed polygon to generate a signed distance field as the initial value of the level set function;

[0029] Construct a hybrid energy function, which includes a CV region fidelity term, a GAC ​​edge guidance term, and a weak anchor point constraint term;

[0030] A distance regularization term is introduced to eliminate the repeated reinitialization of the level set function;

[0031] The level set function is iteratively evolved using the gradient descent method until convergence is obtained to obtain an accurate segmentation contour.

[0032] In a preferred embodiment, the construction of the hybrid energy function, comprising a CV region fidelity term, a GAC ​​edge guidance term, and a weak anchor point constraint term, includes:

[0033] The hybrid energy function is composed of the CV region fidelity energy, GAC edge guiding energy and weak anchor point constraint energy weighted and summed according to preset weight coefficients;

[0034] The weak anchor constraint is activated only in the first 30 iterations to guide the initial convergence direction, and is removed in subsequent iterations to allow unconstrained optimization.

[0035] In a preferred embodiment, the GAC edge guidance term is implemented through an edge stopping function, including:

[0036] The edge stopping function takes the gradient magnitude of the smoothed image as input; the larger the gradient magnitude, the smaller the function value.

[0037] The gradient magnitude is large at the edge of the target, and the edge stopping function value approaches zero, so that the contour stops precisely at the true boundary.

[0038] In a preferred embodiment, the two-stage robust circle fitting of the segmented contour point set includes:

[0039] Phase 1: Randomly sample three non-collinear points to construct candidate circle models, calculate the geometric distance residuals from all points to the candidate circles, count the number of interior points, select the model with the most interior points, and perform least squares fitting on the set of interior points to obtain the coarse circle parameters.

[0040] The second stage: Based on the coarse circle parameters, the Gauss-Newton method is used for weighted least squares iterative optimization. The weights are dynamically adjusted according to the distribution density of the points and the residuals until convergence is obtained to obtain the accurate circle parameters.

[0041] In a preferred embodiment, the step of using the Gauss-Newton method for weighted least squares iterative optimization, with the weights dynamically adjusted based on the point distribution density and residuals, includes:

[0042] The weighted least squares optimization is based on the geometric distance residuals from each edge point to the fitted circle, and the objective function is constructed by summing the weights according to the corresponding weights.

[0043] The weights are dynamically adjusted as the iteration progresses: in the early iterations, density-adaptive weights are used to suppress the excessive influence of local dense points, and in the later iterations, residual-adaptive weights are used to further suppress residual outliers.

[0044] In a preferred embodiment, the weights are dynamically adjusted as the iteration process progresses, including:

[0045] In the early convergence phase, density compensation weight based on angle binning is adopted. The entire circumference is divided into 72 angle intervals. The density compensation weight is calculated based on the number of points in each interval and normalized to a preset value interval.

[0046] In the later refinement stage, Huber robust weights and density compensation weights are introduced and fused together. The fusion coefficient transitions linearly from zero to one. The Huber weights adaptively determine the threshold based on the median absolute deviation of the current residuals to suppress the influence of residual outliers.

[0047] Set a lower limit for the combined weights to prevent numerical instability in the Gauss-Newton iteration.

[0048] To address the aforementioned problems, this invention also provides an improved Chan-Vese model system for measuring the inner diameter of a guide rod based on shape prior constraints. The system includes:

[0049] The image acquisition and coarse positioning module is used to acquire the original image of the guide rod and perform rapid coarse positioning through edge gradient template matching to obtain the preliminary positioning area of ​​the inner diameter of the guide rod.

[0050] An adaptive caliper edge extraction module is used to guide the adaptive caliper to extract a set of sub-pixel edge points based on the edge information of the initially located area. The set of sub-pixel edge points serves as a geometric prior.

[0051] The hybrid-driven active contour segmentation module is used to initialize and constrain the hybrid-driven Chan-Vese model with the sub-pixel edge point set. The hybrid-driven Chan-Vese model integrates the CV global region term, the GAC edge guidance term, and the weak anchor point constraint term to perform high-precision edge optimization segmentation.

[0052] The two-stage robust circle fitting module is used to perform two-stage robust circle fitting on the segmented contour point set. First, RANSAC is used to coarsely remove outliers to obtain initial circle parameters. Then, dynamic weighted least squares optimization is used to compensate for the fitting deviation of non-uniform point distribution, and finally the accurate measurement parameters of the guide rod inner diameter are obtained.

[0053] Compared with the prior art, the present invention has the following beneficial effects:

[0054] 1. This invention achieves fast and robust coarse positioning of guide rods by combining edge gradient template matching with greedy early termination and pyramid search strategies, and has strong anti-interference ability against illumination changes, surface scratches and metal reflections; the adaptive caliper method uses coarse positioning edge information to guide the automatic generation of uniformly distributed anchor points and extraction of sub-pixel edge points, eliminating the inefficiency of the traditional caliper method that requires repeated manual selection of regions, and providing high-quality initial contours for active contour models.

[0055] 2. The hybrid-driven improved Chan-Vese model proposed in this invention innovatively uses high-precision edge points extracted by calipers as shape priors to construct weak anchor point constraints to guide initial convergence. It also integrates global region fidelity (CV) and edge guidance (GAC), which not only solves the problem of sensitivity to initialization in traditional CV models, but also reliably captures weak edges in areas with strong metal reflections, effectively suppressing oversegmentation. The distance regularization term eliminates repeated initialization of level sets, greatly improving computational efficiency, and can maintain accurate segmentation even in scenarios with missing edges and artifact interference.

[0056] 3. The two-stage robust circle fitting method of this invention effectively removes outliers in the sawtooth segmentation results through RANSAC coarse estimation, obtaining reliable initial circle parameters. Subsequent dynamic weighted least squares optimization adaptively adjusts the weights based on the point distribution density and residuals, fundamentally compensating for the fitting bias caused by non-uniform point distribution. The final radius error is only 0.2%, more than an order of magnitude lower than that of traditional equal-weighted least squares fitting. Using a coordinate measuring machine as a reference, the method of this invention achieves an average absolute error of 91.8 μm and a relative error of 0.38% for the inner diameter, fully meeting the accuracy requirements for online inspection of automotive guide rods. Attached Figure Description

[0057] Figure 1 A flowchart illustrating an improved Chan-Vese model method for measuring the inner diameter of a guide rod based on shape prior constraints, provided in an embodiment of the present invention.

[0058] Figure 2 A schematic diagram of the algorithm for an improved Chan-Vese model method for measuring the inner diameter of a guide rod based on shape prior constraints, provided in an embodiment of the present invention;

[0059] Figure 3 This is a schematic diagram of the adaptive caliper edge detection principle of the present invention;

[0060] Figure 4 This is a schematic diagram of the level set function and zero level set of the present invention;

[0061] Figure 5 The improved CV model of this invention is based on the evolution diagram of caliper points on the inner diameter division;

[0062] Figure 6 This is a diagram showing the measurement results of the inner diameter of the two-stage robust circle fitting according to an embodiment of the present invention. The green line represents the edge extracted by the active contour, and the magenta line represents the circular contour of the two-stage robust circle fitting. This diagram is used to show the comparison of the fitting effect of the circular target contour and to visually verify the detection accuracy of the circle contour fitting algorithm. The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0063] It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.

[0064] This application provides an improved Chan-Vese model method for shape prior constraints in measuring the inner diameter of a guide rod. The executing entity of this improved Chan-Vese model method for measuring the inner diameter of a guide rod includes, but is not limited to, at least one of the following electronic devices that can be configured to execute the method provided in this application: a server, a terminal, etc. In other words, the improved Chan-Vese model method for measuring the inner diameter of a guide rod can be executed by software or hardware installed on a terminal device or a server device. The server includes, but is not limited to, a single server, a server cluster, a cloud server, or a cloud server cluster. The server can be an independent server or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms.

[0065] Reference Figure 1 and Figure 2 The diagram shown is a flowchart illustrating an improved Chan-Vese model method for measuring the inner diameter of a guide rod according to the present invention, which uses shape prior constraints.

[0066] In this embodiment, the improved Chan-Vese model method for measuring the inner diameter of a guide rod using shape prior constraints includes:

[0067] S1. Obtain the original image of the guide rod, and perform rapid coarse positioning through edge gradient template matching to obtain the preliminary positioning area of ​​the guide rod's inner diameter.

[0068] In this embodiment of the invention, the step of acquiring the original image of the guide rod and performing rapid coarse positioning through edge gradient template matching to obtain the preliminary positioning area of ​​the guide rod's inner diameter includes:

[0069] Perform Canny edge detection on the original image to extract edge contours and calculate pixel gradient magnitude and direction;

[0070] Construct a similarity metric based on the dot product of gradient vectors, and calculate the degree of alignment of the gradient directions of corresponding edge points between the template and the candidate sub-image;

[0071] A greedy early termination strategy and a multi-resolution pyramid search strategy are adopted, combined with SIMD parallel acceleration, to quickly locate the position and attitude of the guide rod.

[0072] The method employs a greedy early termination strategy and a multi-resolution pyramid search strategy, combined with SIMD parallel acceleration, to quickly locate the position and attitude of the guide rod, including:

[0073] The cumulative similarity is dynamically monitored, and the evaluation of the current candidate is terminated in advance when the maximum possible contribution of the remaining points cannot make the total score reach the preset threshold.

[0074] Construct an image pyramid, perform fast coarse search in the low-resolution layer, and perform fine localization in the high-resolution layer;

[0075] It employs multi-threaded parallel matching and SIMD vector operations to process multiple pixels and vectors simultaneously, thus accelerating the matching process.

[0076] Specifically, the edge contours are first extracted using the Canny operator, and the pixel gradient magnitude and direction are calculated. Optimized non-maximum suppression is employed, retaining only pixels with gradient magnitudes greater than all eight neighbors, reducing computational cost compared to standard Canny. The retained edge pixels and their gradient information form a template. During template matching, the template image is compared with each candidate sub-image extracted from the search image, with the template and candidate sub-images maintaining the same size. For each pixel location in the template, the horizontal and vertical gradient vectors are pre-calculated and stored. Correspondingly, the gradient vectors at the corresponding locations in the candidate sub-images are also calculated synchronously. To improve computational efficiency and robustness, only edge pixels with large gradient magnitudes are retained to form the template edge point set. For each edge point, a similarity metric is calculated between the gradient vectors of the template and the corresponding candidate sub-images to measure the alignment of edge directions.

[0077] Furthermore, template matching requires calculating point-by-point similarity scores between the template and each local region of the target image, which is computationally expensive for large images or a large number of candidates. Therefore, a greedy early termination strategy is introduced: the cumulative similarity is dynamically monitored, and the evaluation of the candidate is stopped when it is impossible to reach the required minimum score. The similarity metric ranges from 0 to 1, where a value of 1 represents a perfect match and a value of 0 represents no similarity. When the cumulative similarity remains far below the preset minimum threshold after a certain number of points, further calculation is unlikely to raise the total score above that threshold. Therefore, the evaluation can be stopped after reaching a certain number of points to avoid unnecessary work.

[0078] Furthermore, performing template matching directly on high-resolution images is computationally too demanding for real-time applications. Therefore, an image pyramid strategy is adopted to balance efficiency and accuracy, constructing a pyramid of the original image through iterative Gaussian smoothing and downsampling. Edge gradient features of templates at multiple rotation angles are pre-computed and stored at low resolution. Multi-scale, multi-angle search is accelerated through multi-threaded parallel matching, and the final target position, scale, and rotation are determined by comparing the maximum similarity scores across all threads. SIMD parallelism is further utilized to accelerate preprocessing convolution and dot product operations in the matching stage by processing multiple pixels or vectors simultaneously.

[0079] In summary, by combining Canny edge detection with optimized nonmaximum suppression to extract edge gradient information, we can reduce computational cost while preserving key edge features, providing an efficient and reliable feature foundation for subsequent template matching.

[0080] In summary, the similarity metric based on gradient vector dot product evaluates the matching degree by measuring the alignment of edge directions. Compared with traditional grayscale matching, it has stronger illumination robustness and can effectively adapt to changes in illumination in industrial environments.

[0081] In summary, the greedy early termination strategy can quickly eliminate mismatched candidates, significantly reduce invalid computations, and significantly improve the overall efficiency of template matching, avoiding the need to perform complete point-by-point computation for each candidate.

[0082] In summary, the image pyramid strategy achieves multi-scale search from coarse to fine, quickly narrowing the search range at low-resolution layers and accurately locating at high-resolution layers, thus balancing matching speed and positioning accuracy.

[0083] In summary, multi-threaded parallelism and SIMD vector operations further accelerate the matching process at the hardware level. By processing multiple pixels and vectors simultaneously, computing resources are fully utilized, enabling edge gradient template matching to meet the real-time requirements of industrial online inspection.

[0084] S2. Based on the edge information of the initially located area, an adaptive caliper is used to extract a set of sub-pixel edge points, which serves as a priori geometric shape.

[0085] Reference Figure 3 The diagram shown is a schematic of the adaptive caliper edge detection principle of the present invention.

[0086] In this embodiment of the invention, the step of guiding the adaptive caliper to extract sub-pixel edge point sets based on the edge information of the preliminary positioning area includes:

[0087] Generate evenly distributed anchor points along the initially positioned inner diameter contour.

[0088] At each anchor point, a rectangular caliper region is constructed along the local gradient direction, with the caliper direction perpendicular to the edge tangent.

[0089] Gray-scale projection analysis is performed within each caliper region, and the optimal sub-pixel edge points are extracted through Gaussian smoothing, first derivative calculation, and non-maximum suppression.

[0090] The process of generating uniformly distributed anchor points along the initially positioned inner diameter contour includes:

[0091] Extract the highest and lowest points of the preliminary positioning contour, and use the line connecting the two points as a reference baseline;

[0092] Rotate the baseline at fixed angular intervals with the midpoint of the baseline as the center of rotation, and the intersection with the contour is the anchor point;

[0093] Linear interpolation is performed on missing anchor points to ensure uniform distribution along the circumference.

[0094] Specifically, the caliper tool is a standard method for subpixel edge extraction, capable of local detection without traversing the entire contour, quickly extracting effective edge points from coarse localization results for subsequent high-precision fitting. However, traditional implementations require repeated manual selection of regions for each measurement parameter, leading to inefficiency. To address this issue, edge line information obtained from template matching is reused to determine anchor points, constructing a rectangular caliper aligned with the local gradient direction. Then, optimal edge points are extracted through grayscale analysis, reducing invalid searches and redundant computations.

[0095] Furthermore, the caliper method requires an initial estimate of the edge positions. Instead of traversing every contour pixel, it detects reliable edge points and obtains a high-precision contour through edge fitting. Anchor points with uniform spacing are generated along the inner diameter contour obtained by matching the shape template. At each anchor point, a rectangular caliper is aligned along the local gradient direction, i.e., perpendicular to the inner diameter edge, orthogonally covering the target edge region. Each caliper extracts a local image patch where the inner diameter edge exhibits a clear transition between light and dark gray levels. Edge detection is limited to these local regions, eliminating redundant global computation.

[0096] Furthermore, within each caliper region, grayscale values ​​are sampled only from the sub-block containing the target pixel. The gradient magnitude and direction of each sampled pixel are calculated to locate gradient discontinuities. Then, projection analysis is performed, and abrupt changes in the projected waveform are verified and the edge positions are refined. By combining gradient and projection information, optimal edge points with sub-pixel accuracy are obtained. Each rectangular caliper generates an optimal edge point, and all obtained edge points are connected to form the final target edge.

[0097] Specifically, to generate uniformly distributed anchor points along the reference circle, the highest and lowest points of the contour are first extracted. The line connecting these two points is defined as the reference baseline. The initial direction of this baseline serves as the starting reference for rotation. For a predetermined number of anchor points covering the entire circumference, the circumference is evenly divided at fixed angular intervals, generating multiple uniformly distributed directions. Each rotation line intersects the reference contour to generate an anchor point, ensuring uniform distribution along the circumference.

[0098] Furthermore, the midpoint connecting the highest and lowest points is used as the rotation center. The reference baseline is rotated around this center by a preset angle to generate a rotation line. For each rotation line, the intersection point with the reference profile is calculated. If multiple intersection points are detected, the point with the highest gradient magnitude is retained as the valid anchor point. If no intersection point is found, the missing anchor point is linearly interpolated from its adjacent anchor points. This results in a uniformly distributed set of anchor points. Each caliper is oriented along the local gradient direction at its anchor point, perpendicular to the edge tangent.

[0099] In summary, the adaptive caliper method utilizes coarse positioning edge information to guide the automatic generation of uniformly distributed anchor points and the construction of local detection regions. This eliminates the inefficiency of the traditional caliper method, which requires repeated manual selection of regions, and significantly improves the automation and efficiency of edge extraction.

[0100] In summary, generating uniformly distributed anchor points along the inner diameter contour ensures that the caliper samples evenly across the entire circumference, avoiding oversampling or undersampling in local areas, and providing a balanced and reliable initial position for subsequent sub-pixel edge extraction.

[0101] In summary, by extracting sub-pixel edge points through grayscale projection analysis combined with gradient information within each caliper region, the edge positions can be accurately located in a local area, obtaining a set of edge points with sub-pixel accuracy, which provides high-quality geometric priors for subsequent active contour models.

[0102] S3. Initialize and constrain the hybrid-driven Chan-Vese model with the sub-pixel edge point set. The hybrid-driven Chan-Vese model integrates the CV global region term, the GAC edge guidance term, and the weak anchor point constraint term to perform high-precision edge optimization segmentation.

[0103] Reference Figure 4 The diagram shown is a schematic representation of the flow of the level set function and the zero level set in this invention.

[0104] In this embodiment of the invention, the initialization and constraint of the hybrid-driven Chan-Vese model using the sub-pixel edge point set includes:

[0105] Connect the sub-pixel edge point sets into a closed polygon to generate a signed distance field as the initial value of the level set function;

[0106] A hybrid energy function is constructed, which includes a CV region fidelity term, a GAC ​​edge guidance term, and a weak anchor point constraint term; a distance regularization term is introduced to eliminate the repeated reinitialization of the level set function;

[0107] The level set function is iteratively evolved using gradient descent until convergence yields an accurate segmented contour. The constructed hybrid energy function includes a CV region fidelity term, a GAC ​​edge guiding term, and a weak anchor point constraint term, comprising:

[0108] The hybrid energy function is composed of the CV region fidelity energy, GAC edge guiding energy and weak anchor point constraint energy weighted and summed according to preset weight coefficients;

[0109] The weak anchor constraint is activated only in the first 30 iterations to guide the initial convergence direction, and is removed in subsequent iterations to allow unconstrained optimization.

[0110] The GAC edge guidance term is implemented through an edge stopping function, including:

[0111] The edge stopping function takes the gradient magnitude of the smoothed image as input; the larger the gradient magnitude, the smaller the function value.

[0112] The gradient magnitude is large at the edge of the target, and the edge stopping function value approaches zero, so that the contour stops precisely at the true boundary.

[0113] Specifically, the caliper tool can achieve efficient sub-pixel edge localization within a predefined local area, providing high-precision initial contour positions for active contour models. Traditional active contour models are highly sensitive to the placement of the initial contour; different initializations often lead to drastically different segmentation results. However, the sub-pixel edge points extracted by the caliper closely fit the real boundary, enabling the initial contour to be accurately placed near the target edge. This fundamentally solves the initialization sensitivity problem, significantly reduces the number of iterations required for contour evolution, and significantly improves segmentation efficiency and result stability.

[0114] Specifically, based on this, the active contour model further leverages its global optimization advantages. It is based on local image features and a global energy minimization evolutionary closed curve, capable of tolerating significant local noise while maintaining the smoothness and continuity of the contour. When strong reflections cause edge gaps, the contour can automatically bridge gaps using the spatial continuity of adjacent regions; when surface artifacts or burrs cause local disturbances, the contour can suppress jagged fluctuations through smoothing constraints, always maintaining a continuous and complete closed boundary.

[0115] In summary, the two work synergistically, utilizing the high-precision positioning capability of the calipers to provide reliable initial values, and leveraging the global smoothness of the active contour model to achieve robust edge optimization. The precise initial position provided by the calipers ensures that the active contour model is in the correct convergence base from the beginning, avoiding local optima or divergence problems caused by improper initial positions. Meanwhile, the global smoothness of the active contour model compensates for the shortcomings of the calipers' discrete detection, connecting isolated edge points into continuous, smooth closed contours, while also possessing the ability to handle topological changes.

[0116] Reference Figure 5 The figure shown is an evolution diagram of the improved CV model of the present invention based on caliper points in the inner diameter segmentation.

[0117] Furthermore, the combination of caliper prior and active contour model achieves the complementary advantages of high-precision initial positioning and global smooth optimization. It not only solves the pain point of sensitive initialization of traditional active contour model, but also overcomes the limitations of pure caliper method in lack of spatial context and shape constraints, and together completes the high-precision and high-robustness inner diameter segmentation task.

[0118] Furthermore, the discrete sub-pixel edge points extracted by the adaptive caliper are connected to form a closed polygon that closely fits the inner diameter contour of the target. A binary mask is generated by filling this polygon. Then, the shortest Euclidean distance from each pixel in the image to the closed contour is calculated, and a signed distance field is obtained by assigning positive values ​​to the outside and negative values ​​to the inside. This signed distance field serves as the initial level set function, where the zero level set defines the target contour. The function is normalized to a preset numerical range to ensure numerical stability during subsequent evolution.

[0119] Furthermore, when strong reflections cause missing edge segments, the profile can bridge gaps by merging adjacent segments. When surface artifacts or burrs create false edges, the profile can split and discard erroneous segments, retaining only the true boundaries. In contrast, explicit parametric models cannot handle such topological changes without complex, case-specific interventions, limiting their robustness in unstructured industrial environments.

[0120] Specifically, to overcome the inherent shortcomings of traditional CV models, a hybrid energy function is proposed, combining a region-fidelity term to adapt to uneven grayscale, an edge-guiding term to improve boundary localization accuracy, and a weak anchor point constraint term to enhance initialization robustness. To mitigate sensitivity to initial contour placement, a weak anchor point constraint term is introduced in the early stages of evolution, utilizing prior edge points extracted using adaptive calipers. This ensures convergence stability without unduly restricting the final boundary fitting.

[0121] Furthermore, the prior edge point set obtained by the adaptive calipers is used as the anchor point reference. For any pixel in the image domain, its minimum distance to the anchor point set is defined. This weak anchor constraint term is activated only in the first 30 iterations and then removed to allow unconstrained thinning. This phased design guides initial convergence toward the target region while preventing local errors at individual anchor points from compromising the final boundary accuracy. The final level set evolution equation is obtained by minimizing the total energy functional through gradient descent. A signed distance field preservation penalty term is added to the evolution equation. This term constrains the level set function to approximate the signed distance function during evolution, thereby eliminating the need for reinitialization and improving computational efficiency.

[0122] Specifically, an edge guiding term is constructed by combining the edge stopping function of the GAC model to suppress excessive movement of the evolving profile at the target boundary. At the inner diameter edge, the gradient magnitude is large enough that the edge stopping function value approaches zero. Therefore, the length regularization term in the evolution equation also approaches zero, accurately stopping the profile at the true boundary and preventing over-evolution.

[0123] In summary, using sub-pixel edge points extracted by calipers as shape priors to initialize the active contour model ensures that the initial contour closely fits the real boundary, significantly reducing the number of evolution iterations. It also fundamentally solves the problem of traditional CV models being highly sensitive to the placement of the initial contour, significantly improving the stability and repeatability of the segmentation results. Furthermore, the weak anchor point constraint term employs a staged activation strategy, guiding the convergence direction only in the early stages of evolution. This ensures the stability of initial convergence while avoiding the loss of boundary fitting accuracy caused by excessive constraints in later stages, achieving a balance between convergence stability and boundary accuracy.

[0124] In summary, the GAC edge guidance term achieves accurate boundary localization through the edge stopping function, reliably capturing true boundaries even in weak edge regions caused by strong metal reflection. This effectively suppresses the oversegmentation phenomenon that is prone to occur in traditional region-based models, significantly improving segmentation robustness in complex industrial scenarios. Furthermore, the distance regularization term eliminates the need for periodic re-initialization during the evolution of the level set function, greatly reducing computational costs, improving algorithm efficiency, and making it more suitable for the real-time requirements of industrial online inspection.

[0125] In summary, the combination of caliper prior and active contour model shows significant advantages in scenarios with missing edges and artifact interference: when some edges are lost due to strong reflection, the contour can automatically bridge gaps using the spatial continuity of adjacent anchor points; when there are artifacts or burrs on the surface, the contour can discard erroneous segments through a splitting mechanism, retaining only the true boundaries, thus maintaining accurate inner diameter segmentation results under complex industrial imaging conditions.

[0126] S4. The segmented contour point set is fitted with a two-stage robust circle fitting. First, RANSAC is used to coarsely remove outliers to obtain the initial circle parameters. Then, dynamic weighted least squares optimization is used to compensate for the fitting deviation of the non-uniform point distribution, and finally the accurate measurement parameters of the guide rod inner diameter are obtained.

[0127] Reference Figure 6 The figure shown is a diagram of the two-stage robust circle fitting inner diameter measurement results of the present invention.

[0128] In this embodiment of the invention, the two-stage robust circle fitting of the segmented contour point set includes:

[0129] Phase 1: Randomly sample three non-collinear points to construct candidate circle models, calculate the geometric distance residuals from all points to the candidate circles, count the number of interior points, select the model with the most interior points, and perform least squares fitting on the set of interior points to obtain the coarse circle parameters.

[0130] The second stage: Based on the coarse circle parameters, the Gauss-Newton method is used for weighted least squares iterative optimization. The weights are dynamically adjusted according to the distribution density of the points and the residuals until the accurate circle parameters are obtained.

[0131] The weights are dynamically adjusted based on the point distribution density and residuals, including:

[0132] In the early convergence phase, density-adaptive weights are used, which calculate the weights based on the local distribution density of each point. The higher the density, the lower the weight, thus suppressing the excessive influence of local dense points.

[0133] In the later refinement stage, residual adaptive weighting is used. The weight is calculated based on the fitting residual of each point. The larger the residual, the lower the weight, which further suppresses the influence of residual outliers.

[0134] A smooth transition strategy is adopted between the two stages to avoid numerical instability caused by sudden changes in weights.

[0135] Specifically, traditional weighted least squares fitting typically starts with equal weights and applies global equilibrium to all edge points. However, the edge point set obtained after active contour optimization is naturally non-uniformly distributed, and equal-weighted fitting ignores these distributional differences. Therefore, even if subsequent correction uses center angle-based weighting, the influence of outliers on the initial parameter estimation is still difficult to eliminate. To address this issue, the RANSAC algorithm is introduced to provide robust initial estimates. By constructing candidate models through random sampling and evaluating data consistency, RANSAC identifies the effective point set while suppressing the excessive influence of locally dense points. Therefore, it can generate reliable initial fitting parameters without predefined weights, establishing a high-precision reference for subsequent center angle-based weighted fitting. This achieves a seamless transition from robust initial estimation to non-uniformly weighted optimization, significantly improving the circle fitting accuracy for non-uniformly distributed edge points.

[0136] Furthermore, in the initial fitting stage, the RANSAC algorithm is applied to remove outliers and estimate circle parameters, compensating for the limited tolerance of least squares fitting to gross errors. Three non-collinear points are randomly sampled from the edge point set obtained from active contour segmentation. Then, the geometric distance residual from each edge point to the current candidate circle is calculated. The sum of all residuals constitutes the total residual. Points whose residuals are less than a preset threshold are marked as inliers, and the circle model with the largest set of inliers is retained as the optimal coarse fitting result. Then, least squares fitting is applied to the filtered set of inliers to obtain coarse circle parameters for subsequent fine fitting.

[0137] Specifically, based on the coarse parameters estimated by RANSAC, the fine fitting stage employs a weighted least squares method. Compared to classical algebraic circle fitting, the objective function is constructed on the geometric distance from the edge points to the circumference, ensuring that the fitted parameters have direct physical meaning. This is a weighted nonlinear least squares problem with no closed-form solution because the circle parameters are nonlinearly coupled to the objective function. The Gauss-Newton method is used, which determines the step size only from the first-order Jacobian of the residuals, providing fast convergence and low computational cost.

[0138] Furthermore, the weights are dynamically adjusted as the iteration progresses. In the early convergence phase, density-adaptive weights are used, calculated based on the local neighborhood density of each point. Higher density results in lower weights, suppressing the excessive influence of locally dense points. Specifically, using the current fitted circle center as the origin of the polar coordinates, the polar angle corresponding to each edge point is calculated and normalized to the range of 0 to 2π. Then, the entire circumference is divided into 72 equal angle intervals. The number of edge points in each interval is counted, and the density compensation weight for points in that interval is calculated based on the number of points; the more points, the lower the weight. To prevent excessively wide weight ranges from causing numerical divergence, the density weights are normalized to the range of 1 to 5. This balances the enhanced contribution of sparse regions while ensuring the stability of the Gauss-Newton iteration, thereby correcting the offset of the circle fitting center caused by the non-uniform distribution of edge points.

[0139] Furthermore, the later refinement stage switches to residual adaptive weighting, where larger residuals result in lower weights, further suppressing the influence of residual outliers. After the initial system bias is largely eliminated, the algorithm gradually shifts its focus to suppressing residual outliers. A smooth transition strategy is adopted between the two stages, with the fusion coefficient increasing linearly from zero to one. This transition process is completed within a preset number of iterations, preventing numerical instability or convergence oscillations caused by abrupt changes in weight distribution. To improve computational efficiency, points with weights below a preset threshold are temporarily excluded from parameter estimation in the current iteration, as their contribution to the fitting results is negligible, thus reducing computational costs. If the number of valid points falls below a preset minimum, the iteration is immediately terminated to avoid an underdetermined system.

[0140] Furthermore, after the transition phase, only Huber robust weights are applied. These weights suppress the influence of large residual points not removed in the previous RANSAC steps. A robust adaptive threshold is defined based on the median absolute deviation of the current iteration residuals, with a threshold coefficient of 2.5, corresponding to approximately 99% confidence intervals for normally distributed residuals. A lower bound is set for the combined weights to prevent numerical instability of Gauss-Newton iterations and to avoid excluding valid points from parameter estimates. This lower bound ensures that even points with relatively large residuals contribute minimally to the fitting process, preventing over-suppression of legitimate edge points that are slightly off-target due to surface roughness.

[0141] In summary, the RANSAC coarse fitting stage can effectively remove outliers and jagged noise in the active contour segmentation results, obtain reliable initial circle parameters, and provide a high-quality starting point for subsequent fine fitting, fundamentally solving the problem of traditional least squares being sensitive to gross errors.

[0142] In summary, the early density adaptive weighting method automatically reduces the weight of points in dense regions and increases the contribution of points in sparse regions by statistically analyzing the point distribution density through angle binning. This fundamentally compensates for the system fitting bias caused by non-uniform point distribution and significantly improves the estimation accuracy of the center and radius.

[0143] In summary, the adaptive weighting of the residuals in the later stage adaptively determines the threshold based on the median absolute deviation of the residuals, which can effectively suppress residual outliers that were not completely removed in the RANSAC stage, and further improve the robustness and accuracy of the fitting results.

[0144] In summary, the two-stage dynamic weighting strategy achieves a smooth transition from system bias correction to outlier suppression, ensuring convergence stability and achieving high-precision fitting. The final radius error is only 0.2 percent, which is more than an order of magnitude lower than that of traditional equal-weighted least squares fitting.

[0145] In the several embodiments provided by this invention, it should be understood that the disclosed method can be implemented in other ways.

[0146] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention.

[0147] The embodiments of this application can acquire and process relevant image data based on machine vision and artificial intelligence technologies. Among them, machine vision is the theory, method and technology of using digital computers or imaging devices controlled by digital computers to simulate, extend and expand human visual functions, perceive industrial environments, acquire image information and use image processing and pattern recognition knowledge to obtain optimal measurement results.

[0148] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.

Claims

1. An improved Chan-Vese model method for measuring the inner diameter of a guide rod using shape prior constraints, characterized in that, The method includes: S1. Obtain the original image of the guide rod, and perform rapid coarse positioning on the image using edge gradient template matching to obtain the preliminary positioning area of ​​the inner diameter of the guide rod; S2. Based on the edge information of the preliminary positioning area, extract sub-pixel edge point sets using the edge-guided adaptive caliper, and use the sub-pixel edge point sets as geometric priors; S3. Initialize and constrain the hybrid-driven Chan-Vese model with the sub-pixel edge point set. The hybrid-driven Chan-Vese model integrates the CV global region term, GAC edge guidance term, and weak anchor point constraint term to perform high-precision edge optimization segmentation of the inner diameter. S4. The contour point set obtained by segmentation is subjected to two-stage robust circle fitting. First, the outliers of the contour point set are removed by RANSAC to obtain the initial circle parameters. Then, the fitting deviation of the non-uniform point distribution of the contour point set is compensated by dynamic weighted least squares optimization, and finally the accurate measurement parameters of the inner diameter of the guide rod are obtained.

2. The improved Chan-Vese model method for measuring the inner diameter of the guide rod according to claim 1, characterized in that, The process of acquiring the original image of the guide rod and performing rapid coarse positioning through edge gradient template matching yields a preliminary positioning area for the inner diameter of the guide rod, including: Perform Canny edge detection on the original image to extract edge contours and calculate pixel gradient magnitude and direction; Construct a similarity metric based on the dot product of gradient vectors, and calculate the degree of alignment of the gradient directions of corresponding edge points between the template and the candidate sub-image; A greedy early termination strategy and a multi-resolution pyramid search strategy are adopted, combined with SIMD parallel acceleration, to quickly locate the position and attitude of the guide rod.

3. The improved Chan-Vese model method for measuring the inner diameter of the guide rod according to claim 2, characterized in that... The greedy early termination strategy and multi-resolution pyramid search strategy are employed, including: The cumulative similarity is dynamically monitored, and the evaluation of the current candidate is terminated in advance when the maximum possible contribution of the remaining points cannot make the total score reach the preset threshold. Construct an image pyramid, perform fast coarse search in the low-resolution layer, and perform fine localization in the high-resolution layer; It employs multi-threaded parallel matching and SIMD vector operations to process multiple pixels and vectors simultaneously.

4. The improved Chan-Vese model method for measuring the inner diameter of the guide rod according to claim 1, characterized in that, The step of guiding the adaptive caliper to extract sub-pixel edge point sets based on the edge information of the initially located region includes: Anchor points are generated evenly distributed along the initially positioned inner diameter contour. At each anchor point, a rectangular caliper region is constructed along the local gradient direction, wherein the caliper direction is perpendicular to the edge tangent. Gray-scale projection analysis is performed within each caliper region, and the optimal sub-pixel edge points are extracted through Gaussian smoothing, first derivative calculation, and non-maximum suppression.

5. The improved Chan-Vese model method for measuring the inner diameter of the guide rod according to claim 4, characterized in that, The process of generating uniformly distributed anchor points along the initially positioned inner diameter contour includes: Extract the highest and lowest points of the preliminary positioning contour, and use the line connecting the two points as a reference baseline; With the midpoint of the baseline as the center of rotation, the baseline is rotated at fixed angular intervals, and the intersection point with the contour is the anchor point; Linear interpolation is performed on the missing anchor points to ensure uniform distribution along the circumference.

6. The improved Chan-Vese model method for measuring the inner diameter of a guide rod according to claim 1, characterized in that, The initialization and constraint of the hybrid-driven Chan-Vese model using the sub-pixel edge point set includes: Connect the sub-pixel edge point sets into a closed polygon to generate a signed distance field as the initial value of the level set function; Construct a hybrid energy function, which includes a CV region fidelity term, a GAC ​​edge guidance term, and a weak anchor point constraint term; A distance regularization term is introduced to eliminate the repeated reinitialization of the level set function; The level set function is iteratively evolved using the gradient descent method until convergence is obtained to obtain an accurate segmentation contour.

7. The improved Chan-Vese model method for measuring the inner diameter of the guide rod according to claim 6, characterized in that, The construction of the hybrid energy function includes: The hybrid energy function is characterized by being a weighted sum of the region fidelity energy corresponding to the CV region fidelity term, the edge guiding energy corresponding to the GAC edge guiding term, and the anchor constraint energy corresponding to the weak anchor constraint term, weighted by a preset weighting coefficient. The expression for constructing the hybrid energy function is as follows:

8. Among them, The region fidelity energy of the CV model. The GAC edge guiding energy of the CV model. The weak anchor constraint energy of the CV model. , , Let be the weight coefficients of the CV model; The weak anchor constraint is activated only in the first 30 iterations to guide the initial convergence direction, and is removed in subsequent iterations to allow unconstrained optimization.

9. The improved Chan-Vese model method for measuring the inner diameter of a guide rod according to claim 6, characterized in that, The GAC edge guidance term is implemented through an edge stopping function, including: The edge stopping function takes the gradient magnitude of the smoothed image as input; the larger the gradient magnitude, the smaller the function value. The key feature is that the GAC edge guiding term is implemented through the edge stopping function, which is: ; in, For Gaussian kernel, This is the edge response sensitivity gain coefficient. This represents the gradient magnitude of the smoothed image. The gradient magnitude is large at the target edge, and the edge stopping function value approaches zero, so that the evolution profile stops precisely at the true boundary.

10. The improved Chan-Vese model method for measuring the inner diameter of a guide rod according to claim 1, characterized in that, The segmented contour point set is fitted with a two-stage robust circle, including: Phase 1: Randomly sample three non-collinear points to construct a candidate circle model, calculate the geometric distance residuals from all points to the candidate circle, count the number of interior points, select the candidate circle model with the most interior points, and perform least squares fitting on the point set corresponding to the interior points to obtain the coarse circle parameters. The second stage: Based on the coarse circle parameters, the Gauss-Newton method is used for weighted least squares iterative optimization. The weights are dynamically adjusted according to the distribution density of the points and the residuals until convergence is obtained to obtain the accurate circle parameters.

11. The improved Chan-Vese model method for measuring the inner diameter of a guide rod according to claim 9, characterized in that, The method employs Gauss-Newton's weighted least squares iterative optimization, with weights dynamically adjusted based on the point distribution density and residuals, including: The weighted least squares optimization is based on the geometric distance residuals from each edge point to the fitted circle, and the objective function is constructed by summing the residuals according to the corresponding weights. The objective function of the weighted least squares optimization is: ; in,( , () represents the coordinates of the center of the circle with the inner diameter. The radius of the inner diameter, The inner diameter of the first The weight of each point; The weights are dynamically adjusted as the iteration progresses, and density-adaptive weights are used in the early iterations to suppress the excessive influence of local dense points. Later iterations employ residual adaptive weights to further suppress residual outliers in the segmented inner diameter.