An intelligent detection and identification method for metal bent pipes based on image processing

By employing techniques such as fine-grained preprocessing and adaptive local thresholding, the problems of noise interference and positioning deviation in the edge detection of metal bends in traditional detection systems have been solved, achieving high-precision bend detection and edge extraction, and improving the stability and efficiency of the detection system.

CN120471889BActive Publication Date: 2026-02-03LINHAI LINJI AUTOMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510609696.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-05-13
Publication Date
2026-02-03
Estimated Expiration
2045-05-13

AI Technical Summary

Technical Problem

Traditional visual inspection systems struggle to maintain edge integrity and connectivity when inspecting bent metal pipes in situations with uneven lighting, rust spots, welding marks, or reflective areas. Furthermore, gradient operators such as the Sobel operator cannot accurately reflect the sub-pixel position of the pipe's contour, resulting in low positioning accuracy. Existing ridge or skeleton extraction algorithms are prone to breakage or deviation at noisy or large-span edges.

Method used

By employing fine-grained preprocessing, median filtering, sub-pixel-level non-maximum suppression, adaptive local thresholding, direction vector smoothing, dynamic step-size bidirectional tracking, and ridge merging, continuous and unbroken ridges are constructed and their cumulative rotation angle is calculated, enabling real-time determination of curvature.

Benefits of technology

It achieves high-precision and robust edge extraction and curvature detection for metal bends, reduces noise interference, improves detection accuracy and robustness, and simplifies subsequent processing procedures.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120471889B_ABST
    Figure CN120471889B_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of metal elbow pipe intelligent detection and recognition based on image processing, and discloses a metal elbow pipe intelligent detection and recognition method based on image processing. The method first performs mirror filling 3*3 median filtering on the original image in the two-dimensional coordinate system of the upper left corner origin to remove salt and pepper noise and boundary artifacts; then, the horizontal, vertical gradient and amplitude, direction are calculated by using central difference; the sub-pixel position is subjected to bilinear interpolation along the smoothing direction to suppress non-maximum value, and the seed points are screened in the local window by taking 75% percentile threshold; the ridge line is extracted by positive and negative tracking according to the dynamic step length, and the complete edge is obtained by combining the end point Euclidean merging and length elimination; finally, the turning angle is calculated point by point and the total bending angle is accumulated, and the single segment and total threshold are compared to complete the precise anti-noise bending qualification determination in real time online.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of intelligent detection and recognition technology for metal bends based on image processing, specifically to an intelligent detection and recognition method for metal bends based on image processing. Background Technology

[0002] Metal bends are crucial components in industrial pipelines, mechanical parts, and structural components. Their bending angles and shape accuracy directly impact product performance and assembly quality. In actual production and quality inspection processes, accurate and automated testing of the curvature, bending angle, and contour integrity of bends has become a vital technical requirement for improving production efficiency, reducing labor costs, and ensuring product consistency.

[0003] Traditional visual inspection systems typically employ a global thresholding method based on grayscale histograms to extract pipe edges. When the inspected part's surface has uneven lighting, rust spots, welding marks, or reflective areas, the global threshold struggles to simultaneously adapt to the grayscale distribution of different regions, leading to missed or false edge detections. This results in broken or skipped edges in subsequent contour tracking, making it difficult to guarantee edge integrity and connectivity. Commonly used gradient operators for pipe contour extraction include Roberts, Sobel, and Prewitt. The Sobel operator is widely used due to its good noise resistance, but its fixed convolution kernel weights introduce positioning bias, failing to accurately reflect the true sub-pixel position of the pipe contour in space. When the pipe surface has minute scratches or texture noise, the Sobel operator often produces false edges or edge position shifts, affecting positioning accuracy. The classic Canny edge detection algorithm, during non-maximum suppression (NMS), only compares the gradient magnitude of integer pixels while ignoring peak changes in the sub-pixel range, causing true edges to be suppressed or missed at pixel-level grayscale gradient changes. Furthermore, NMS only uses global or fixed thresholds to remove non-peak points, failing to balance edge connectivity and noise suppression. Existing ridge or skeleton extraction algorithms, such as those based on shortest path or morphological skeletonization, are prone to breakage, deviation, or jitter at noisy or large-span edges because they cannot consider the smoothness of edge intensity direction and local contextual information. In addition, fixed-step tracking strategies tend to skip details in high-contrast regions and stutter in low-contrast regions, making it difficult to achieve complete extraction of the entire ridge.

[0004] Therefore, this case aims to propose an intelligent detection and recognition method for metal bends based on image processing. Through fine-grained preprocessing, sub-pixel-level non-maximum suppression, adaptive local thresholding, direction vector smoothing, dynamic step-size bidirectional tracking, and ridge merging, a continuous and unbroken ridge is constructed and its cumulative rotation angle is calculated, so as to realize the real-time judgment of excessive bending. Summary of the Invention

[0005] This invention provides an intelligent detection and recognition method for metal bends based on image processing, which helps to solve the problems mentioned in the background art.

[0006] This invention provides the following technical solution: an intelligent detection and recognition method for bent metal pipes based on image processing, comprising:

[0007] Establish a coordinate system and perform median filtering on the original grayscale image;

[0008] Calculate the gradients in the horizontal and vertical directions, as well as the gradient magnitude and direction, based on the image grayscale values;

[0009] Perform interpolation along the gradient direction to determine whether a pixel is a local maximum of the gradient.

[0010] Local percentile thresholding is used to filter local maxima and extract initial seed points;

[0011] The smoothed gradient direction is calculated by summing the direction vectors within the local pane.

[0012] Starting from the seed point, ridge line extraction is completed using forward and reverse tracing methods;

[0013] Ridges are merged and filtered based on the distance between endpoints and length thresholds;

[0014] The angle of rotation and the total bending angle are calculated based on the extracted ridge line and compared with a set threshold to determine whether the bending is qualified.

[0015] Optionally, the process of establishing a coordinate system and performing median filtering on the original grayscale image specifically includes:

[0016] Let the original grayscale image be The size is the width. Pixels, height Pixels; where, The grayscale intensity function represents the coordinates. The pixel grayscale value at that location;

[0017] Taking the top left corner as the origin Horizontal to the right is Positive axis, vertically downwards. Positive axis;

[0018] pixel coordinates are ,in, ;

[0019] For each pixel Constructing a 3×3 neighborhood set is as follows:

[0020] When the image extends beyond its boundaries, mirror padding is used; where, For pixels The set of gray values ​​in the 3×3 neighborhood;

[0021] The grayscale value after median filtering is calculated as follows: ;

[0022] in, This is a function of the grayscale value after median filtering; This refers to sorting the 9 values ​​in the set from smallest to largest and then selecting the 5th value.

[0023] Optionally, the calculation of the horizontal and vertical gradients based on the image grayscale values, as well as the gradient magnitude and direction, specifically includes:

[0024] Calculate the horizontal gradient as follows ;in, This represents the rate of change in grayscale value in the horizontal direction.

[0025] Calculate the vertical gradient as follows ;in, This represents the rate of change in grayscale value in the vertical direction.

[0026] Calculate the gradient magnitude as ;in, It is the gradient magnitude function;

[0027] The gradient direction is calculated as follows ;in, Let be the gradient direction function; It is a two-parameter arctangent function.

[0028] Optionally, the step of performing interpolation along the gradient direction to determine whether a pixel is a local maximum of the gradient specifically includes:

[0029] Interpolation along the gradient direction, specifically:

[0030] S1, for each pixel Remember the direction Take adjacent interpolation points:

[0031] , ;

[0032] S2, to exist and Perform bilinear interpolation at the point to obtain and ;

[0033] The determination of local maxima is as follows:

[0034] ;in, This is a binary edge mask after non-maximum suppression, where 1 indicates a local maximum of the gradient.

[0035] Optionally, the step of using a local percentile threshold method to filter local maxima and extract initial seed points specifically includes:

[0036] Let the half width of the window be To construct a local pane, specifically:

[0037] Set the 75th percentile within the pane as the percentile threshold, specifically:

[0038] ;in, To retrieve the first element of the sorted set One value;

[0039] Filter the initial seed point mask based on the percentile threshold:

[0040] ;in, To retain only the points with strong gradient maxima.

[0041] Optionally, the step of calculating the smoothed gradient direction using the vector sum of the direction vectors within the local pane specifically includes:

[0042] In the same pane Inside, the vector sum is calculated for each direction, specifically:

[0043] , ;

[0044] in, and These are the vector sums of the direction cosines and sines within the local window, respectively.

[0045] Smoothing direction calculation: ;in, This represents the gradient direction after smoothing.

[0046] Optionally, the ridge extraction, starting from the seed point and employing a forward and reverse tracing method, specifically includes:

[0047] For each seed point and Perform the following steps:

[0048] S3, Set the dynamic step size to ;in, This is the step size gain coefficient, used to amplify the effect of gradient strength; This is the floor function; This represents the number of pixels the current point has moved.

[0049] S4, Forward Tracking:

[0050] S41. Set the initial point Initial direction ;

[0051] S42, Perform iterations:

[0052] ;

[0053] ;

[0054] ;in, This is a rounding function that maps floating-point coordinates to the nearest pixel; This represents the number of iterations.

[0055] S43, if ,make Otherwise, stop.

[0056] S5, Reverse Tracking: By Direction Repeat S41 to S43 to obtain the reverse sequence;

[0057] By concatenating and deduplicating the forward and reverse sequences, a complete ridge is formed. .

[0058] Optionally, the merging and filtering of ridges based on the distance between endpoints and length thresholds specifically includes:

[0059] For any two ridge lines and The endpoints are respectively , Calculate the Euclidean distance: ;

[0060] like For each pixel, the corresponding sequence is concatenated and deduplicated to obtain a new ridge line;

[0061] Set the minimum length threshold to ;

[0062] Calculate the length of each ridge line Remove The ridge lines retain the effective set of ridge lines.

[0063] Optionally, the step of calculating the turning angle and total bending angle based on the extracted ridge line and comparing them with a set threshold to determine whether the bending is qualified specifically includes:

[0064] For each valid ridge line Perform the following steps:

[0065] S6. Calculate the rotation angle:

[0066] right calculate:

[0067] , ;

[0068] ;

[0069] in, and They are adjacent vectors; For the first Corner angle;

[0070] S7. Calculate the total bending angle as follows: ;

[0071] S8, Threshold Comparison:

[0072] Set the maximum allowed turning angle for a single segment to... The total bending threshold is ;

[0073] like or If the bending exceeds the standard, the corresponding point will be marked.

[0074] Otherwise, the bending test is deemed acceptable.

[0075] The present invention has the following beneficial effects:

[0076] 1. By employing mirror-filled boundary pixels and explicitly defining a 3×3 median filter operation, we ensure that there are no zero-fill artifacts at the image edges. This completely removes salt-and-pepper noise without sacrificing true edge details, providing a clean foundation for subsequent gradient calculations. In common steel pipe inspection images, strong noise is generated by weld points and rust spots. Median filtering eliminates isolated noise points and avoids the generation of false ridges. Traditional zero-fill or cropped edges introduce discontinuous false edges; this solution combines mirror-filled and median filtering for more natural boundary processing and complete preservation of edge information.

[0077] 2. Using symmetric central difference instead of the common Sobel operator, precise and unbiased gradient components are calculated. This ensures the mathematical accuracy of gradient magnitude and direction, unaffected by the weight bias of the Sobel convolution kernel. At bends in the pipe, the slope of the edge changes drastically; central difference more accurately captures the true gradient, while the Sobel approximation results in edge position shifts. Sobel convolution has smoothing weights, reducing noise but introducing positioning errors; central difference directly reflects grayscale differences, achieving high-precision edge detection.

[0078] 3. Bilinear interpolation is introduced into non-maximum suppression to include non-integer gradient magnitudes in the comparison, achieving sub-pixel-level local maxima detection. This suppresses jagged edges and improves edge coherence; it also avoids gradient peaks lost due to rounding. Rough surfaces or uneven lighting on bent metal pipes cause gradient peaks to shift across pixels, which traditional non-maximum suppression easily misses; interpolated non-maximum suppression can accurately identify these. Classic Canny NMS only compares integer magnitudes, resulting in a high false positive rate; this method uses sub-pixel interpolation to improve peak detection rate and edge connectivity.

[0079] 4. A dynamic threshold based on the 75th percentile gradient within a local pane replaces the global fixed threshold. It preserves true edges in areas of rust and shadow, and automatically increases the threshold at high-contrast welds to suppress false edges. Pipe surfaces often exhibit both high and low contrast, which is difficult to accommodate with a fixed threshold; adaptive thresholding is compatible with multi-region characteristics. Traditional Otsu's or dual-threshold methods rely on full-image statistics, while local percentile thresholding is more flexible and adapts to image texture differences in real time.

[0080] 5. Apply a vector sum to all gradient directions within the window to output the direction, instead of a simple arithmetic average. This maintains directional continuity, significantly reduces noise-induced direction abrupt changes, and improves tracking stability. The original direction map jitters due to micro-noise, causing tracking deviations; vector smoothing obtains a consistent direction flow, improving tracking coherence. Convolutional smoothing or median filtering blurs true turning points; vector superposition preserves the main direction features, balancing detail and smoothness.

[0081] 6. The step size increases linearly with the gradient intensity and tracks in both directions. It advances rapidly in high-contrast regions and makes subtle steps at weak edges, balancing speed and integrity; bidirectional tracking avoids breaks caused by unidirectional blind spots. Fixed step size tracking either skips details or is inefficient at strong and weak edges; unidirectional tracking leaves tails, while bidirectional tracking completes the effective closed loop. Conventional edge tracking often uses pixel-by-pixel tracking; dynamic step size + bidirectional tracking significantly improves detection efficiency and edge integrity.

[0082] 7. Utilizing Euclidean distance, the connectivity of ridge endpoints is accurately determined, and a minimum length threshold is set to filter short, noisy chains. Edge segments interrupted by noise or lighting are automatically pieced together, while useless fragments are removed, reducing subsequent computational burden. Multiple ridges are scattered across the tube surface, making manual merging costly; this method automatically merges and cleans segments. While edge segments generally require post-processing clustering or morphological operations, this endpoint merging method is intuitive and efficient, preserving true long chains.

[0083] 8. Accurately calculate local turning angles based on vector dot product and sum them to obtain the total bending angle. The summation of turning angles directly corresponds to the bending amount of the pipe fitting and can be directly mapped to the production acceptance threshold without the need for curve fitting or Hough transform. Traditional methods rely on arc fitting or Hough space search, which are computationally complex and sensitive to noise; this method is simple, efficient, and highly noise-resistant. Radius calculation based on fitting is easily affected by data segmentation; this point-by-point cumulative turning angle method is more intuitive, robust, and easy to implement. Attached Figure Description

[0084] Figure 1 This is a schematic diagram of the process of the present invention. Detailed Implementation

[0085] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. 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.

[0086] Example, refer to Figure 1 A method for intelligent detection and recognition of bent metal pipes based on image processing, comprising:

[0087] Establish a coordinate system and perform median filtering on the original grayscale image;

[0088] Calculate the gradients in the horizontal and vertical directions, as well as the gradient magnitude and direction, based on the image grayscale values;

[0089] Perform interpolation along the gradient direction to determine whether a pixel is a local maximum of the gradient.

[0090] Local percentile thresholding is used to filter local maxima and extract initial seed points;

[0091] The smoothed gradient direction is calculated by summing the direction vectors within the local pane.

[0092] Starting from the seed point, ridge line extraction is completed using forward and reverse tracing methods;

[0093] Ridges are merged and filtered based on the distance between endpoints and length thresholds;

[0094] The angle of rotation and the total bending angle are calculated based on the extracted ridge line and compared with a set threshold to determine whether the bending is qualified.

[0095] By establishing a coordinate system and using median filtering, the problems of boundary artifacts and salt-and-pepper noise interference are solved. Median filtering, based on 3×3 neighborhood sorting with mirror filling and taking the median, effectively removes randomly occurring noise points in the image (such as weld spatter, abrupt rust spots, etc.) without losing true edges; mirror filling eliminates boundary artifacts caused by zero filling. This ensures a clean input base for subsequent gradient calculations, providing a high signal-to-noise ratio image for edge localization and improving detection stability and accuracy. The problem of operator localization bias and texture jitter is solved by using center difference gradient calculation. A symmetrical center difference operator, rather than a weighted convolution operator (such as Sobel), is used to accurately calculate the gray-level change rate in the horizontal and vertical directions at the integer pixel level. This ensures the mathematical accuracy of gradient magnitude and direction, avoids edge offset caused by operator kernel bias, and achieves more accurate edge strength and direction estimation. The problem of missed detection of cross-pixel peaks is solved by sub-pixel-level non-maximum suppression interpolation. Bilinear interpolation is performed on floating-point interpolation points in the gradient direction, and then compared with the center magnitude to remove non-maximum points. This system achieves sub-pixel-level edge peak detection, eliminating edge loss caused by traditional NMS's comparison of only integer points, and obtaining more complete and smooth edge candidates. Local percentile thresholding solves the problem of false positives and false negatives caused by uneven lighting and material differences. The 75th percentile of the gradient magnitude is used as a dynamic threshold within the local pane of each pixel, retaining only significantly maxima. It automatically adapts to the grayscale distribution of different regions, achieving robust edge extraction for complex scenes such as shadows, reflections, and rust, reducing manual parameter adjustments. Direction vector smoothing solves the problem of directional jitter and tracking errors caused by micro-noise. The cosine and sine of all gradient directions are vectorized and summed within the same local pane to obtain smooth and consistent gradient directions. Isolated noisy directions are eliminated to ensure directional continuity during subsequent ridge tracking, reducing link breaks and deviations. Dynamic step-size forward and reverse tracking solves the problem of missed detections or redundancy in fixed-step-size tracking. The step size adaptively increases or decreases with gradient intensity and extends bidirectionally from the seed point, covering both strong and weak edges. Rapid tracking in high-contrast areas and meticulous stepping in low-contrast areas ensures continuous and complete ridge lines without subsequent interpolation or manual repair. Endpoint Euclidean merging and minimum length elimination solve the problems of multi-segment ridge splicing and noisy link filtering. Automatic splicing of adjacent links is determined by Euclidean distance between endpoints, and excessively short fragments are discarded. Complete long ridge lines are automatically generated, and edge noise segments are removed, simplifying the post-processing workflow and accelerating algorithm operation. The high complexity of curvature fitting and strong anomaly sensitivity are addressed by accumulating corner angles and comparing with a preset threshold. The vector angles are calculated point-by-point and accumulated to obtain the total bending angle, which is then compared with a preset threshold for acceptance determination. The method is intuitive and efficient, requiring no circular arc fitting or Hough transform, exhibits strong noise resistance, and can be directly mapped to production acceptance standards for real-time online quality control.

[0096] The process of establishing a coordinate system and performing median filtering on the original grayscale image specifically includes:

[0097] Let the original grayscale image be The size is the width. Pixels, height Pixels; where, The grayscale intensity function represents the coordinates. The pixel grayscale value at that location;

[0098] Taking the top left corner as the origin Horizontal to the right is Positive axis, vertically downwards. Positive axis;

[0099] pixel coordinates are ,in, ;

[0100] Define the pixel location index and image range to provide a unified spatial reference for all subsequent operations;

[0101] For each pixel Constructing a 3×3 neighborhood set is as follows:

[0102] When the image extends beyond its boundaries, mirror padding is used; where, For pixels A 3×3 neighborhood grayscale value set; collect the grayscale values ​​of the current pixel and its 8 neighboring pixels for median filtering noise reduction;

[0103] The grayscale value after median filtering is calculated as follows: ;

[0104] in, This is a function of the grayscale value after median filtering; This refers to sorting the 9 values ​​in the set from smallest to largest and then taking the 5th value; by taking the median gray value of the neighborhood, salt-and-pepper noise is effectively suppressed while preserving edge details.

[0105] By establishing a coordinate system, the pixel location index and image range are clearly defined, resolving the spatial reference confusion caused by inconsistent pixel coordinates. This ensures that all subsequent algorithms run under the same coordinate reference, facilitating accurate pixel-level feature extraction and geometric transformation. Defining a coordinate system with the top-left corner as the origin, the x-axis pointing horizontally to the right, and the y-axis pointing vertically downwards resolves inconsistencies in the origin and direction across different software or modules, resulting in a streamlined and consistent image processing workflow and reducing complexity and errors caused by coordinate system transformations. Constructing a 3×3 neighborhood set for each pixel and using mirror filling addresses the issue of missing adjacency values ​​for edge pixels during neighborhood operations, ensuring each pixel has complete 8-neighborhood data for subsequent filtering and gradient calculations, thus preventing artifacts or information loss in boundary regions. The median filtering step—sorting the nine grayscale values ​​in the set from smallest to largest and then selecting the fifth value to generate the filtered grayscale—solves the interference of salt-and-pepper noise and random discrete noise common in metal bent pipe images, improving the image's signal-to-noise ratio.

[0106] This median filter effectively removes isolated noise while preserving true edge details, making subsequent gradient calculations more stable and edge localization more accurate. It reduces false detections and breaks caused by noise, significantly improving the robustness and reliability of the overall detection algorithm.

[0107] The calculation of the horizontal and vertical gradients based on image grayscale values, as well as the gradient magnitude and direction, specifically includes:

[0108] Calculate the horizontal gradient as follows ;in, This represents the grayscale change rate in the horizontal direction; it quantizes the grayscale change rate of pixels in the horizontal direction and detects the intensity of the left and right edges.

[0109] Calculate the vertical gradient as follows ;in, This represents the grayscale change rate in the vertical direction; it quantizes the grayscale change rate of pixels in the vertical direction and detects the intensity of the top and bottom edges.

[0110] Calculate the gradient magnitude as ;in, This is the gradient magnitude function, which measures edge intensity; a larger value indicates a more drastic change in grayscale.

[0111] The gradient direction is calculated as follows ;in, Let be the gradient direction function; It is a two-parameter arctangent function; it represents the local direction of the edge and provides a basis for non-maximum suppression and tracking direction.

[0112] By employing a horizontal gradient calculation step, the problem of inaccurate edge localization in the left and right directions is solved, effectively improving edge detection accuracy. Quantifying the grayscale change rate of pixels in the horizontal direction enables precise capture of abrupt bright-dark transitions on the left and right sides of the pipe fitting. This addresses the issue of localization offset that traditional unidirectional gradient operators (such as Sobel) are prone to in high-noise or unevenly lit scenes. The response to left and right edges is more sensitive and accurate, providing a reliable horizontal edge benchmark for subsequent non-maximum suppression and ridge tracking, reducing missed detections and false edges. The vertical gradient calculation step solves the problems of missed edges and texture interference in the up and down directions, ensuring edge integrity. Quantifying the grayscale change rate of pixels in the vertical direction enables accurate detection of contour changes at the top and bottom of the pipe fitting. This method overcomes the defect of frequent misjudgment or missed detection of top and bottom edges when the texture of weld seams and rust spots is complex. It provides a stable vertical edge response, achieving balanced extraction of edges in all directions, laying a solid foundation for overall contour generation. The gradient magnitude calculation step solves the problem of difficulty in uniformly measuring the individual gradient intensity in different directions, improving the reliability of edge intensity judgment. By fusing horizontal and vertical gradients into a single gradient magnitude function, the intensity of grayscale changes in all directions can be comprehensively reflected, avoiding false detections or omissions caused by a single component being too weak or too strong. Unifying the measurement of multi-directional information simplifies subsequent thresholding and seed point extraction processes, improving the accuracy and stability of edge candidate points. The gradient direction calculation step solves the tracking deviation problem caused by missing edge direction information, providing precise directional guidance for non-maximum suppression and ridge tracking. Calculating the two-parameter arctangent function to obtain the local gradient direction clearly distinguishes the angle and direction of edges. This step avoids the problem of unclear edge direction when processing only based on amplitude. In the non-maximum suppression stage, the correct direction can be used to determine whether a peak is a true edge, and in subsequent ridge tracking, it can be extended along a smooth direction to ensure a coherent and accurate ridge contour.

[0113] In summary, through these four complementary gradient calculation steps, this method can achieve multi-directional, high-precision, and robust edge extraction when faced with uneven illumination, texture noise, and complex contours on the surface of bent metal pipes. This provides a reliable data foundation for subsequent connectivity tracking, threshold screening, and curvature determination, significantly improving detection accuracy and robustness.

[0114] The interpolation operation along the gradient direction to determine whether a pixel is a local maximum of the gradient specifically includes:

[0115] Interpolation along the gradient direction, specifically:

[0116] S1, for each pixel Remember the direction Take adjacent interpolation points:

[0117] , Two points are taken in the gradient direction and the opposite direction to determine whether the current point is a true edge peak.

[0118] S2, to exist and Perform bilinear interpolation at the point to obtain and Accurately estimate gradient values ​​at non-integer coordinates to improve edge localization accuracy;

[0119] The determination of local maxima is as follows:

[0120] ;in, This is a binary edge mask after non-maximum suppression, where 1 indicates a local maximum of the gradient; it removes non-peak points of the gradient response and retains only edge candidates with the highest local gradient.

[0121] Gradient-direction interpolation solves the problem of insufficient positioning accuracy for discrete pixels. Traditional non-maximum suppression only compares the gradient magnitude of integer pixels, which can easily lead to missed detections of true edge peaks that fall between pixels. By taking one interpolation point along the gradient direction and one in the opposite direction... and This breaks the limitations of pixel grids, enabling sub-pixel-level candidate positions for edge peak detection. Interpolation points provide finer sampling locations, capturing the peak positions of real edges, improving the completeness and connectivity of initial edge candidates, and laying a more accurate foundation for subsequent tracking. Bilinear interpolation solves the problem of inaccurate estimation of non-integer gradient values. At the interpolation points... and Bilinear interpolation is applied to perform a weighted average of the gray levels of surrounding pixels to accurately estimate the gradient magnitude at non-integer coordinates. and Compared to simple nearest-neighbor interpolation or integer rounding, bilinear interpolation takes into account information from multiple neighboring pixels, resulting in a smoother and more continuous interpolation amplitude, reducing interpolation errors, and thus improving the accuracy and robustness of edge localization. By using local maxima determination, it solves the problem of noise and weak response points interfering with edge detection. Using the formula... True maxima with amplitudes higher than both interpolation points are strictly retained, while noise responses and non-peak points are eliminated. This effectively distinguishes true edge peaks from surrounding noise peaks, retaining only the most representative edge candidates, improving edge extraction accuracy and reducing false detections and breaks in subsequent processing. Through refined interpolation and maxima selection, overall edge connectivity and subsequent tracking efficiency are significantly improved. After completing sub-pixel interpolation and rigorous local maxima determination in a single step, the generated edge candidate points possess both sub-pixel-level positioning advantages and eliminate noise and weak response points. This significantly reduces jumps and chain breaks during subsequent ridge tracking, allowing the tracking algorithm to focus more on true edges, greatly improving ridge continuity and tracking speed. This provides high-quality input data for subsequent directional smoothing and dynamic step-size tracking, ultimately improving the overall accuracy and stability of the detection system.

[0122] The method of using local percentile thresholding to filter local maxima and extract initial seed points specifically includes:

[0123] Let the half width of the window be To construct a local pane, specifically:

[0124] ; Statistical gradient distribution over a wide range provides samples for dynamic thresholding; Increase Its function is to statistically analyze gradient magnitudes over a larger area, and the threshold is used for this purpose. It provides smoother handling of global changes and more thorough noise suppression, preventing drastic threshold fluctuations caused by single-point or small-scale outliers. However, it also reduces its adaptability to localized fine textures and uneven lighting, potentially missing weak local edges; it also reduces... Its function is to calculate percentile thresholds only in very local environments, and the thresholds are more sensitive to fluctuations in local details; it can capture small or abrupt edge features, making it suitable for high-detail scenes, such as the detection of minute cracks; however, it is more sensitive to sporadic noise or texture points, which can easily lead to false detections, and a small pane of glass may result in insufficient statistical samples and unstable thresholds; if the detection environment has low noise and high sensitivity to minute defects is required, it can be used. If the scene noise is strong or the target has a large curved area, and the tolerance for false detection is low, then... ;

[0125] Set the 75th percentile within the pane as the percentile threshold, specifically:

[0126] ;in, To retrieve the first element of the sorted set Each value; adaptively selects the threshold with higher local intensity to remove local weak noise;

[0127] Filter the initial seed point mask based on the percentile threshold:

[0128] ;in, To retain only the strong gradient maxima as seeds for subsequent tracking, an initial set of strong gradient pixels is generated for tracking, improving the stability of subsequent tracking.

[0129] By constructing local panes and statistically analyzing gradient magnitude distribution, the sensitivity of a globally fixed threshold to uneven lighting and material differences is addressed. A half-width region is constructed around each pixel. Local pane By statistically analyzing gradient changes over a larger range, a richer sample is provided for threshold calculation. This avoids drastic threshold jumps caused by single-point or small-scale abnormal noise, ensuring a smooth transition of the threshold to global changes and effectively suppressing scattered noise. The local pane percentile dynamic threshold solves the problem of unrepresentativeness of traditional average or extreme value thresholds. The 75th percentile within the pane is used. As a dynamic threshold, it eliminates most weak noise points while retaining the main edge responses. This strategy overcomes the problems of the maximum threshold being easily skewed by isolated noise and the average threshold being affected by weak noise, ensuring that the threshold is more statistically significant and robust. By flexibly adjusting the pane size to balance noise suppression and detail preservation, it solves the adaptability problem of changing detection environments. When the pane size is increased, statistics can be performed over a wider area, reducing local noise interference and improving threshold stability, making it suitable for batch detection of large-area smooth bends; when the pane size is decreased, it can maintain high sensitivity to small textures and local abrupt changes, suitable for detecting small defects such as cracks and crevices. This adjustability allows the algorithm to work robustly in noisy environments and accurately capture weak edges when high detail is required. By selecting the initial seed point mask based on the percentile threshold, the problem of uncontrolled edge candidate point numbers is solved. Only those that meet the requirements are retained. The gradient local maxima are used to generate an initial seed point set with a high signal-to-noise ratio. This step effectively filters out weak noise residues and isolated points, ensuring that subsequent ridge tracing is carried out only at the most meaningful pixel locations, significantly improving the stability and computational efficiency of the tracing.

[0130] Overall, this step, through adaptive and statistically driven dynamic threshold design, achieves robust edge extraction for complex surfaces and variable scenes, suppressing noise while preserving effective details, and significantly improving the accuracy and anti-interference capability of pipe bending detection.

[0131] The calculation of the smoothed gradient direction using the vector sum of the direction vectors within the local pane specifically includes:

[0132] In the same pane Inside, the vector sum is calculated for each direction, specifically:

[0133] , ;

[0134] in, and These are the vector sums of the direction cosine and sine within the local window, respectively; they aggregate all local gradient direction information and suppress isolated noise directions.

[0135] Smoothing direction calculation: ;in, The smoothed gradient direction is used for connected tracing to reduce noise jitter; the locally consistent gradient direction is output to reduce jumps during connected tracing.

[0136] By calculating the vector sum of direction vectors within a local pane, the tracking instability caused by gradient direction jitter is resolved. At each pixel... Within the local pane, for all gradient directions Find the vector sum of the cosine and sine respectively. and Then calculate the smoothing direction. This step aggregates all gradient direction information within the neighborhood, averaging out sharp direction deviations caused by isolated noise points, thus improving the output... It more closely approximates the main edge direction of the region. The smoothed direction is continuous and changes gently, making the ridge line extending along it almost jitter-free and easier to form a complete continuous curve; isolated noise points have limited impact on the vector sum, reducing the weight of noise direction on the overall direction estimation, thus maintaining the correct main direction even in high-noise environments; while maintaining the local main direction, it does not over-smooth and cause the loss of fine edge features, enabling the algorithm to both restore the tiny bumps and concavities of the pipe and avoid jitter; after obtaining a smooth and consistent direction field, there is no need to perform multiple direction corrections and breakpoint filling on the ridge line tracking results, accelerating subsequent dynamic step size tracking and maximum value selection, and improving overall operating efficiency.

[0137] In summary, this vector sum-argument smoothing step significantly improves the directional continuity and robustness of the ridge extraction process, providing a solid foundation for the complete identification and accurate positioning of the edges of metal bends.

[0138] The process of extracting ridge lines using a forward and reverse tracing method, starting from a seed point, specifically includes:

[0139] For each seed point and Perform the following steps:

[0140] S3, Set the dynamic step size to ;in, This is the step size gain coefficient, used to amplify the effect of gradient strength; increasing... The effect is that in areas with strong gradients (more pronounced edges), the stride is significantly increased, allowing tracking to skip more pixels forward; in areas with weak gradients, the stride remains at its minimum of 1. This can accelerate the coverage of strong edges, reduce the number of iterations, and improve computational efficiency. However, an excessively large stride can skip details and may miss turning points at rapid corners, leading to discontinuous or offset ridge lines. Decreasing the stride... Its purpose is to make the step size closer to a constant 1, with only a slight gain at extremely strong gradients; it allows for more detailed tracking and more precise capture of edge transitions; however, it increases the number of computation iterations, reduces overall speed, and is less efficient for tracking low-gradient regions; if the gradient magnitude... and If the product is too large, you can first... Normalization to Then use a larger Stay alert; This is the floor function; The number of pixels moved at the current point is adaptively amplified with the gradient strength; this makes the tracking step size adapt to the gradient strength, enhancing the rapid coverage of strong edges;

[0141] S4, Forward Tracking:

[0142] S41. Set the initial point Initial direction ;

[0143] S42, Perform iterations:

[0144] ;

[0145] ;

[0146] ;in, This is a rounding function that maps floating-point coordinates to the nearest pixel; This represents the number of iterations.

[0147] Advance along the smooth direction with dynamic steps and round to the pixel grid to form continuous ridges;

[0148] S43, if ,make Otherwise, stop.

[0149] S5, Reverse Tracking: By Direction Repeat S41 to S43 to obtain the reverse sequence; ensure that a complete ridge can be extended from both sides of each seed point;

[0150] By concatenating and deduplicating the forward and reverse sequences, a complete ridge is formed. .

[0151] By dynamically setting the step size, the problem of fixed step sizes failing to adequately cover different gradient regions is solved, ensuring both efficient coverage and preservation of detail. In S3, the step size... With gradient magnitude The design adaptively increases or maintains a minimum step size of 1. This resolves the contradiction of traditional fixed step sizes requiring multiple iterations in high-contrast regions, resulting in low efficiency, and potentially missing corners in low-contrast regions. In strong gradient regions (where edges are clearly defined), the step size is automatically increased, allowing for rapid advancement by skipping redundant pixels, significantly reducing the number of iterations and improving overall computational speed. In weak gradient regions, the step size is maintained at 1, accurately detecting minute turns or creases to ensure that ridge details are not skipped. Through forward tracking and rounding mapping, the problem of mismatch between floating-point coordinate tracking and pixel grids is solved, enabling continuous and accurate ridge line S41–S43 steps, advancing along the smooth direction with a dynamic step size and using... The function rounds to the nearest pixel, ensuring that floating-point coordinates cannot directly correspond to pixel grids; the rounding mapping places ridges onto pixel grid points, eliminating sub-pixel errors and transforming continuous trajectories into discrete addressable pixels, facilitating subsequent fusion and display. The reverse tracing step solves the problem of ridge breakage or bias caused by unidirectional extension, ensuring that complete links are generated from both sides of each seed point. Reverse tracing... The process begins by repeating the forward flow and splicing it with the forward sequence, avoiding the risk of breakage on both sides of the seed point in unidirectional tracking. Bidirectional extension fills in unidirectional blind spots, automatically repairs edge breakpoints, and ensures that ridges grow simultaneously from the seed point inwards and outwards, generating a more complete contour chain.

[0152] In summary, dynamic step size significantly reduces the number of iterations in strong edge regions; fine stepping in weak edge regions preserves corner details, improving ridge continuity and curvature estimation accuracy; and the combination of bidirectional tracking and pixel mapping avoids chain breaks and jumps caused by noise and local occlusion.

[0153] The process of merging and filtering ridges based on the distance between endpoints and length thresholds specifically includes:

[0154] For any two ridge lines and The endpoints are respectively , Calculate the Euclidean distance: ;Measures the distance between two endpoints (pixels) to determine the connectivity of ridge endpoints;

[0155] like For each pixel, the corresponding sequence is spliced ​​and deduplicated to obtain a new ridge; overlapping or broken ridges generated from different seed points are merged into a complete chain.

[0156] Set the minimum length threshold to ; Its function is to filter out excessively short edge ridges and prevent noise discontinuities from being treated as valid edges; increase This method can more rigorously eliminate short-chain noise, improving overall detection accuracy; however, it may miss true, but slightly shorter curve segments, such as small-range bends, reducing recall; and decrease... This can preserve more short ridges, reducing the false negative rate; however, it will also preserve more noise chains, which may introduce false positives.

[0157] Calculate the length of each ridge line Remove The ridges are selected, and the effective ridge set is preserved; short noise chains are filtered out to ensure that only effective edges are retained.

[0158] The step of merging ridges by calculating the Euclidean distance of endpoints solves the problem of edge discontinuity caused by tracking breaks or overlaps, effectively generating complete ridges. By calculating the Euclidean distance between any two ridge endpoints and stitching them together when the distance is less than a threshold, edge fragments interrupted by noise, light spots, or local texture interference can be automatically connected, avoiding fragmented and discontinuous short chains in subsequent processing. This significantly improves the integrity of the edge structure, reduces manual or additional algorithmic repair work, ensures that the extracted ridges represent the true pipe contour, and improves the usability and reliability of the detection results. The step of filtering short ridges by setting a minimum length threshold solves the problem of noise fragments being misidentified as valid edges, eliminating meaningless links. A length threshold is used. For the length of each ridge line The comparison process removes links whose length is below a threshold. This step avoids misidentifying tiny discontinuous edges caused by local textures, reflective spots, or pixel jumps as real ridges. It significantly reduces false alarms in subsequent curvature calculations and quality assessments; simplifies data volume and improves detection efficiency; and allows for strict noise filtering or preservation of minute features by adjusting the threshold, adapting to different detection needs. The adjustable threshold mechanism solves the problem that fixed-length filtering cannot meet the needs of different scenarios, achieving algorithm flexibility. When high recall is required for small-scale bending or micro-cracks, the threshold can be appropriately reduced. When noise is high or the tolerance for false detection is extremely low, the [capacity] can be increased. This approach ensures that the algorithm can quickly eliminate a large number of useless links on high-speed production lines while capturing subtle edges in high-precision detection scenarios. It provides customized support for different production processes and detection standards, improving the system's applicability and flexibility, and reducing the cost of secondary parameter tuning due to environmental changes. Through an ordered combination of merging and filtering, it solves the pain points of complex post-processing and high computational load after edge extraction, simplifying the overall process. After merging, only the curvature and bending angle calculations need to be performed on the retained long ridges, eliminating the need for meaningless calculations and clustering of a large number of short fragments, significantly reducing the computational burden of subsequent curvature accumulation and threshold determination. This improves the overall algorithm speed and reduces system resource consumption; at the same time, it ensures the accuracy and stability of the final results, giving the detection system higher real-time performance and production site deployability.

[0159] In summary, through steps such as endpoint distance merging, minimum length filtering, and adjustable threshold, this solution effectively suppresses noise debris while ensuring the complete connectivity of the ridge line, providing an efficient, robust, and flexible edge post-processing solution, laying a solid foundation for the accurate bending detection of metal pipes.

[0160] The calculation of the turning angle and total bending angle based on the extracted ridge line, and the comparison with a set threshold to determine whether the bending is qualified, specifically includes:

[0161] For each valid ridge line Perform the following steps:

[0162] S6. Calculate the rotation angle:

[0163] right calculate:

[0164] , ;

[0165] ;

[0166] in, and They are adjacent vectors; For the first The turning angle is calculated; the instantaneous turning angle between three adjacent points is calculated, reflecting the curvature of the ridge line;

[0167] S7. Calculate the total bending angle as follows: The total curvature of the entire spine is accumulated for overall over-limit assessment.

[0168] S8, Threshold Comparison:

[0169] Set the maximum allowed turning angle for a single segment to... The total bending threshold is ; Its function is to limit the maximum bend at any three adjacent points; reduce It can detect slighter, sharper bends, but it is also more likely to misjudge image noise or fine ripples as non-compliant; increasing This will only mark very prominent bends, but may ignore smaller but still excessive bends; Its function is to measure the cumulative curvature of the entire ridge line; to reduce It will also give a non-compliance judgment for large-scale curves that are relatively flat overall, thus increasing sensitivity but also making it prone to false alarms; increase Only extremely large overall bending is considered to be out of tolerance, which is more tolerant, but may miss moderate bending defects.

[0170] By comparing real-time calculated values ​​with preset thresholds, it can be determined whether the pipe fittings are qualified or exceed the standards.

[0171] like or If the bending exceeds the standard, the corresponding point will be marked.

[0172] Otherwise, the bending test is deemed acceptable.

[0173] By calculating local corner angles, the method solves the problems of low accuracy and computational complexity of traditional circular arc fitting methods, effectively obtaining real-time curvature information for each point on the ridge line. In S6, for three adjacent points on the ridge line, the turning angle of each segment is directly calculated using the vector dot product formula. This method bypasses complex calculations such as least squares fitting of circular arcs or Hough transform, accurately reflecting local curvature changes. It solves the problems of large fitting errors, sensitivity to noise, and difficulty in real-time calculation; at the same time, it avoids the breakage or neglect of subtle corner angles that occur at pipe bends due to segmented fitting. Real-time corner angle analysis enables the algorithm to quickly locate sharp or subtle bends, combining high accuracy with low computational load. By calculating the total bending amount by accumulating corner angles, it solves the problem that it is difficult to assess the overall bending degree by relying solely on local angles, achieving intuitive quantification of the overall curvature of the bend. In S7, all local corner angles on the ridge line are calculated. Accumulated This establishes a total bending angle metric that can be directly mapped to production acceptance standards. This approach addresses the one-sidedness of focusing solely on the maximum curvature at a single point while neglecting the broader, gentler bends, enabling a quantitative assessment of the overall bending. The cumulative angle clearly reflects the bending trend of the pipe along its entire length, facilitating comparison with a total threshold. It allows for early warning of excessive overall bending, improving the comprehensiveness and accuracy of the inspection. The threshold comparison step overcomes the lack of flexibility and repeatability in traditional fixed or manual judgment methods, achieving adaptive and adjustable judgment of both local and overall bending. In S8, thresholds for the maximum angle of a single segment are set separately. and total bending threshold This process involves real-time comparison, which solves the problems of inconsistent manual experience thresholds and poor adaptability of fixed thresholds. It allows for flexible adjustment of judgment criteria based on pipe specifications and process requirements. Through adjustable local and global dual thresholds, it can highly sensitively detect minute but potentially life-affecting sharp bends while avoiding misjudgments of large-scale, gentle curves, thus balancing recall and accuracy to meet the requirements of different production batches and quality standards.

[0174] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.

[0175] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the technical principles of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.

Claims

1. A method for intelligent detection and recognition of bent metal pipes based on image processing, characterized in that, include: Establish a coordinate system and perform median filtering on the original grayscale image; The process of establishing a coordinate system and performing median filtering on the original grayscale image specifically includes: Let the original grayscale image be The size is the width. Pixels, height Pixels; where, The grayscale intensity function represents the coordinates. The pixel grayscale value at that location; Taking the top left corner as the origin Horizontal to the right is Positive axis, vertically downwards. Positive axis; pixel coordinates are ,in, ; For each pixel Constructing a 3×3 neighborhood set is as follows: When the image extends beyond its boundaries, mirror padding is used; where, For pixels The set of gray values ​​in the 3×3 neighborhood; The grayscale value after median filtering is calculated as follows: ; in, This is a function of the grayscale value after median filtering; This refers to sorting the 9 values ​​in the set from smallest to largest and then selecting the 5th value. Calculate the gradients in the horizontal and vertical directions, as well as the gradient magnitude and direction, based on the image grayscale values; The calculation of the horizontal and vertical gradients based on image grayscale values, as well as the gradient magnitude and direction, specifically includes: Calculate the horizontal gradient as follows ;in, This represents the rate of change in grayscale value in the horizontal direction. Calculate the vertical gradient as follows ;in, This represents the rate of change in grayscale value in the vertical direction. Calculate the gradient magnitude as ;in, It is the gradient magnitude function; The gradient direction is calculated as follows ;in, Let be the gradient direction function; It is a two-parameter arctangent function; Perform interpolation along the gradient direction to determine whether a pixel is a local maximum of the gradient. The interpolation operation along the gradient direction to determine whether a pixel is a local maximum of the gradient specifically includes: Interpolation along the gradient direction, specifically: S1, for each pixel Remember the direction Take adjacent interpolation points: , ; S2, to exist and Perform bilinear interpolation at the point to obtain and ; The determination of local maxima is as follows: ;in, This is a binary edge mask after non-maximum suppression, where 1 indicates a local maximum of the gradient. Local percentile thresholding is used to filter local maxima and extract initial seed points; The method of using local percentile thresholding to filter local maxima and extract initial seed points specifically includes: Let the half width of the window be To construct a local pane, specifically: ; Set the 75th percentile within the pane as the percentile threshold, specifically: ;in, To retrieve the first element of the sorted set One value; Filter the initial seed point mask based on the percentile threshold: ;in, To retain only points with strong gradient maxima; The smoothed gradient direction is calculated by summing the direction vectors within the local pane. The calculation of the smoothed gradient direction using the vector sum of the direction vectors within the local pane specifically includes: In the same pane Inside, the vector sum is calculated for each direction, specifically: , ; in, and These are the vector sums of the direction cosines and sines within the local window, respectively. Smoothing direction calculation: ;in, The gradient direction after smoothing; Starting from the seed point, ridge line extraction is completed using forward and reverse tracing methods; Ridges are merged and filtered based on the distance between endpoints and length thresholds; The angle of rotation and the total bending angle are calculated based on the extracted ridge line and compared with a set threshold to determine whether the bending is qualified.

2. The intelligent detection and recognition method for metal bent pipes based on image processing according to claim 1, characterized in that, The process of extracting ridge lines using a forward and reverse tracing method, starting from a seed point, specifically includes: For each seed point and Perform the following steps: S3, Set the dynamic step size to ;in, This is the step size gain coefficient, used to amplify the effect of gradient strength; This is the floor function; This represents the number of pixels the current point has moved. S4, Forward Tracking: S41. Set the initial point Initial direction ; S42, Perform iterations: ; ; ;in, This is a rounding function that maps floating-point coordinates to the nearest pixel; This represents the number of iterations. S43, if ,make Otherwise, stop. S5, Reverse Tracking: By Direction Repeat S41 to S43 to obtain the reverse sequence; By concatenating and deduplicating the forward and reverse sequences, a complete ridge is formed. .

3. The intelligent detection and recognition method for metal bent pipes based on image processing according to claim 2, characterized in that, The process of merging and filtering ridges based on the distance between endpoints and length thresholds specifically includes: For any two ridge lines and The endpoints are respectively , Calculate the Euclidean distance: ; like For each pixel, the corresponding sequence is concatenated and deduplicated to obtain a new ridge line; Set the minimum length threshold to ; Calculate the length of each ridge line Remove The ridge lines retain the effective set of ridge lines.

4. The intelligent detection and recognition method for metal bent pipes based on image processing according to claim 3, characterized in that, The calculation of the turning angle and total bending angle based on the extracted ridge line, and the comparison with a set threshold to determine whether the bending is qualified, specifically includes: For each valid ridge line Perform the following steps: S6. Calculate the rotation angle: right calculate: , ; ; in, and They are adjacent vectors; For the first Corner angle; S7. Calculate the total bending angle as follows: ; S8, Threshold Comparison: Set the maximum allowed turning angle for a single segment to... The total bending threshold is ; like or If the bending exceeds the standard, the corresponding point will be marked. Otherwise, the bending test is deemed acceptable.

Citation Information

Patent Citations

  • Edge detection method based on Canny algorithm

    CN111833366A

  • Method and system for detecting three-dimensional central axis of elbow

    CN112508885A