Intelligent detection and identification method for metal bent pipe based on image processing
The noise is removed through mirror filling and median filtering, combined with central differential and local percentile threshold screening, and a dynamic step bidirectional tracking method is adopted to solve the problem of inaccurate edge detection in metal bend detection, and high-precision and robust bending detection are achieved.
Patent Information
- Application Number
- CN202510609696.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-13
- Publication Date
- 2025-08-12
- Estimated Expiration
- 2045-05-13
AI Technical Summary
When detecting metal bent pipes, traditional vision detection systems are difficult to ensure edge integrity and connectivity when uneven light, rust spots, welding marks or reflective areas. In addition, existing operators such as Sobel and Canny algorithms cannot accurately reflect the subpixel-level position of the tube body contour, resulting in insufficient positioning accuracy and edge detection accuracy.
Mirror filling and median filtering are used to remove noise, combine the central differential to calculate the gradient, interpolation and local percentile threshold screening are performed along the gradient direction, dynamic step bidirectional tracking is used and ridges are combined to calculate the rotation angle to achieve bending judgment.
It realizes high-precision edge extraction and continuous ridge tracing under complex surface conditions, improves the accuracy and robustness of bending detection, simplifies the subsequent calculation process, and meets the real-time online quality control needs.
Smart Images

Figure CN120471889A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of intelligent detection and identification of metal bends based on image processing, and in particular to an intelligent detection and identification method of metal bends based on image processing. Background Art
[0002] Metal pipe bends are critical components in industrial piping, mechanical components, and structural parts. 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, bend angle, and contour integrity of pipe bends has become a crucial technical requirement for improving production efficiency, reducing labor costs, and ensuring product consistency.
[0003] Traditional visual inspection systems typically use a global threshold segmentation method based on grayscale histograms to extract pipe edges. When uneven lighting, rust spots, welding marks, or reflective areas are present on the surface of the inspected part, the global threshold cannot simultaneously adapt to the grayscale distribution of different areas, resulting in missed or false edge detections. This can cause discontinuities and jumps in subsequent contour tracing, making it difficult to ensure edge integrity and connectivity. Commonly used gradient operators for pipe contour extraction include Roberts, Sobel, and Prewitt. While the Sobel operator is widely used due to its excellent noise immunity, its fixed convolution kernel weights introduce positioning bias, making it inaccurately reflecting the true sub-pixel position of the pipe contour in space. When micro-scratches or texture noise are present on the pipe surface, the Sobel operator often produces false edges or offsets in edge position, compromising positioning accuracy. The classic Canny edge detection algorithm, during its non-maximum suppression (NMS) process, only compares the gradient amplitudes at whole pixels and ignores peak variations in the sub-pixel range. This results in true edges being suppressed or missed where the grayscale gradient changes across pixels. Furthermore, NMS only removes non-peak points based on a global or fixed threshold, failing to strike a balance between edge connectivity and noise suppression. Existing ridge or skeleton extraction algorithms, such as those based on the shortest path or morphological skeletonization, fail to consider the smoothness of the edge intensity direction and local contextual information, and are prone to breakage, deviation, or jitter at edges with noise or large spans. Furthermore, fixed-step tracking strategies tend to skip details in high-contrast areas and freeze in low-contrast areas, making it difficult to fully extract the entire ridge.
[0004] To this end, 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, directional vector smoothing, dynamic step-size bidirectional tracking and ridge merging, a continuous and unbroken ridge is constructed and its cumulative turning angle is calculated, thus achieving real-time judgment of excessive bending. Summary of the Invention
[0005] The present invention provides an intelligent detection and identification method for metal bends based on image processing, which helps solve the problems mentioned in the above background technology.
[0006] The present invention provides the following technical solution: a method for intelligent detection and identification of metal bends based on image processing, comprising: Establish a coordinate system and perform median filtering on the original grayscale image; Calculate the horizontal and vertical gradients, as well as the gradient magnitude and direction based on the image grayscale value; Perform interpolation along the gradient direction to determine whether the pixel is a local maximum gradient value; The local percentile threshold method is used to screen the local maximum points and extract the initial seed points; Calculate the smoothed gradient direction by the vector sum of the direction vectors in the local window; Starting from the seed point, the ridge line extraction is completed using the forward and reverse tracking method; Merge and filter ridges based on the distance between endpoints and length thresholds; The corner angle and total bending angle are calculated based on the extracted ridge line and compared with the set threshold to determine whether the bending is qualified.
[0007] Optionally, the establishing of a coordinate system and performing median filtering on the original grayscale image specifically includes: Assume the original grayscale image is , the size is width Pixels, height pixels; where is the grayscale intensity function, indicating the coordinate The gray value of the pixel at ; Take the upper left corner as the origin , horizontally to the right Axis positive direction, vertically downward Axis positive direction; Pixel coordinates are marked as ,in, ; For each pixel Construct a 3×3 neighborhood set, specifically: , when it exceeds the image boundary, mirror filling is adopted; among them, Pixels The 3×3 neighborhood grayscale value set of ; Calculate the grayscale value after median filtering, specifically: ; in, is the gray value function after median filtering; It means sorting the 9 values in the set from smallest to largest and taking the 5th one.
[0008] Optionally, the calculating of the gradients in the horizontal and vertical directions, as well as the gradient amplitude and direction based on the grayscale value of the image specifically includes: Calculate the horizontal gradient as ;in, is the grayscale change rate in the horizontal direction; Calculate the vertical gradient as ;in, is the grayscale change rate in the vertical direction; The calculated gradient amplitude is ;in, is the gradient amplitude function; The gradient direction is calculated as ;in, is the gradient direction function; is the two-argument inverse tangent function.
[0009] Optionally, performing an interpolation operation along the gradient direction to determine whether a pixel is a local gradient maximum specifically includes: Interpolation along the gradient direction, specifically: S1, for each pixel , remember the direction , take adjacent interpolation points: , ; S2, yes exist and Perform bilinear interpolation at and ; Determine local maximum, specifically: ;in, It is the binary edge mask after non-maximum suppression, and 1 represents the local maximum point of the gradient.
[0010] Optionally, the method of using a local percentile threshold method to screen local maximum points and extract initial seed points specifically includes: Let the half-width of the pane be , construct a local pane, specifically: ; Set the 75th percentile in the pane as the percentile threshold, specifically: ;in, To get the first values; Filter the initial seed point mask based on a percentile threshold: ;in, To retain only the strong gradient maximum points.
[0011] Optionally, calculating the smoothed gradient direction by the vector sum of the direction vectors in the local window pane specifically includes: In the same pane Inside, calculate the vector sum for the direction, specifically: , ; in, and are the vector sums of direction cosines and sines within the local window respectively; Smooth direction calculation: ;in, is the direction of the gradient after smoothing.
[0012] Optionally, starting from the seed point, the ridge line extraction is completed by using a forward and reverse tracing method, specifically including: For each seed point and , perform the following steps: S3, set the dynamic step size to ;in, is the step gain coefficient, which is used to amplify the influence of gradient strength; is the floor function; is the number of pixels moved for the current point; S4, forward tracking: S41, set the initial point , initial direction ; S42, iterate: ; ; ;in, is a rounding function that maps floating-point coordinates to the nearest pixel; is the number of iterations; S43, if ,make ; Otherwise stop; S5, reverse tracking: in the direction Repeat S41 to S43 to obtain the reverse sequence; The forward and reverse sequences are spliced and duplicated to form a complete ridgeline .
[0013] Optionally, merging and screening ridge lines according to the distance between endpoints and the length threshold specifically includes: For any two ridges and , the endpoints are 、 , calculate the Euclidean distance: ; like Pixels, the corresponding sequences are spliced and duplicated to obtain the new ridge line; Set the minimum length threshold to ; Calculate the length of each ridge , remove ridges, retaining the valid ridge set.
[0014] Optionally, the step of calculating the corner angle and the 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: For each valid ridge , perform the following steps: S6. Calculate the turning angle: right calculate: , ; ; in, and are adjacent vectors; For the At the corner angle; S7. Calculate the total bending angle as ; S8, threshold comparison: Set the maximum allowable rotation angle of a single segment to , the total bending threshold is ; like or , it is determined that the bending exceeds the standard and the corresponding point is marked; Otherwise, the bending is judged to be qualified.
[0015] The present invention has the following beneficial effects: 1. Mirroring border pixels and explicitly defining a 3×3 median filter operation ensure zero-fill artifacts are eliminated from image edges. This thoroughly removes salt-and-pepper noise without losing true edge detail, providing a clean foundation for subsequent gradient calculations. In common steel pipe inspection images, strong noise is generated by welds and rust spots. Median filtering eliminates isolated noise points and prevents the generation of false ridges. Traditional zero-filling or edge cropping introduces discontinuous artifacts. This solution, combining mirroring and median filtering, achieves more natural border processing while preserving edge information.
[0016] 2. Uses symmetric central differencing rather than the common Sobel operator to calculate precise and unbiased gradient components. This ensures the mathematical accuracy of gradient magnitude and direction, unaffected by the Sobel convolution kernel weight bias. Where the slope of pipe edges changes dramatically at bends, central differencing more accurately captures the true gradient; the Sobel approximation can cause edge position offsets. Sobel convolution uses smoothing weights to reduce noise but introduces positioning errors; central differencing intuitively reflects grayscale differences, enabling high-precision edge detection.
[0017] 3. Bilinear interpolation is introduced into non-maximum suppression, incorporating non-integer gradient amplitudes into the comparison to achieve sub-pixel local maximum detection. This suppresses jagged edges and improves edge continuity, avoiding gradient peaks lost due to rounding. Traditional non-maximum suppression can easily miss detections due to rough surfaces or uneven lighting in metal bends, resulting in gradient peaks that shift across pixels. Interpolated non-maximum suppression can accurately identify local maximums. Classic Canny NMS only compares integer amplitudes, resulting in a high false positive rate. This method's sub-pixel interpolation improves peak detection rates and edge connectivity.
[0018] 4. A dynamic threshold based on the 75th percentile of the gradient within a local window replaces a global fixed threshold. This preserves true edges in mottled rust and shadowed areas, while automatically increasing the threshold to suppress false edges in high-contrast welds. Pipe surfaces often experience a mix of high and low contrast, making it difficult for a fixed threshold to accommodate both. Adaptive thresholding accommodates multi-regional features. Traditional Otsu or dual thresholding relies on full-image statistics, while local percentile thresholding is more flexible and adapts to image texture variations in real time.
[0019] 5. Apply the vector sum of all gradient directions within the window to output the direction, rather than simply taking the arithmetic average. This maintains directional continuity, significantly reduces sudden changes in noise direction, and improves tracking stability. The original directional map can experience jitter due to micro-noise, leading to tracking deviations. Vector smoothing achieves a consistent directional flow, improving tracking consistency. Convolution smoothing or median filtering can obscure true turning points; vector superposition preserves the main directional features, balancing detail and smoothness.
[0020] 6. Step size increases linearly with gradient strength, and tracking is performed in both forward and reverse directions. Rapid advancement is achieved in high-contrast areas, while subtle steps are taken along weak edges, balancing speed and integrity. Bidirectional tracking avoids interruptions caused by unidirectional blind spots. Fixed step size tracking can skip details or be inefficient on strong and weak edges. Unidirectional tracking leaves traces, while bidirectional tracking effectively closes the loop by completing the trace. Conventional edge tracking often uses pixel-by-pixel tracking; dynamic step size combined with bidirectional tracking significantly improves detection efficiency and edge integrity.
[0021] 7. Euclidean distance is used to accurately determine the connectivity of ridge endpoints, and a minimum length threshold is set to filter out short noise chains. Edge segments interrupted by noise or light shadows are automatically joined, while useless fragments are removed to reduce the subsequent computational burden. Multiple ridges are scattered across the tube surface, making manual merging expensive; this method automatically merges and cleans the segments. While edge segments typically require post-processing clustering or morphological operations, this endpoint merging method is intuitive and efficient, preserving true long chains.
[0022] 8. Accurately calculate local angles based on vector dot products and accumulate them to form the total bend angle. The summed angles intuitively correspond to the amount of pipe bending and can be directly mapped to the production acceptance threshold without the need for curve fitting or Hough transforms. 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 resistant to noise. Radius calculation based on fitting is susceptible to data segmentation; this point-by-point angle accumulation method is more intuitive, robust, and easy to implement. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 It is a schematic diagram of the process of the present invention. DETAILED DESCRIPTION
[0024] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0025] Example, see Figure 1 , an intelligent detection and recognition method for metal bends based on image processing, comprising: Establish a coordinate system and perform median filtering on the original grayscale image; Calculate the horizontal and vertical gradients, as well as the gradient magnitude and direction based on the image grayscale value; Perform interpolation along the gradient direction to determine whether the pixel is a local maximum gradient value; The local percentile threshold method is used to screen the local maximum points and extract the initial seed points; Calculate the smoothed gradient direction by the vector sum of the direction vectors in the local window; Starting from the seed point, the ridge line extraction is completed using the forward and reverse tracking method; Merge and filter ridges based on the distance between endpoints and length thresholds; The corner angle and total bending angle are calculated based on the extracted ridge line and compared with the set threshold to determine whether the bending is qualified.
[0026] The establishment of a coordinate system and median filtering address the issues of boundary artifacts and salt-and-pepper noise. Median filtering takes the median value of a 3×3 neighborhood sorted with mirror padding, effectively removing random noise points (such as weld slag and rust spots) from the image without losing true edges. Mirror padding eliminates boundary artifacts caused by zero padding. This ensures a clean input basis for subsequent gradient calculations, providing a high signal-to-noise ratio image for edge localization, improving detection stability and accuracy. Central difference gradient calculation addresses operator positioning bias and texture jitter. Using a symmetric central difference rather than a weighted convolution operator (such as Sobel), the algorithm accurately calculates the horizontal and vertical grayscale change rate at the integer pixel level. This ensures the mathematical accuracy of gradient magnitude and direction, avoids edge shifts caused by operator kernel bias, and achieves more accurate edge strength and direction estimation. Sub-pixel non-maximum suppression interpolation addresses the problem of missed cross-pixel peaks. Bilinear interpolation is performed on floating-point interpolation points along the gradient direction and compared with the central magnitude to eliminate non-maximum points. This method detects edge peaks at the sub-pixel level, eliminating edge loss caused by traditional NMS that only compares whole points, resulting in more complete and smoother edge candidates. Local percentile thresholding eliminates false detections and missed detections caused by uneven lighting and material variations. The 75th percentile of the gradient magnitude within each pixel's local window is used as a dynamic threshold to retain only peaks with significant intensity. It automatically adapts to the grayscale distribution of different regions, enabling robust edge extraction in complex scenes such as shadows, reflections, and rust, reducing manual parameter adjustments. Directional vector smoothing eliminates directional jitter and tracking errors caused by micro-noise. The vector sum of all gradient direction cosines and sines within the same local window is calculated to generate smooth and consistent gradient directions. Isolated noise directions are eliminated to ensure directional consistency during subsequent ridge tracing, reducing link breakage and deviation. Dynamic step-size forward and reverse tracking eliminates missed detections or redundancies associated with fixed-step-size tracking. The step size adaptively scales up or down based on gradient strength and extends bidirectionally from the seed point to cover both strong and weak edges. Rapid tracking in high-contrast areas and careful stepping in weak areas ensure the continuity and integrity of the ridge line without the need for subsequent interpolation or manual repair. The Euclidean merging of endpoints and the elimination of minimum lengths solve the problems of multi-segment ridge line splicing and noise link filtering. The Euclidean distance between endpoints is used to determine the automatic splicing of adjacent links, and short fragments are discarded. Complete long ridge lines are automatically generated, edge noise segments are removed, the post-processing process is simplified, and the algorithm operation is accelerated. The problems of high curvature fitting complexity and strong anomaly sensitivity are solved through corner accumulation and threshold comparison. The vector angle is calculated point by point and the total bending angle is accumulated, which is compared with the preset threshold to achieve qualified judgment. The method is intuitive and efficient, does not require arc fitting or Hough transform, has strong noise resistance, can be directly mapped to production acceptance standards, and realizes real-time online quality control.
[0027] The establishing of a coordinate system and performing median filtering on the original grayscale image specifically includes: Assume the original grayscale image is , the size is width Pixels, height pixels; where is the grayscale intensity function, indicating the coordinate The grayscale value of the pixel at ; Take the upper left corner as the origin , horizontally to the right Axis positive direction, vertically downward Axis positive direction; Pixel coordinates are marked as ,in, ; Clarify the pixel position index and image range to provide a unified spatial reference for all subsequent operations; For each pixel Construct a 3×3 neighborhood set, specifically: , when it exceeds the image boundary, mirror filling is adopted; among them, Pixels The grayscale value set of the 3×3 neighborhood of the current pixel and its 8 neighboring pixels is collected for median filtering noise reduction; Calculate the grayscale value after median filtering, specifically: ; in, is the gray value function after median filtering; This method sorts the nine values in a set from smallest to largest and then takes the fifth one. By taking the median grayscale value of the neighborhood, it effectively suppresses salt and pepper noise while preserving edge details.
[0028] The coordinate system establishment step clarifies pixel position indices and image ranges, resolving spatial reference confusion caused by inconsistent pixel coordinates. This ensures that all subsequent algorithms operate within the same coordinate base, facilitating accurate pixel-level feature extraction and geometric transformations. By defining a coordinate system with the upper left corner as the origin, the x-axis extending horizontally to the right, and the y-axis extending vertically downward, this resolves the issue of inconsistent origin and orientation conventions across different software or modules. This streamlines the image processing workflow and reduces the complexity and errors associated with coordinate system conversion. By constructing a 3×3 neighborhood set for each pixel and applying mirror padding, the problem of missing neighboring values for edge pixels during neighborhood operations is resolved. This ensures that each pixel has complete eight-neighborhood data, allowing for subsequent filtering and gradient calculations, thus preventing artifacts or information loss in boundary regions. A median filtering step, which sorts the nine grayscale values in the set from smallest to largest and then takes the fifth value to generate the filtered grayscale, mitigates the interference of salt-and-pepper noise and random discrete noise, common in metal bend images, on edge detection and improves the image's signal-to-noise ratio.
[0029] This median filter effectively removes isolated noise while retaining true edge details, making subsequent gradient calculation more stable and edge positioning more accurate, reducing false detections and breaks caused by noise, and significantly improving the robustness and reliability of the overall detection algorithm.
[0030] The calculation of the horizontal and vertical gradients, as well as the gradient magnitude and direction based on the image grayscale value specifically includes: Calculate the horizontal gradient as ;in, is the grayscale change rate in the horizontal direction; quantizes the grayscale change rate of the pixel in the horizontal direction and detects the left and right edge strengths; Calculate the vertical gradient as ;in, The grayscale change rate in the vertical direction is quantified to detect the upper and lower edge strengths. The calculated gradient amplitude is ;in, It is a gradient amplitude function that measures edge strength. A larger value indicates a more drastic grayscale change. The gradient direction is calculated as ;in, is the gradient direction function; It is a two-parameter inverse tangent function; it represents the local direction of the edge and provides a basis for non-maximum suppression and tracking direction.
[0031] The horizontal gradient calculation step solves the problem of inaccurate left and right edge positioning, effectively improving edge detection accuracy. By quantifying the horizontal grayscale change rate of pixels, the method accurately captures the sudden changes in brightness and darkness on the left and right sides of the pipe. This overcomes the positioning offset that traditional unidirectional gradient operators (such as Sobel) are prone to in high-noise or uneven lighting conditions. The method provides a more sensitive and accurate response to left and right edges, providing a reliable horizontal edge reference 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 upper and lower directions, ensuring edge integrity. By quantifying the vertical grayscale change rate of pixels, the method accurately detects contour changes at the top and bottom of the pipe. This method overcomes the common problem of misidentification or missed detection of upper and lower edges in complex textures such as welds and rust spots. It provides a stable vertical edge response, achieving balanced edge extraction in all directions, laying a solid foundation for overall contour generation. The gradient amplitude calculation step solves the problem of difficulty in uniformly measuring gradient strength in different directions, improving the reliability of edge strength determination. By fusing the horizontal gradient and the vertical gradient into a single gradient amplitude function, it is possible to comprehensively reflect the intensity of grayscale changes in all directions, avoiding false detection or neglect caused by a single component being too weak or too strong. The multi-directional information is uniformly measured, and the subsequent threshold screening and seed point extraction process is simplified, thereby improving the accuracy and stability of the edge candidate points. The gradient direction calculation step solves the tracking deviation problem caused by the lack of edge direction information, and provides precise direction guidance for non-maximum suppression and ridge tracking. The two-parameter inverse tangent function is calculated to obtain the local gradient direction, which can clearly distinguish the angle and direction of the edge. This step avoids the problem of unclear edge direction in traditional processing based only on amplitude. In the non-maximum suppression link, it can be judged in the correct direction whether the peak is a true edge, and extended in a smooth direction in the subsequent ridge tracking to ensure a coherent and accurate ridge profile.
[0032] 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 metal bends, providing a reliable data basis for subsequent connectivity tracking, threshold screening, and curvature determination, significantly improving detection accuracy and robustness.
[0033] The interpolation operation is performed along the gradient direction to determine whether the pixel is a local gradient maximum, specifically including: Interpolation along the gradient direction, specifically: S1, for each pixel , remember the direction , take adjacent interpolation points: , ; Take two points in the gradient direction and the reverse direction to determine whether the current point is a true edge peak; S2, yes exist and Perform bilinear interpolation at and ; Accurately estimate the gradient value at non-integer coordinates to improve edge positioning accuracy; Determine local maximum, specifically: ;in, It is the binary edge mask after non-maximum suppression, where 1 represents the local maximum point of the gradient. It removes the non-peak points of the gradient response and only retains the edge candidates with the local highest gradient.
[0034] By interpolating in the gradient direction, the problem of insufficient positioning accuracy of discrete pixels is solved. Traditional non-maximum suppression only compares the gradient amplitude of the whole pixel, which makes it easy to miss the real edge peak if it falls between pixels. By taking an interpolation point in the gradient direction and the reverse direction and , breaking the limitation of pixel grid, making the edge peak detection obtain sub-pixel candidate position. The interpolation point provides a more delicate sampling position, which can capture the peak position of the real edge, improve the integrity and connectivity of the initial edge candidate, and lay a more accurate foundation for subsequent tracking. Through bilinear interpolation operation, the problem of inaccurate estimation of non-integer point gradient value is solved. At the interpolation point and Bilinear interpolation is applied at the location to perform weighted averaging of the grayscale values of the surrounding pixels to accurately estimate the gradient amplitude at non-integer coordinates. and Compared with simple nearest neighbor interpolation or integer rounding, bilinear interpolation takes into account the information of multiple neighboring pixels, making the interpolation amplitude smoother and more continuous, reducing the interpolation error, and thus improving the accuracy and robustness of edge positioning. By determining the local maximum, the interference of noise and weak response points on edge detection is solved. Using the formula Strictly retain the true maximum points with higher amplitudes than the interpolation points on both sides, and eliminate noise responses and non-peak points. Effectively distinguish the true edge peaks from the surrounding noise peaks, and only retain the most representative edge candidates, which improves the accuracy of edge extraction and reduces false detection and breakage in subsequent processing. Through refined interpolation and maximum value screening, the overall edge connectivity and subsequent tracking efficiency are significantly improved. After completing sub-pixel interpolation and strict local maximum judgment in a single step, the generated edge candidate points have the advantages of sub-pixel positioning while eliminating noise and weak response points. The subsequent ridgeline tracking greatly reduces the number of jump points and broken links, allowing the tracking algorithm to focus more on the true edge, greatly improving the ridgeline coherence and tracking speed, and laying a high-quality input data foundation for subsequent direction smoothing and dynamic step tracking, thereby improving the accuracy and stability of the detection system as a whole.
[0035] The local percentile threshold method is used to screen the local maximum points and extract the initial seed points, specifically including: Let the half-width of the pane be , construct a local pane, specifically: ; Statistical gradient distribution in a large range to provide samples for dynamic threshold; increase The role of the statistical gradient amplitude in a larger area is to It is smoother for global changes; it can suppress noise more thoroughly and will not cause severe fluctuations in thresholds due to single point or small range outliers; but at the same time it reduces the ability to adapt to local tiny textures and uneven lighting, and may miss local weak edges; it reduces The function of is to calculate the percentile threshold only in a very local environment. The threshold is more sensitive to fluctuations in local details. It can capture small or sudden edge features and is suitable for high-detail scenes, such as fine crack detection. However, it is more sensitive to occasional noise or texture points, which can easily lead to false detection. If the window is too small, it may lead to insufficient statistical samples and unstable threshold. If the detection environment noise is low and the sensitivity to small defects is high, it is recommended to use If the scene noise is strong or the target is curved, or the tolerance to false detection is low, it is recommended to ; The 75th percentile in the pane is set as the percentile threshold, specifically: ;in, To get the first value; adaptively select a threshold with higher local intensity to remove local weak noise; Filter the initial seed point mask based on a percentile threshold: ;in, To retain only the strong gradient maximum points as seeds for subsequent tracking; to produce the initial strong gradient pixel set for tracking, to improve the stability of subsequent tracking.
[0036] By constructing a local window pane and statistically analyzing the distribution of gradient amplitude, the problem of global fixed threshold being sensitive to uneven lighting and material differences is solved. Local pane , statistics of gradient changes in a larger range provide rich samples for threshold calculation. This can avoid drastic threshold jumps caused by abnormal noise at a single point or in a small range, ensure smooth transition of the threshold to global changes, and effectively suppress scattered noise. The local window percentile dynamic threshold solves the problem that the traditional average or extreme value threshold is not representative. Take the 75th percentile in the window As a dynamic threshold, it not only eliminates most weak noise points, but also retains the main edge response. This strategy overcomes the problem that the maximum threshold is easily affected by isolated noise and the average threshold is affected by weak noise, ensuring that the threshold is more statistically significant and robust. By flexibly adjusting the window size to balance noise suppression and detail retention, the adaptability problem of the changing detection environment is solved. When the window size is increased, statistics can be collected in a wider area, local noise interference can be reduced, and the threshold stability can be improved, which is suitable for batch detection of large-scale smooth bends; when the window size is reduced, high sensitivity can be maintained to tiny textures and local mutations, which is suitable for small defect detection scenarios such as cracks and slits. This adjustability allows the algorithm to work robustly in a noisy environment and accurately capture weak edges when high detail requirements are required. By screening the initial seed point mask based on the percentile threshold, the problem of the number of edge candidate points out of control is solved. Only those that meet the requirements are retained. The local maximum of the gradient is used to generate an initial set of seed points with a high signal-to-noise ratio. This step effectively filters out weak noise residues and isolated points, allowing subsequent ridge tracking to be carried out only at the most meaningful pixel locations, significantly improving tracking stability and computational efficiency.
[0037] Overall, this step achieves robust edge extraction for complex surfaces and changing scenes through adaptive, statistically driven dynamic threshold design, which suppresses noise while retaining effective details, greatly improving the accuracy and anti-interference ability of pipe bending detection.
[0038] The step of calculating the smoothed gradient direction by the vector sum of the direction vectors in the local window pane specifically includes: In the same pane Inside, calculate the vector sum for the direction, specifically: , ; in, and are the vector sums of direction cosines and sines within the local window respectively; they aggregate all local gradient direction information and suppress isolated noise directions; Smooth direction calculation: ;in, It smoothes the gradient direction and is used for connectivity tracking to reduce noise jitter. It outputs a locally consistent gradient direction and is used to reduce jumps during connectivity tracking.
[0039] The tracking instability problem caused by the gradient direction jitter is solved by the vector sum calculation step of the direction vector in the local window. In the local window of Find the vector sum of cosine and sine respectively and , then calculate the smooth direction This step aggregates all gradient direction information in the neighborhood and averages out the sharp direction deviations produced by isolated noise points, making the output Closer to the main edge direction of the area. 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 influence on the vector sum, reducing the weight of the noise direction on the overall direction estimation, so that the correct main direction can still be maintained in a high-noise environment; while maintaining the local main direction, it will not be over-smoothed to cause the loss of small edge features, allowing the algorithm to restore the tiny bumps and grooves of the pipe while avoiding jitter; after obtaining a smooth and consistent direction field, there is no need to perform multiple direction corrections and breakpoint filling on the ridge tracking results, which accelerates the subsequent dynamic step tracking and maximum value screening, improving overall operation efficiency.
[0040] In summary, the vector sum-inverse tangent smoothing step significantly improves the directional continuity and robustness of the ridge extraction process, providing a solid foundation for the complete identification and precise positioning of the metal bend edge.
[0041] The ridge extraction is completed by using the forward and reverse tracking method starting from the seed point, specifically including: For each seed point and , perform the following steps: S3, set the dynamic step size to ;in, is the step gain coefficient, which is used to amplify the influence of gradient intensity; The effect is that the step size is significantly increased in places with strong gradients (more obvious edges), and the tracking can skip more pixels forward; in places with weak gradients, the step size still maintains the minimum value of 1; it can accelerate the coverage of strong edges, reduce the number of iterations, and improve computational efficiency; however, if the step size is too large, details will be skipped, and turning points may be missed at fast corners, resulting in discontinuity or offset of the ridge line; reducing The role of is to make the step size closer to a constant 1, with only a slight gain at the very strong gradient; it can track more carefully and capture the edge turning point more accurately; but it increases the number of operation iterations, reduces the overall speed, and has low efficiency in tracking low gradient areas; if the gradient amplitude is and The product of is too large, you can first Normalized to , and then use a larger Stay sensitive; is the floor function; The number of pixels moved at the current point is adaptively amplified with the gradient strength; the tracking step size is adaptive to the gradient strength to enhance the rapid coverage of strong edges; S4, forward tracking: S41, set the initial point , initial direction ; S42, iterate: ; ; ;in, is a rounding function that maps floating-point coordinates to the nearest pixel; is the number of iterations; Advance in a dynamic step size along the smoothing direction and round to the pixel grid to form a continuous ridge line; S43, if ,make ; Otherwise stop; S5, reverse tracking: in the direction Repeat S41 to S43 to obtain a reverse sequence; ensure that a complete ridge line can be extended from both sides of each seed point; The forward and reverse sequences are spliced and duplicated to form a complete ridgeline .
[0042] The dynamic step size setting solves the problem that the fixed step size cannot cover different gradient areas well, ensuring both efficient coverage and retaining details. With gradient amplitude Adaptively increase or maintain the minimum value of 1. This design solves the contradiction that the traditional fixed step size requires multiple iterations in high-contrast areas, which is inefficient, and may miss corners in weak-contrast areas; the step size is automatically enlarged in strong gradient areas (where the edges are obvious), which can skip redundant pixels and advance quickly, greatly reducing the number of iterations and improving the overall operation speed; the step size is maintained at 1 in weak gradient areas, accurately detecting small turns or cracks to ensure that ridge details are not skipped. Through forward tracking and rounding mapping, the problem of floating-point coordinate tracking not corresponding to the pixel grid is solved, and continuous and accurate ridges are achieved. In steps S41-S43, the dynamic step size is used to advance in the smooth direction and The function rounds to the nearest pixel, ensuring that floating-point coordinates cannot directly correspond to the pixel grid; the rounded mapping places the ridge line on the pixel grid, eliminating sub-pixel errors and converting the continuous trajectory into discrete addressable pixels, facilitating subsequent fusion and display. The reverse tracing step solves the problem of ridge line breakage or bias caused by unidirectional extension, ensuring that a complete link is generated from both sides of each seed point. The forward process is repeated and joined with the forward sequence, avoiding the risk of one-way tracking breaking on both sides of the seed point. Bidirectional extension fills in one-way blind spots and automatically repairs edge breakpoints, ensuring that ridges grow simultaneously from the seed point inward and outward, generating a more complete contour chain.
[0043] In summary, dynamic step size significantly reduces the number of iterations in strong edge areas; fine stepping in weak edge areas preserves corner details, improving ridge continuity and curvature estimation accuracy; bidirectional tracking is combined with pixel mapping to avoid link breaks and jumps caused by noise and local occlusion.
[0044] The merging and screening of ridge lines according to the distance between endpoints and the length threshold specifically includes: For any two ridges and , the endpoints are 、 , calculate the Euclidean distance: ;Measure the distance between the two end point pixels to determine the connectivity of the ridge endpoints; like If there are pixels, the corresponding sequences are spliced and duplicated to obtain new ridges; overlapping or broken ridges generated from different seed points are merged into a complete chain; Set the minimum length threshold to ; The function of is to filter out the edge ridges that are too short to avoid treating the noise discontinuity points as valid edges; increasing , can more strictly eliminate short chain noise and improve the overall detection accuracy; however, it may miss real but slightly shorter curve segments, such as small-scale bends, and reduce the recall rate; reduce , can retain more short ridges and reduce the missed detection rate; but it will cause more noise chains to be retained, which may introduce false detection; Calculate the length of each ridge , remove ridges, retaining the valid ridge set; filtering out short noise chains to ensure that only valid edges are retained.
[0045] The step of merging ridges by calculating the Euclidean distance of the endpoints solves the problem of edge discontinuity caused by tracking breaks or overlaps, and effectively generates complete ridges. By calculating the Euclidean distance of any two ridge endpoints and splicing and deduplicating when the distance is less than the threshold, the edge interruption fragments caused by noise, light spots or local texture interference can be automatically connected to avoid fragmented and incoherent short chains in subsequent processing. The integrity of the edge structure is greatly improved, and manual or additional algorithm repair work is reduced. It ensures that the extracted ridges represent the true pipe body contour and improves the availability and reliability of the detection results. By setting the minimum length threshold to filter short ridges, the problem of noise fragments being misidentified as valid edges is solved, and meaningless links are eliminated. Using a length threshold , for each ridge length Compare and remove links whose length is lower than the threshold. This step avoids the misjudgment of tiny discontinuous edges caused by local textures, reflective spots or pixel jumps as real ridges. It significantly reduces the number of false detection fragments and reduces false alarms in subsequent curvature calculations and quality judgments; simplifies the amount of data and improves detection efficiency; at the same time, it can strictly filter noise or retain tiny features by adjusting the threshold to adapt to different detection needs. The threshold adjustable mechanism solves the problem that fixed-length filtering cannot take into account the needs of different scenarios, and achieves algorithm flexibility. When high recall is required for small-scale bending or microcracks, the threshold can be appropriately reduced. ; When the noise is strong or the tolerance to false detection is very low, you can increase . This ensures that the algorithm can not only quickly eliminate a large number of useless links on high-speed assembly lines, but also capture subtle edges in high-precision detection scenarios. Provide customized support for different production processes and detection standards, improve the applicability and flexibility of the system, and reduce the cost of secondary parameter adjustment due to environmental changes. Through an orderly combination of merging and screening, the pain points of complex and computationally intensive post-processing of edge extraction are solved, simplifying the overall process. After merging, only the curvature and bending angle calculations need to be performed on the retained long ridges, and there is no need to perform meaningless calculations and clustering on a large number of short fragments, which significantly reduces the computational burden of subsequent curvature accumulation and threshold judgment. Improve the overall running speed of the algorithm and reduce system resource usage; at the same time, ensure the accuracy and stability of the final results, so that the detection system has higher real-time performance and deployability on production sites.
[0046] In summary, through steps such as endpoint distance merging, minimum length filtering, and adjustable thresholds, this solution effectively suppresses noise fragments while ensuring the complete connectivity of ridges. It provides an efficient, robust, and flexible edge post-processing solution, laying a solid foundation for accurate bend detection of metal bends.
[0047] The calculation of the corner angle and the total bending angle based on the extracted ridge line and comparing them with the set threshold to determine whether the bending is qualified specifically includes: For each valid ridge , perform the following steps: S6. Calculate the turning angle: right calculate: , ; ; in, and are adjacent vectors; For the Calculate the instant turning angle between three adjacent points to reflect the ridge curvature; S7. Calculate the total bending angle as ; Accumulate the curvature of the entire ridge line for overall exceeding standard determination; S8, threshold comparison: Set the maximum allowable rotation angle of a single segment to , the total bending threshold is ; The function of is to limit the maximum bending at any three adjacent points; reduce , it will detect more subtle sharp bends, but it will also be more likely to misjudge image noise or small ripples as unqualified; increasing , then only very prominent bends are marked, but smaller but still excessive bends may be ignored; The function of is to measure the cumulative curvature of the entire ridge line; reduce , will give an unqualified judgment for a relatively flat large range of curves, thereby increasing sensitivity but also prone to false alarms; increasing , then only the largest overall curvature is judged as exceeding the standard, which has a higher tolerance, but may miss moderate curvature defects; By comparing the real-time calculated value with the preset threshold, it is determined whether the pipe fitting is qualified or exceeds the standard; like or , it is determined that the bending exceeds the standard and the corresponding point is marked; Otherwise, the bending is judged to be qualified.
[0048] By calculating the local turning angle, the problems of low precision and complex calculation of the traditional arc fitting method are solved, and the real-time curvature information of each point on the ridge line is effectively obtained. In S6, for the three adjacent points on the ridge line, the vector dot product formula is used to directly calculate the turning angle of each segment. This method bypasses complex operations such as arc least squares fitting or Hough transform, and accurately reflects the local curvature changes. It solves the problems of large fitting error, sensitivity to noise and difficulty in real-time calculation; at the same time, it avoids the breakage or neglect of subtle corners due to segmented fitting at the bend of the pipe. Real-time corner analysis enables the algorithm to quickly locate sharp or subtle bends, with both high precision and low computational load. By accumulating the angles to calculate the total bending amount, the deficiency of being difficult to evaluate the overall bending degree by local angles alone is solved, and the intuitive quantification of the overall curvature of the bent pipe is achieved. In S7, all local turning angles on the ridge line are calculated. Accumulated as A total bending angle metric is formed that can be directly mapped to the production acceptance standard. This measure solves the one-sided problem of focusing only on the maximum curvature of a certain point and ignoring the smooth bending over a large range, so that the overall curvature can also be quantitatively evaluated. The cumulative angle clearly reflects the bending trend of the bend over the entire length, which is convenient for comparison with the total threshold. It can provide early warning for overall excessive bending and improve the comprehensiveness and accuracy of detection. Through the threshold comparison step, the problem of lack of flexibility and repeatability of traditional fixed or manual experience judgment is solved, and adaptive and controllable judgment of local and overall bending is achieved. In S8, the maximum angle threshold of each segment is set separately. and total bending threshold , and conducts real-time comparisons. This step addresses the difficulty of standardizing thresholds based on manual experience and the poor adaptability of fixed thresholds, allowing the judgment criteria to be flexibly adjusted based on pipe specifications and process requirements. Adjustable local and global dual thresholds can highly sensitively detect tiny sharp bends that may affect pipe lifespan, while also avoiding misjudgments of large, gentle curves. This balances recall and accuracy, meeting the requirements of different production batches and quality standards.
[0049] It should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that includes a list of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus.
[0050] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the technical principles of the present invention. These improvements and modifications should also be regarded as within the scope of protection of the present invention.
Claims
1. A metal bend intelligent detection and recognition method based on image processing, characterized in that: include: Establish a coordinate system and perform median filtering on the original grayscale image; Calculate the horizontal and vertical gradients, as well as the gradient magnitude and direction based on the image grayscale value; Perform interpolation along the gradient direction to determine whether the pixel is a local maximum gradient value; The local percentile threshold method is used to screen the local maximum points and extract the initial seed points; Calculate the smoothed gradient direction by the vector sum of the direction vectors in the local window; Starting from the seed point, the ridge line extraction is completed using the forward and reverse tracking method; Merge and filter ridges based on the distance between endpoints and length thresholds; The corner angle and total bending angle are calculated based on the extracted ridge line and compared with the set threshold to determine whether the bending is qualified.
2. The method for intelligent detection and identification of metal bends based on image processing according to claim 1, characterized in that: The establishing of a coordinate system and performing median filtering on the original grayscale image specifically includes: Assume the original grayscale image is , the size is width Pixels, height pixels; where is the grayscale intensity function, indicating the coordinate The gray value of the pixel at ; Take the upper left corner as the origin , horizontally to the right Axis positive direction, vertically downward Axis positive direction; Pixel coordinates are marked as ,in, ; For each pixel Construct a 3×3 neighborhood set, specifically: , when it exceeds the image boundary, mirror filling is adopted; among them, Pixels The 3×3 neighborhood grayscale value set of ; Calculate the grayscale value after median filtering, specifically: ; in, is the gray value function after median filtering; It means sorting the 9 values in the set from smallest to largest and taking the 5th one.
3. The method for intelligent detection and identification of metal bends based on image processing according to claim 2 is characterized in that: The calculation of the horizontal and vertical gradients, as well as the gradient magnitude and direction based on the image grayscale value specifically includes: Calculate the horizontal gradient as ;in, is the grayscale change rate in the horizontal direction; Calculate the vertical gradient as ;in, is the grayscale change rate in the vertical direction; The calculated gradient amplitude is ;in, is the gradient amplitude function; The gradient direction is calculated as ;in, is the gradient direction function; is the two-argument inverse tangent function.
4. The method for intelligent detection and identification of metal bends based on image processing according to claim 3 is characterized in that: The interpolation operation is performed along the gradient direction to determine whether the pixel is a local gradient maximum, specifically including: Interpolation along the gradient direction, specifically: S1, for each pixel , remember the direction , take adjacent interpolation points: , ; S2, yes exist and Perform bilinear interpolation at and ; Determine local maximum, specifically: ;in, It is the binary edge mask after non-maximum suppression, and 1 represents the local maximum point of the gradient.
5. The method for intelligent detection and identification of metal bends based on image processing according to claim 4 is characterized in that: The local percentile threshold method is used to screen the local maximum points and extract the initial seed points, specifically including: Let the half-width of the pane be , construct a local pane, specifically: ; The 75th percentile in the pane is set as the percentile threshold, specifically: ;in, To get the first values; Filter the initial seed point mask based on a percentile threshold: ;in, To retain only the strong gradient maximum points.
6. The method for intelligent detection and identification of metal bends based on image processing according to claim 5 is characterized in that: The step of calculating the smoothed gradient direction by the vector sum of the direction vectors in the local window pane specifically includes: In the same pane Inside, calculate the vector sum for the direction, specifically: , ; in, and are the vector sums of direction cosines and sines within the local window respectively; Smooth direction calculation: ;in, is the direction of the gradient after smoothing.
7. The method for intelligent detection and identification of metal bends based on image processing according to claim 6, characterized in that: The ridge extraction is completed by using the forward and reverse tracking method starting from the seed point, specifically including: For each seed point and , perform the following steps: S3, set the dynamic step size to ;in, is the step gain coefficient, which is used to amplify the influence of gradient strength; is the floor function; is the number of pixels moved for the current point; S4, forward tracking: S41, set the initial point , initial direction ; S42, iterate: ; ; ;in, is a rounding function that maps floating-point coordinates to the nearest pixel; is the number of iterations; S43, if ,make ; Otherwise stop; S5, reverse tracking: in the direction Repeat S41 to S43 to obtain the reverse sequence; The forward and reverse sequences are spliced and duplicated to form a complete ridgeline .
8. The method for intelligent detection and identification of metal bends based on image processing according to claim 7 is characterized in that: The merging and screening of ridge lines according to the distance between endpoints and the length threshold specifically includes: For any two ridges and , the endpoints are 、 , calculate the Euclidean distance: ; like Pixels, the corresponding sequences are spliced and duplicated to obtain the new ridge line; Set the minimum length threshold to ; Calculate the length of each ridge , remove ridges, retaining the valid ridge set.
9. The method for intelligent detection and identification of metal bends based on image processing according to claim 8, characterized in that: The calculation of the corner angle and the total bending angle based on the extracted ridge line and comparing them with the set threshold to determine whether the bending is qualified specifically includes: For each valid ridge , perform the following steps: S6. Calculate the turning angle: right calculate: , ; ; in, and are adjacent vectors; For the At the corner angle; S7. Calculate the total bending angle as ; S8, threshold comparison: Set the maximum allowable rotation angle of a single segment to , the total bending threshold is ; like or , it is determined that the bending exceeds the standard and the corresponding point is marked; Otherwise, the bending is judged to be qualified.
Citation Information
Patent Citations
Edge detection method based on Canny algorithm
CN111833366A
Method and system for detecting three-dimensional central axis of elbow
CN112508885A
High-precision production line sensor rapid positioning method based on industrial camera
CN116402889A
Canny edge detection method based on bilateral filtering and adaptive threshold
CN117853510A
Bearing defect detection method and system based on computer vision
CN118799706A
Cited By
Contour bending detection method, system and equipment for aluminum bar quality inspection
CN120655648A
License plate recognition method based on image processing
CN121170775A
A license plate recognition method based on image processing
CN121170775B
Line end defect detection method and device in line draft graph and storage medium
CN121304581A