A threshold segmentation-based stainless steel kitchenware weld quality visual detection method

CN122657052APending Publication Date: 2026-08-28DONGGUAN ELEGANT KITCHENWARE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610801467.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-06-04
Publication Date
2026-08-28

AI Technical Summary

Technical Problem

首先,主流阈值分割方案多以固定或弱自适应的形式生成阈值,难以兼顾大面积和细小缺陷的检测需求,尤其对焊缝区域中的尺寸跨度大、灰度对比度变化剧烈的复杂形貌适应性较差;其次,焊缝本体与周边基材区域的物理属性和光学响应易受角度变化、照明变化及表面工艺扰动影响,常规算法较难区分焊缝与背景、缺陷与伪影,导致误检率较高;再次,部分方法对区域窗口的尺度调整仅基于粗略的全局参数,并未充分利用焊缝几何连续性和对称性,没有精细深入到实际焊缝的空间语义与结构层次,从而在空间一致性与检测完整性方面受限

Benefits of technology

(1)通过引入轻量级方向滤波与响应归一化机制,结合改进型快速霍夫变换并嵌入拓扑约束条件,实现了在强金属镜面反射干扰下对焊缝中心线的高鲁棒性提取,不仅有效抑制了局部过曝伪影导致的结构断裂或误检问题,还同步获取了每一点处的局部宽度估计与曲率置信度信息,为后续自适应感知窗口构建提供了几何先验支撑。相较于传统固定窗口或全局阈值方法易受反光区域误导而导致边缘漂移的问题,本方案利用动态生成的三类嵌套感知窗口——紧邻核心窗、过渡缓冲窗与背景参考窗,并依据局部曲率弹性调节其尺寸,使得特征提取能够精准匹配焊缝形貌变化,在保持宏观条带结构完整性的同时,显著提升了复杂曲率段和热影响区交界处的细节分辨能力,从而切实克服了现有技术中因静态分析区域设定所引发的语义混淆与判别失准缺陷。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122657052A_ABST
    Figure CN122657052A_ABST
Patent Text Reader

Abstract

The present application relates to a kind of based on threshold segmentation stainless steel kitchen weld quality visual detection method, comprising: to the original gray image of weld area is subjected to lightweight direction filtering and response normalization, inhibit reflection noise and enhance strip structure;Using improved Hough transform and topological constraint extraction weld center line skeleton and width, curvature and other features;Based on skeleton information dynamic construction multiscale nested perception window, extract histogram, gradient and edge continuity and other multidimensional local features, realize the intelligent discrimination of different area semantic state;According to semantic state, generate anchor point level adaptive threshold, fusion forms full graph dynamic threshold surface, realizes the accurate binary segmentation of weld defect;Through center line guided morphological processing eliminates isolated noise and boundary artifact, finally realizes the classification, grade and quality determination of different types of weld defects.The method improves the anti-reflection interference ability and detection reliability, and can realize high-precision automatic closed-loop quality control.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of weld visual inspection and image processing technology, and in particular to a visual inspection method for the quality of stainless steel kitchenware welds based on threshold segmentation. Background Technology

[0002] With the improvement of stainless steel kitchenware manufacturing processes, weld quality has a crucial impact on the product's appearance and structural strength. To achieve automated quality control, visual inspection of weld defects has become a key component of integrated intelligent inspection systems on the production line. Currently, the industry widely adopts threshold-based weld defect detection methods. This technology utilizes the grayscale characteristics of weld images, binarizing the image by setting global or local thresholds to separate potential defects such as cracks, porosity, and lack of fusion. Mainstream methods include global thresholding algorithms (such as Otsu's method), adaptive local thresholding methods (such as Niblack and Sauvola), and composite segmentation schemes combining morphological processing and histogram analysis. In recent years, with the increasing complexity of industrial scenarios and the improvement of equipment computing power, some applications have gradually introduced multi-scale filtering, region growing, or deep learning segmentation networks to enhance the detection capability of weld defects and adapt to the image diversity brought about by different welding processes. Overall, the technological trend mainly reflects the improvement of the robustness of segmentation algorithms and the enhancement of system real-time performance.

[0003] In common applications in this field, various threshold segmentation methods based on local or global features can effectively handle weld images with simple backgrounds and stable defect distributions, demonstrating high detection rates for large-sized, clearly defined defects. However, these methods exhibit limited adaptability and flexibility when faced with multi-scale and diverse weld defects in real-world production environments. Especially on stainless steel surfaces, due to significant differences in specular reflection, process scratches, and the dynamic range of grayscale around the weld body, traditional threshold-based segmentation methods are prone to imbalances in threshold settings, leading to the loss or misjudgment of large-sized defect boundaries, while small, minute defects are often submerged by background noise.

[0004] Existing technologies still have the following shortcomings and technical challenges. First, mainstream threshold segmentation schemes mostly generate thresholds in a fixed or weakly adaptive manner, making it difficult to meet the detection needs of both large areas and small defects, especially for complex morphologies in weld areas with large size spans and drastic gray-scale contrast changes. Second, the physical properties and optical responses of the weld body and surrounding substrate areas are easily affected by changes in angle, lighting, and surface process disturbances, making it difficult for conventional algorithms to distinguish between welds and backgrounds, and defects and artifacts, resulting in a high false detection rate. Third, some methods adjust the scale of the region window based only on coarse global parameters, failing to fully utilize the geometric continuity and symmetry of the weld, and not delving into the spatial semantics and structural levels of the actual weld, thus limiting spatial consistency and detection completeness. In addition, as vision systems are increasingly deployed towards embedded and edge intelligence, the demand for algorithm computational efficiency and physical interpretability is constantly increasing. Although complex multi-scale filtering, pyramid iteration, and deep segmentation networks have improved detection performance, their excessive computational power consumption and parameter black-box characteristics restrict their widespread application and engineer optimization in actual production lines.

[0005] Because the aforementioned techniques have not yet achieved an effective balance between dynamically adapting to multi-scale weld defects, maintaining the realism of defect boundaries, and maintaining sensitivity to fine-grained defects, they suffer from prominent problems such as insufficient threshold adaptability, poor accuracy in segmenting complex regions, and difficulty in elastically removing artifacts. Therefore, there is an urgent need to propose a novel detection method that combines the inherent geometric structure of the weld, semantic hierarchical perception, and physically interpretable threshold mapping. Solving the problem of high-sensitivity and high-precision collaborative detection of weld defects in stainless steel kitchenware under multi-scale and complex environments, shortening the algorithm development and engineering debugging cycle, and improving the applicability and detection integrity of automated quality control systems are currently pressing technical challenges that the industry needs to overcome. Therefore, developing a multi-scale adaptive threshold segmentation method based on weld centerline guidance, capable of dynamically generating multi-granularity local perception windows, and automatically optimizing the threshold generation method according to local structure and grayscale distribution has become a key requirement for promoting technological upgrades and actual mass production deployment in the industry. Summary of the Invention

[0006] This application provides a visual inspection method for the weld quality of stainless steel kitchenware based on threshold segmentation, which aims to solve one of the problems or issues of the prior art mentioned in the background.

[0007] This application provides a visual inspection method for the weld quality of stainless steel kitchenware based on threshold segmentation, specifically including: The original grayscale image of the weld seam area of ​​stainless steel kitchenware is acquired and preprocessed to generate a noise-reduced and enhanced grayscale image; Perform Fast Hough Transform on the denoised and enhanced grayscale image and extract features by combining topological constraints to extract the weld centerline skeleton data; Based on the local width estimate and curvature confidence in the weld centerline skeleton data, a multi-scale local perception window set is generated with each anchor point on the centerline as a reference. For each window in the multi-scale local perception window set, the gray-scale histogram peak and valley distribution, gradient magnitude cumulative ratio, and edge continuity score are calculated. Based on the above statistical characteristics, the current local region is determined to belong to one of the following: high-contrast flat segment, low-contrast curved segment, or multi-interference transition segment, and a local semantic state label sequence is generated. Based on the classification results of different semantic states in the local semantic state label sequence, a differentiated threshold generation mechanism is enabled to generate an adaptive threshold discrete point set; The adaptive threshold discrete point set is mapped to a continuous threshold surface covering the entire image range by bicubic interpolation, and pixel-by-pixel threshold segmentation is performed to generate a binary mask image of weld defects. Based on the spatial location information of the weld centerline skeleton data, centerline-guided morphological post-processing is performed on the weld defect binarized mask image. Hole filling and burr trimming operations are performed only in the neighborhood of the centerline, and isolated noise points far from the centerline are forcibly removed to generate an optimized weld defect detection image. Based on the defect distribution characteristics in the optimized weld defect detection image, a quality judgment conclusion is output, and the judgment conclusion is fed back to the automated quality control process to complete the closed-loop detection of the weld quality of stainless steel kitchenware.

[0008] This application provides a visual inspection method for the weld quality of stainless steel kitchenware based on threshold segmentation, which has the following beneficial effects: (1) By introducing a lightweight directional filtering and response normalization mechanism, combined with an improved fast Hough transform and embedded topological constraints, a robust extraction of the weld centerline under strong metal mirror reflection interference is achieved. This not only effectively suppresses structural fracture or false detection caused by local overexposure artifacts, but also simultaneously acquires local width estimation and curvature confidence information at each point, providing geometric prior support for subsequent adaptive perception window construction. Compared with the problem of edge drift caused by the susceptibility of traditional fixed window or global threshold methods to being misled by reflective areas, this scheme utilizes three types of dynamically generated nested perception windows—adjacent core window, transition buffer window, and background reference window—and adjusts their size elastically according to local curvature, so that feature extraction can accurately match weld morphology changes. While maintaining the integrity of the macroscopic strip structure, it significantly improves the detail resolution capability at the junction of complex curvature segments and heat-affected zones, thereby effectively overcoming the semantic confusion and discrimination inaccuracy defects caused by static analysis area setting in the prior art.

[0009] (2) Differentiated threshold generation mechanisms are designed for different local semantic states ("high-contrast flat segment", "low-contrast curved segment", "multi-interference transition segment"), and a continuously differentiable full-image threshold surface is constructed through bicubic interpolation, achieving physical consistency and spatial smoothness of pixel-level binarization. This strategy avoids the failure risk of traditional global methods such as Otsu and maximum entropy under non-uniform lighting, and also avoids the computational redundancy and parameter sensitivity problems caused by multi-scale filtering or pyramid iteration. In particular, the one-dimensional gray-level trend fitting residual compensation mechanism introduced for the low-contrast curved segment, and the restricted bimodal search strategy using neighborhood gray-level entropy weighting in multi-interference regions, greatly enhance the discrimination stability of the algorithm in weak boundary and noise-mixed scenes, making the threshold generation process both adaptive and interpretable. The final threshold surface not only reflects the local statistical characteristics of the original image, but also integrates high-level semantic guidance from the geometric shape of the center line and semantic state reasoning, which is significantly better than traditional methods that simply rely on intensity distribution or gradient response.

[0010] (3) A centerline-guided morphological post-processing strategy is adopted, which performs hole filling and burr trimming operations only in the neighborhood of the main weld path, while forcibly removing isolated noise components far from the centerline, ensuring that the segmentation results strictly follow the spatial orientation of the weld, greatly reducing the risk of false connectivity and false contours. The entire processing flow is based entirely on traditional image processing operators and geometric modeling ideas, without relying on deep neural networks or other data-driven models, thus possessing high determinism and real-time deployment capabilities. It can run stably on resource-constrained embedded vision controllers, meeting the dual requirements of low latency and high reliability for online industrial welding inspection. In addition, the outputs of each stage have clear physical meanings, facilitating intuitive debugging and intervention by production line engineers based on actual working conditions, significantly improving the maintainability and engineering applicability of the system. In summary, this solution constructs a closed-loop processing system from illumination robust enhancement, geometrically guided feature extraction to semantically driven threshold generation. Under the premise of ensuring computational efficiency, it achieves accurate, stable, and interpretable segmentation of the weld area in complex welding scenarios, effectively filling the gap in existing technologies in terms of balancing accuracy, speed, and adjustability. Attached Figure Description

[0011] Figure 1 This is the main flowchart of a visual inspection method for the weld quality of stainless steel kitchenware based on threshold segmentation.

[0012] Figure 2 This is a sub-flowchart of a visual inspection method for the weld quality of stainless steel kitchenware based on threshold segmentation.

[0013] Figure 3 This is another sub-flowchart of a visual inspection method for the weld quality of stainless steel kitchenware based on threshold segmentation. Detailed Implementation

[0014] Embodiments of the present invention are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.

[0015] The following disclosure provides many different embodiments or examples for implementing different structures of the invention. To simplify the disclosure, specific examples of components and arrangements are described below. Of course, these are merely examples and are not intended to limit the invention. Furthermore, reference numerals and / or letters may be repeated in different examples; such repetition is for simplification and clarity and does not in itself indicate a relationship between the various embodiments and / or arrangements discussed.

[0016] like Figure 1 As shown, this application provides a visual inspection method for the weld quality of stainless steel kitchenware based on threshold segmentation, specifically including: S1: Obtain the original grayscale image of the weld seam area of ​​the stainless steel kitchenware, and perform lightweight directional filtering and response normalization on the original grayscale image to suppress local overexposure artifacts caused by metal mirror reflection and retain the macroscopic strip structure of the weld seam, generating a noise-reduced and enhanced grayscale image.

[0017] S2: Based on the denoised and enhanced grayscale image, an improved fast Hough transform is performed and feature extraction is performed in combination with topological constraints to robustly extract weld centerline skeleton data containing pixel coordinate sequences, local width estimates, and curvature confidence.

[0018] S3: Using the local width estimate and curvature confidence in the weld centerline skeleton data as the basis for dynamic scaling, three types of nested perception windows are constructed based on each anchor point on the centerline: adjacent core window, transition buffer window and background reference window, to generate a multi-scale local perception window set.

[0019] S4: For each window in the multi-scale local perception window set, calculate the peak and valley distribution of the gray-scale histogram, the cumulative ratio of gradient magnitude, and the edge continuity score. Based on the above statistical characteristics, determine whether the current local region belongs to a high-contrast flat segment, a low-contrast curved segment, or a multi-interference transition segment, and generate a local semantic state label sequence.

[0020] S5: Based on the classification results of different semantic states in the local semantic state label sequence, a differentiated threshold generation mechanism is enabled. For high-contrast straight segments, a weighted local mean shift method is used; for low-contrast curved segments, a one-dimensional gray-scale trend fitting residual compensation term is introduced; and for multi-interference transition segments, a bimodal search strategy based on neighborhood gray-scale entropy weighting is activated to generate an adaptive threshold discrete point set.

[0021] S6: The adaptive threshold discrete point set is mapped to a continuous threshold surface covering the entire image range through a bicubic interpolation algorithm, and the continuous threshold surface is segmented pixel by pixel with the original grayscale image to generate a binary mask image of weld defects.

[0022] S7: Based on the spatial location information of the weld centerline skeleton data, perform centerline-guided morphological post-processing on the binary mask image of weld defects, perform hole filling and burr trimming operations only in the neighborhood of the centerline, and forcibly remove isolated noise points far away from the centerline to generate an optimized weld defect detection image.

[0023] Step S1: Acquire the original grayscale image of the weld area of ​​the stainless steel kitchenware, and perform lightweight directional filtering and response normalization on the original grayscale image to suppress local overexposure artifacts caused by metal specular reflection and preserve the macroscopic stripe structure of the weld, generating a denoised and enhanced grayscale image. Specifically, this includes: S1.1: Obtain the original grayscale image of the weld seam area of ​​the stainless steel kitchenware, perform spatial domain sampling and quantization encoding on the original grayscale image to convert the light intensity signal collected by the optical sensor into discrete digital matrix data, and generate the original grayscale matrix to be processed.

[0024] The S1.1 sub-step serves as the data entry point for the entire weld quality inspection process. Its core task is to convert the analog light signal captured by the optical imaging equipment into a discrete digital matrix that can be processed by a computer, providing a standardized data foundation for subsequent lightweight directional filtering and response normalization. This step directly determines the upper limit of the signal-to-noise ratio for subsequent feature extraction, and it is crucial to address the dynamic range overflow and quantization noise issues caused by the high reflectivity of the stainless steel surface.

[0025] Industrial linear array cameras or area array CMOS sensors perform photoelectric conversion on the weld seam area of ​​stainless steel kitchenware, receive the light intensity signal reflected after being illuminated by a light source, and convert it into a continuously changing analog voltage signal to form the original image electrical signal stream.

[0026] The original image electrical signal stream is subjected to analog-to-digital conversion (ADC) operation. Based on the preset sampling frequency and quantization bit depth, the continuous analog signal is discretized into a digital signal with a specific number of gray levels, generating an initial digital image data stream.

[0027] To take advantage of the high dynamic range reflectivity of stainless steel, linear or nonlinear gamma correction preprocessing is performed to adjust the mapping relationship between input light intensity and output grayscale value, thereby compressing the dynamic range of highlight areas and improving the discernibility of shadow details.

[0028] Spatial domain two-dimensional sampling is performed on the corrected digital image data. The number of row pixels and column pixels of the image are determined according to the set resolution parameters. A regular two-dimensional grid coordinate system is constructed to establish the spatial position index of each pixel.

[0029] Based on a two-dimensional grid coordinate system, the light intensity value of each pixel is quantized and encoded, and the continuous light intensity amplitude is mapped to an integer gray value in the range of 0 to 255, thus completing the discretization representation from physical light intensity to digital gray level.

[0030] The quantized grayscale data is formatted and encapsulated, and the pixel values ​​are arranged in row-major or column-major storage order to construct an original grayscale matrix of dimension M×N to be processed, where M represents the image height and N represents the image width.

[0031] The original grayscale matrix to be processed is validated to detect invalid pixel values ​​caused by sensor defects or transmission errors. Abnormal values ​​are replaced and repaired by neighborhood mean replacement to ensure the integrity and consistency of the matrix data.

[0032] Through the above spatial domain sampling and quantization encoding processing method, the light intensity signal collected by the optical sensor in the previous step is transformed into discrete raw gray-scale matrix data to be processed, realizing the standardized conversion from physical optical signal to digital image processing domain, and providing a high-quality and structurally complete input data foundation for subsequent multi-directional gradient operator convolution operation.

[0033] S1.2: Perform multi-directional gradient operator convolution operation based on the original gray-level matrix to be processed to calculate the directional response intensity value of each pixel in the image under the preset angle set, and generate a multi-channel directional response feature map.

[0034] Based on the original grayscale matrix to be processed, a set of preset angles containing four main directions of 0 degrees, 45 degrees, 90 degrees and 135 degrees is constructed to cover the main orientation features that the macroscopic strip structure of the weld may exhibit in the spatial domain.

[0035] For each orientation angle in the preset angle set, a corresponding discretized orientation gradient operator template is designed. The template adopts a 3x3 or 5x5 convolution kernel size to ensure that it can capture the grayscale change rate in the local pixel neighborhood.

[0036] Perform a two-dimensional convolution operation between the original grayscale matrix to be processed and the angle gradient operator template of the current direction to calculate the grayscale difference response value of each pixel in the image in that specific direction.

[0037] The absolute value of the difference response value obtained from the convolution operation is taken to eliminate the influence of the negative gradient on the subsequent intensity accumulation, and a single-channel directional response intensity map is generated in that direction.

[0038] Iterate through all the directional angles in the preset angle set, and repeat the above convolution and absolute value processing steps until multiple single-channel directional response intensity maps are obtained, equal to the number of angles.

[0039] All single-channel directional response intensity maps are stacked and stitched together according to the corresponding angular order to form a multi-channel directional response feature map with a multi-channel data structure.

[0040] By using multi-directional gradient operator convolution and channel stacking, the original gray-level matrix to be processed in the previous step is transformed into a multi-channel directional response feature map containing omnidirectional edge response information, thus realizing the comprehensive extraction of the directional features of weld stripes and providing multi-dimensional gradient basis for subsequent suppression of specular reflection artifacts.

[0041] S1.3: Use multi-channel directional response feature maps to perform extreme value filtering and non-maximum suppression operations to identify and locate the coordinates of high-frequency overexposure areas caused by metal mirror reflection, and generate a local overexposure artifact mask.

[0042] Sub-step S1.3 follows the multi-channel directional response feature map generated in the previous step. Its aim is to precisely extract high-frequency overexposure artifacts caused by specular reflection from complex metal surface textures through extreme value filtering and non-maximum suppression operations, generating a local overexposure artifact mask for subsequent compensation processing. The core of this step lies in utilizing the isotropic high-intensity abrupt change characteristics of metal reflection in the gradient domain, distinguishing it from the anisotropic edge features of weld defects, to achieve directional identification and localization of artifacts.

[0043] Global statistical histogram analysis is performed on the input multi-channel directional response feature map to calculate the mean and standard deviation of grayscale values ​​of all pixels in the maximum directional response channel. This establishes a dynamic global brightness baseline and eliminates the problem of absolute threshold failure caused by ambient light fluctuations.

[0044] Based on the global brightness baseline, a high-confidence overexposure initial judgment threshold is set. This threshold is set as the mean plus three times the standard deviation to cover more than 99.7% of the normal texture distribution range in the image, and to initially screen out a potential set of abnormally bright pixels.

[0045] Iterate through each pixel in the potential abnormally bright pixel candidate set, extract the directional response intensity values ​​of all channels under the preset angle set, construct the directional response vector of the pixel, and calculate the magnitude of the vector as the comprehensive gradient magnitude of the point.

[0046] For each candidate pixel, non-maximum suppression (NMS) is performed in its 8-neighborhood. The magnitude of the current pixel's overall gradient is compared with the magnitudes of its two adjacent pixels along the gradient direction. If the magnitude of the current pixel is not a local maximum, it is marked as a suppression point and removed from the candidate set. Ridge pixels with significant gradient abrupt changes are retained.

[0047] For the ridge pixels preserved after non-maximum suppression, the entropy value of their directional response vector is calculated to quantify the degree of gradient dispersion. Metal mirror reflection areas usually exhibit a simultaneous surge of gradients in multiple directions, resulting in a significantly higher directional entropy value than weld edges or scratches with a single dominant direction.

[0048] By setting a directional entropy threshold, pixels with directional entropy values ​​higher than the threshold are identified as isotropic specular artifacts, while pixels with directional entropy values ​​lower than the threshold are identified as anisotropic structural edges, thereby achieving preliminary separation of artifacts from the real weld structure in the gradient domain.

[0049] Pixels identified as isotropic specular artifacts are subjected to morphological dilation using circular structuring elements with a radius of 2 pixels to cover the blurred edges of overexposed areas caused by sensor saturation effects, ensuring the integrity of the artifact area.

[0050] The inflated artifact region is mapped to the original image coordinate system to generate a binarized local overexposure artifact mask, where the pixel value of the artifact region is 1, and the pixel value of the background and normal weld seam region is 0.

[0051] Through the above extreme value screening, non-maximum suppression and directional entropy discrimination processing, the multi-channel directional response feature map of the previous step is transformed into local overexposure artifact mask data with spatial location information, realizing the accurate positioning of the high-frequency overexposure area caused by metal mirror reflection, providing accurate domain guidance for the adaptive gain compensation in the subsequent step S1.4, and effectively avoiding accidental damage to normal weld texture.

[0052] S1.4: Based on the local overexposure artifact mask, perform adaptive gain compensation and smoothing filtering fusion processing on the original grayscale matrix to be processed, so as to suppress local overexposure artifacts while preserving the edge continuity of the macroscopic strip structure of the weld, and generate a denoised and enhanced grayscale image.

[0053] The system receives the original grayscale matrix to be processed and a local overexposure artifact mask as the input data source for adaptive gain compensation and smoothing filtering fusion processing. A morphological dilation operation is performed on the local overexposure artifact mask to expand the boundary range of the bright reflection region, generating an extended artifact region mask containing a transition buffer band. This ensures that subsequent restoration processes can cover the edge attenuation region of the reflected halo.

[0054] Logical index extraction is performed on the original grayscale matrix to be processed based on the extended artifact region mask to separate the overexposed pixel set and its neighboring normal pixel set, thus constructing a local grayscale restoration context. The average grayscale value and standard deviation of the overexposed pixel set within the extended artifact region are calculated, and the statistical characteristics of the neighboring normal pixel set are also calculated to establish a local illumination intensity reference system.

[0055] For each overexposed pixel, non-overexposed pixels are searched within a neighborhood window of a preset radius. A bilinear interpolation algorithm is used to estimate the theoretical background grayscale value at that location under conditions without specular reflection, generating an initial background estimation map. By comparing the difference between the initial background estimation map and the corresponding position in the original grayscale matrix, the grayscale overflow caused by specular reflection is quantified, forming a local gain error mapping table.

[0056] An anisotropic diffusion filtering algorithm is used to iteratively smooth the initial background estimation image to eliminate high-frequency noise introduced by interpolation and maintain the edge sharpness of the weld texture structure, generating a smooth background reference image. During this process, the diffusion coefficient is dynamically adjusted according to the image gradient magnitude, reducing the diffusion intensity at weld edges to protect structural integrity and increasing the diffusion intensity in uniform regions to suppress noise.

[0057] Based on the local gain error mapping table and a smoothed background reference image, an adaptive gain compensation function is constructed to non-linearly correct the pixel grayscale values ​​in overexposed areas. The correction process follows the mathematical model below, replacing the original overexposed grayscale values ​​with the compensated estimated values:

[0058] in, The corrected pixel grayscale value. To smooth the grayscale values ​​at the corresponding locations in the background reference image, These are the pixel values ​​in the original grayscale matrix to be processed. This is the gain suppression coefficient, with a value between 0 and 1, used to control the degree to which the original texture details are preserved.

[0059] The corrected pixel values ​​of the overexposed areas are backfilled into the original grayscale matrix to be processed, replacing the original bright artifact pixels, generating a preliminary denoised grayscale image. Gaussian smoothing filtering is then applied to the preliminary denoised grayscale image to further eliminate residual tiny noise spots and achieve a natural grayscale transition between overexposed and normal areas, generating the final denoised enhanced grayscale image.

[0060] By using the above-mentioned adaptive gain compensation and smoothing filtering fusion processing method, the local overexposure artifact mask generated in the previous step is transformed into a specific pixel-level grayscale correction operation, which effectively suppresses the local overexposure artifacts caused by metal mirror reflection, while preserving the edge continuity of the macroscopic strip structure of the weld, and realizing the high-quality generation of denoised and enhanced grayscale images, providing a data foundation for signal-to-noise ratio optimization for subsequent weld centerline extraction.

[0061] For example, for the locally overexposed areas identified in the original grayscale matrix, the kernel size of the morphological dilation operation is set to a 3x3 rectangular structuring element, causing the artifact region to expand outward by 1 pixel width. When calculating the local illumination intensity reference, non-overexposed pixels within a 5x5 neighborhood of the overexposed pixel are selected, and their average grayscale value is calculated to be 120 with a standard deviation of 15. The theoretical background grayscale value of the overexposed center point is estimated to be 118 using bilinear interpolation, while the original overexposed pixel value is 255, resulting in a grayscale overflow amplitude of 137. In the anisotropic diffusion filtering, the number of iterations is set to 20, the diffusion time step to 0.1, and the edge preservation parameter K is set to 50. After iteration, the gradient preservation rate of the smooth background reference image at the weld edge exceeds 90%. The gain suppression coefficient α is set to 0.2, and the corrected pixel grayscale value is calculated using the formula: I corr =118 + 0.2 * (255 - 118) = 118 + 27.4 = 145.4, rounded down to 145. This value is significantly lower than the original overexposure value of 255 and close to the background grayscale of 118, effectively restoring the weld texture details obscured by strong light. Finally, a Gaussian smoothing filter with a sigma of 1.5 is applied to process the stitched image, eliminating the step effect at the repair boundary. In the final denoised and enhanced grayscale image, the grayscale histogram distribution of the original overexposed area changes from a single peak value to a normal distribution that conforms to the material characteristics of the weld. The contrast-to-noise ratio of the weld centerline is improved by about 3 times, ensuring the accuracy of subsequent Hough transform detection.

[0062] S1.5: Perform global dynamic range mapping and contrast equalization on the denoised and enhanced grayscale image to unify the grayscale distribution benchmark under different lighting conditions and highlight the weld texture details, generating a standardized final denoised and enhanced grayscale image for subsequent steps.

[0063] like Figure 2 As shown, step S2: Based on the denoised and enhanced grayscale image, an improved Fast Hough Transform is performed, and feature extraction is performed in conjunction with topological constraints to robustly extract weld centerline skeleton data containing pixel coordinate sequences, local width estimates, and curvature confidence scores. Specifically, this includes: S2.1: Perform multi-scale directional gradient operator convolution operation on the denoised and enhanced grayscale image to calculate the directional response intensity value of each pixel under the preset angle set and suppress non-weld seam texture interference, and generate a multi-channel directional response feature map.

[0064] S2.2: An improved fast Hough transform accumulator voting mechanism is executed based on the multi-channel directional response feature map to map the spatial domain edge points to the parameter domain and filter out a high-confidence peak candidate set to generate a preliminary weld line parameter cluster.

[0065] Based on the multi-channel directional response feature map generated in step S2.1, pixels with gradient magnitudes exceeding a preset noise suppression threshold are extracted as valid edge candidate points, constructing a spatial domain edge point set. For each pixel in the spatial domain edge point set, its mapping trajectory in the Hough parameter space is determined based on its local principal orientation angle, which is determined by the channel index with the highest response intensity in the multi-channel directional response feature map. A two-dimensional Hough accumulator matrix is ​​initialized, with its row dimension corresponding to the discretization interval of the polar radius ρ and its column dimension corresponding to the discretization interval of the polar angle θ, and all accumulation units are initialized to zero. The spatial domain edge point set is traversed, and for each edge point coordinate (x, y)... and its corresponding principal direction angle θ i The polar radius ρ of this point in the parameter space is calculated using the polar coordinate transformation formula. i And in the Hough accumulator matrix, the corresponding (ρ) i ,θ i Perform a vote counting operation at the index position, increasing the accumulated value at that position by one unit weight.

[0066] Considering the noise characteristics of stainless steel weld images, a gradient magnitude weighting mechanism is introduced. The voting weight is set to the normalized gradient magnitude of the edge point in the multi-channel directional response feature map, thereby enhancing the contribution of the edge to the parameter space and suppressing weak noise interference. After voting on all edge points, local maxima detection is performed on the Hough accumulator matrix to identify peak points with accumulated values ​​significantly higher than the neighborhood average. These peak points correspond to potential linear structure parameters in the image. The detected peak points are sorted in descending order of accumulated values, and the top N peak points with the highest confidence are selected as the preliminary weld line parameter candidate set, where N is dynamically adjusted according to the complexity of the weld image and the expected number of line segments. Through the above-mentioned improved Fast Hough Transform accumulator voting mechanism, spatially dispersed edge points are mapped to the parameter domain and form a high-confidence peak candidate set, generating a preliminary weld line parameter cluster. This achieves robust extraction of the macroscopic linear structure of the weld and effectively reduces the probability of false detections caused by metal reflection and scratches.

[0067] For example, the resolution of the denoised and enhanced grayscale image is set to 1024×768 pixels. The polar angle θ of the Hough accumulator matrix is ​​discretized with a step size of 1 degree, covering the range from 0 to 179 degrees, and the polar radius ρ is discretized with a step size of 1 pixel, covering the range from -1500 to 1500 pixels. In the multi-channel directional response feature map, the noise suppression threshold is set to 1.5 times the global mean of the gradient magnitude, and only 5000 valid edge points exceeding this threshold are retained for voting. For each edge point, the angle corresponding to the channel with the largest response intensity is taken as the principal direction angle. For example, if the coordinates of an edge point are (200, 300...) If the principal direction angle is 45 degrees, then its polar radius ρ is calculated as 200×cos(45°)+300×sin(45°)≈353.55, rounded to 354. A weight is added at position (354,45) in the accumulator matrix, with the weight value being 0.8, the normalized gradient magnitude at that point. After completing all points, multiple local peaks appear in the accumulator matrix, with the largest peak located at (350,46). The cumulative value is 1200, and the second largest peak value is located at (-200, 135). The cumulative value is 800. The filtering threshold N is set to 10, and the 10 peak points with the highest cumulative values ​​are selected, corresponding to (ρ, θ). The parameter pairs serve as the initial weld line parameter set. This process successfully extracted three main straight line parameters representing the weld center direction from images containing significant metallic luster interference, eliminating most of the discrete low-confidence parameters caused by surface scratches, and significantly improving the accuracy and efficiency of subsequent topology constraint filtering.

[0068] S2.3: Utilize the preliminary weld line parameter cluster combined with the prior knowledge of the continuity of the macroscopic strip structure of the weld to perform a topological constraint filtering operation, in order to eliminate discrete false line segments caused by metal scratches or reflection artifacts and connect the fracture edges, generating a continuous weld centerline pixel coordinate sequence.

[0069] Receive the initial weld line parameter set output from step S2.2. This parameter set contains the polar radius and polar angle coordinate pairs corresponding to the high confidence peaks selected in the Hough transform accumulator, and serves as the initial input data for topology constraint filtering.

[0070] Traverse each candidate line segment parameter in the initial weld line parameter cluster, map it to the spatial domain of the noise-enhanced grayscale image, extract the set of coordinates of all edge pixels within the area covered by the line segment, and establish an inverse index relationship from parameter space to image space.

[0071] Based on the prior knowledge of the continuity of the macroscopic strip structure of the weld, a line segment adjacency graph model is constructed to calculate the Euclidean distance and directional angle deviation between the endpoints of any two candidate line segments, thereby quantifying the geometric connectivity possibility between line segments.

[0072] Set distance thresholds and angle tolerance thresholds, perform a merging operation on line segment pairs that meet the connectivity conditions in the adjacency graph, connect broken edge segments into long continuous line segments, and form a preliminary candidate set of weld skeletons.

[0073] For each continuous line segment in the preliminary weld skeleton candidate set, its local support index is calculated. This index is defined as the ratio of the number of real edge pixels in the area covered by the line segment to the theoretical length of the line segment, and is used to evaluate the physical authenticity of the line segment.

[0074] A topology consistency verification mechanism is introduced to analyze the gradient field distribution characteristics around the line segment. If there are significant asymmetric gradient reversals or isolated high-frequency noise clumps on both sides of the line segment, the line segment is determined to be a false structure caused by metal scratches or reflection artifacts.

[0075] Based on the local support index and the topology consistency verification results, a dual filtering strategy is implemented: discrete false line segments with local support below the preset lower limit and marked as topologically inconsistent are removed, while effective weld segments with high support and topological consistency are retained.

[0076] Smoothing spline interpolation is performed on the retained valid weld segments to eliminate the jagged effect caused by discrete pixel connections, generating a geometrically smooth and continuous weld centerline pixel coordinate sequence.

[0077] By using the above-mentioned topological constraint filtering and geometric optimization processing methods, the discrete and noisy preliminary weld line parameter set generated in the previous step is transformed into a continuous and robust weld centerline pixel coordinate sequence, which effectively suppresses complex interference factors on the metal surface and accurately extracts the main structure of the weld, providing a reliable geometric benchmark for subsequent local width estimation and curvature analysis.

[0078] S2.4: Perform local grayscale profile scanning and half-width at half-maximum (WHM) measurement calculations along the normal direction based on the pixel coordinate sequence of the continuous weld centerline to quantify the weld width distribution characteristics at each anchor point and generate a sequence of local width estimates for associated coordinate points.

[0079] Traverse the pixel coordinate sequence of the centerline of the continuous weld, and extract the coordinates of the current centerline anchor point to be processed and its tangent direction vector in the local coordinate system in turn, as the geometric reference for subsequent normal profile scanning.

[0080] Based on the tangent direction vector, an orthogonal rotation transformation operation is performed to calculate the normal direction unit vector perpendicular to the weld direction, and the spatial axis for grayscale profile sampling along this normal direction is established.

[0081] Using the current centerline anchor point as the origin, extend the preset maximum search radius along both sides of the unit vector in the normal direction to construct a one-dimensional discrete sampling path, and perform bilinear interpolation resampling on the denoised and enhanced grayscale image along this path to obtain a grayscale intensity profile sequence distributed along the normal.

[0082] Gaussian smoothing filtering is applied to the grayscale intensity profile sequence to suppress high-frequency noise fluctuations caused by the micro-roughness of the metal surface, generating a smoothed normal grayscale distribution curve to ensure the stability of subsequent extreme value detection.

[0083] On the smoothed normal grayscale distribution curve, the grayscale maximum point located near the center of the weld is identified as the peak value of the weld ridge line, and the grayscale intensity value corresponding to the peak value is determined as the local maximum grayscale reference.

[0084] A half-width threshold is set, which is equal to half the difference between the local maximum grayscale reference and the average grayscale value of the background substrate plus the average grayscale value of the background substrate. This threshold is used to define the energy boundary of the effective weld width.

[0085] Track the grayscale intensity changes from the peak position of the weld ridge line to both sides of the normal line, find the coordinates of the intersection point where the grayscale value first drops below the half-width threshold, and mark it as the left boundary point and the right boundary point.

[0086] If no intersection meeting the conditions is detected on one side, the gradient amplitude abrupt change point or the preset maximum physical weld width limit is used as the alternative boundary to prevent boundary loss due to local reflection or defects.

[0087] Calculate the Euclidean distance between the left and right boundary points, and define this distance value as the estimated local weld width at the current anchor point.

[0088] By performing local grayscale profile scanning and half-width at half-maximum (WHM) measurement calculations along the normal direction, the pixel coordinate sequence of the continuous weld centerline is transformed into a sequence of local width estimates associated with each coordinate point. This achieves a quantitative representation of the weld geometry and provides accurate dimensional basis for constructing a multi-level sensing window adapted to multi-scale defect detection.

[0089] S2.5: Perform three-point curvature radius calculation and smoothness scoring based on the pixel coordinate sequence of the continuous weld centerline to evaluate the local curvature and geometric stability of the centerline and output reliability index, generating weld centerline skeleton data containing pixel coordinate sequence, local width estimate and curvature confidence.

[0090] The input data is a sequence of pixel coordinates of the center line of a continuous weld. This sequence is generated by filtering the topological constraints in the previous step S2.3 and contains a set of discrete anchor point coordinates arranged in spatial order.

[0091] A sliding window traversal operation is performed on the pixel coordinate sequence of the continuous weld centerline. The current center anchor point to be processed and its two adjacent historical anchor points are selected to form a local three-point geometric unit to construct the basic geometric topology for curvature calculation.

[0092] Based on the coordinate data of the local three-point geometric unit, the cosine of the angle between the line vector connecting the first two points and the line vector connecting the last two points, as well as the Euclidean distance parameter, are calculated to quantify the degree of directional change and step size uniformity of the local path.

[0093] Using the three-point circle geometry principle, the instantaneous radius of curvature at the current anchor point is calculated using the following formula:

[0094] in, The instantaneous radius of curvature, , , These are the pairwise Euclidean distances between the three points. The area of ​​the triangle formed by the three points is calculated using Heron's formula.

[0095] Median filtering is performed on the calculated instantaneous radius of curvature sequence to remove singular extreme points caused by image noise or edge detection jitter, generating a smoothed local radius of curvature estimation sequence.

[0096] The smoothed local curvature radius estimate is converted into a curvature value and normalized according to a preset curvature threshold range to generate a curvature confidence index that characterizes the severity of weld bending. The smaller the curvature, the higher the confidence.

[0097] Combining the local width estimate generated in the previous step S2.4, the curvature confidence is weighted and corrected. In areas where the weld width changes drastically, the weight of the curvature confidence is reduced to suppress the misjudgment of geometric features caused by abrupt width changes.

[0098] By performing the above three-point curvature radius calculation and smoothness scoring, the discrete pixel coordinate sequence is transformed into curvature confidence data containing geometric stability quantification indicators, realizing a high-precision description of the local bending morphology of the weld centerline, and providing a reliable geometric constraint basis for the subsequent dynamic scaling of the multi-scale sensing window.

[0099] Step S3: Using the local width estimate and curvature confidence score from the weld centerline skeleton data as the basis for dynamic scaling, three types of nested perception windows—adjacent core windows, transition buffer windows, and background reference windows—are constructed based on each anchor point on the centerline, generating a multi-scale local perception window set. Specifically, this includes: S3.1: Traverse the pixel coordinate sequence in the weld centerline skeleton data to extract the coordinates of the current centerline anchor point to be processed and its associated local width estimate and curvature confidence, and generate a single anchor point feature vector containing geometric attribute information.

[0100] Receive the weld centerline skeleton data output from step S2. This data includes a discrete pixel coordinate sequence arranged in spatial order, the local width estimate corresponding to each coordinate point, and the curvature confidence index, which serve as the geometric reference input for constructing a multi-scale local perception window.

[0101] Initialize the traversal index counter, set the starting index to 1, and the ending index to the total length of the centerline pixel coordinate sequence to ensure that every geometric anchor point within the entire length of the weld is processed without omission.

[0102] Extract the two-dimensional coordinates of the centerline anchor point corresponding to the current index from the weld centerline skeleton data. These coordinates define the geometric center position of the subsequent nested perception window in the image space domain.

[0103] Simultaneously extract the local width estimate bound to the current anchor point coordinates. This value represents the physical size of the weld width of the current weld section and directly determines the basic coverage area adjacent to the core window.

[0104] Read the curvature confidence associated with the current anchor point. This metric quantifies the degree of curvature and geometric stability of the weld centerline at that location and is used to adjust the window size to accommodate local topographic changes.

[0105] The extracted centerline anchor point coordinates, local width estimates, and curvature confidence scores are encapsulated into structured data units to form a single anchor point feature vector containing complete geometric attribute information.

[0106] Through the above-described traversal extraction and data encapsulation processing, the discrete weld centerline skeleton data generated in the previous step is transformed into a single anchor point feature vector with clear geometric semantics, realizing a refined mapping from the global skeleton to the local sensing unit, and providing an accurate input basis for the subsequent dynamic calculation of multi-level window scale parameters.

[0107] S3.2: Perform linear mapping operation based on the local width estimate in the single anchor point feature vector to calculate the base radius size of the adjacent core window, and perform nonlinear correction on the base radius size according to the curvature confidence to generate dynamic scale parameters of the core window that adapt to local morphological changes.

[0108] Receive the single anchor point feature vector generated in step S3.1. This vector contains the two-dimensional pixel coordinates of the current centerline anchor point, the local width estimate obtained by normal profile scanning, and the curvature confidence obtained by three-point curvature solution, and serves as the input data for calculating the dynamic scale of the adjacent core window.

[0109] The local width estimate is extracted from the feature vector of a single anchor point and used as the basic geometric parameter to characterize the physical size of the weld width. A linear mapping operation is then performed to determine the basic coverage area adjacent to the core window.

[0110] A base radius scaling factor is set, which is pre-calibrated based on the minimum resolvable size and maximum allowable weld width ratio of typical defects in stainless steel welds. This factor is used to convert the physical width into a window radius reference for the image pixel domain. Multiplying the base radius scaling factor by the local width estimate yields the base radius size immediately adjacent to the core window.

[0111] Through the above linear mapping operation, the discretized local width values ​​are transformed into a window base scale with clear physical meaning, thus realizing the initial adaptive following of the sensing window size to the changes in weld width.

[0112] The curvature confidence index in the feature vector of a single anchor point is obtained. This index quantifies the degree of bending and geometric stability of the weld centerline at the current anchor point, and serves as a nonlinear adjustment factor for correcting the base radius.

[0113] A nonlinear correction function based on curvature confidence is constructed to shrink the window in the high curvature region (low confidence) to avoid background noise interference, and to maintain or slightly expand the window in the low curvature region (high confidence) to enhance statistical robustness.

[0114] Using an exponentially decaying correction model, the curvature correction factor is calculated using the following formula:

[0115] in, This is the curvature correction factor, with a value range of (0,1]. This is the attenuation control constant, used to adjust the sensitivity of the window size to changes in curvature. The normalized curvature confidence level has a value range of [0,1], where 1 represents complete flatness and 0 represents extreme curvature.

[0116] When the curvature confidence C approaches 1, the exponential term approaches 0, the correction factor λ approaches 1, and the window size remains in the basic state determined by the width; when the curvature confidence C decreases, the exponential term increases, the correction factor λ decreases rapidly, and the window radius is forcibly shrunk.

[0117] The calculated basic radius dimension R base Multiplying the value by the curvature correction factor yields the dynamic scaling parameters of the core window, which are adaptively adjusted for geometric shape. Multiplying the base radius dimension by the curvature correction factor yields the dynamic scaling parameters R of the core window, which adapt to local topographic changes. core .

[0118] For the calculated R core Perform integer rounding and apply minimum radius constraints and maximum radius truncation to prevent the window size from being too small to contain effective pixels or too large to introduce too much background interference due to extreme curvature or width measurement errors.

[0119] The minimum radius threshold is set to 3 pixels to ensure the effectiveness of histogram statistics; the maximum radius threshold is set to 1 / 10 of the short side length of the image to limit computational complexity.

[0120] If R core If R is less than the minimum radius threshold, then it is forcibly assigned the minimum radius threshold; if R core If the value is greater than the maximum radius threshold, then the value will be forcibly assigned to the maximum radius threshold.

[0121] By combining linear mapping with nonlinear correction, the geometric features of the single anchor point in the previous step are transformed into dynamic scale parameters of the adjacent core window with spatial adaptability. This achieves the expected technical effect of maintaining a sufficient sampling window in the straight section of the weld to stabilize statistical characteristics and automatically shrinking the window in the curved section of the weld to avoid background noise interference. This provides a precise size reference for the subsequent construction of multi-level nested sensing windows.

[0122] For example, when processing a grayscale image of a stainless steel kitchenware annular weld seam with a resolution of 1280×1024, the base radius scaling factor k is set to 1.0, the attenuation control constant β is set to 2.0, the minimum radius threshold is 3 pixels, and the maximum radius threshold is 100 pixels.

[0123] Scenario 1: For a certain anchor point P1 in the straight section of the weld, the estimated local width W is... local The value is 16 pixels, and the curvature confidence level C is 0.95 (close to perfect flatness). First, the base radius R is calculated. base =1.0 × 16 = 16 pixels. Next, calculate the curvature correction factor λ = e (-2.0×(1-0.95)) =e -0.1 ≈0.905. Calculate the dynamic scale R of the core window. core =16 × 0.905 ≈ 14.48 pixels. After rounding and constraint checks, 14.48 is between 3 and 100, so R is finally determined. core The value is 14 pixels. This result indicates that in a flat and relatively wide weld area, the window maintains a large coverage area, which is beneficial for collecting sufficient grayscale samples for stable histogram statistics.

[0124] Scenario 2: For an anchor point P2 at a sharp bend in the weld, the estimated local width W is... local With a base radius of 12 pixels, the curvature confidence C drops to 0.40 due to severe bending. First, the base radius R is calculated. base=1.0 × 12 = 12 pixels. Next, calculate the curvature correction factor λ = e (-2.0×(1-0.40)) =e -1.2 ≈0.301. Calculate the dynamic scale R of the core window. core =12 × 0.301 ≈ 3.61 pixels. After rounding and constraint checks, 3.61 is between 3 and 100, so R is finally determined. core It is 4 pixels.

[0125] This result indicates that in the sharply curved region, the window radius shrinks significantly, effectively preventing the window from crossing the weld boundary and entering the background region, thereby preventing the background metallic luster from interfering with defect detection and significantly improving the signal-to-noise ratio of defect segmentation in the curved section.

[0126] Scenario 3: For an anchor point P3 with an extremely narrow weld and slight vibration, the estimated local width W is... local The value is 4 pixels, and the curvature confidence level C is 0.70. First, calculate the base radius RR. base =1.0 × 4 = 4 pixels. Next, calculate the curvature correction factor λ = e (-2.0×(1-0.70)) =e -0.6 ≈0.549. Calculate the dynamic scale R of the core window. core =4 × 0.549 ≈ 2.19 pixels. After rounding, this is 2 pixels, but less than the minimum radius threshold of 3 pixels, so a forced adjustment of R is necessary. core The value is 3 pixels. This result shows that even under moderate curvature and extremely narrow weld seams, the algorithm can still ensure that the window contains at least a certain number of pixels, maintaining the minimum data support for subsequent statistical feature calculations and avoiding statistical failures caused by excessively small windows.

[0127] S3.3: Using the core window dynamic scale parameter as a reference factor, multiply it by the preset overexpansion coefficient and background reference coefficient respectively to derive the expansion radius size of the transition buffer window and the outer radius size of the background reference window, and generate a multi-level window scale parameter set.

[0128] Receive the core window dynamic scale parameter output from step S3.2. This parameter represents the radius of the core sensing region adjacent to the weld ridge line and serves as the reference geometry for constructing multi-level nested windows.

[0129] The system reads the overexpansion coefficient and background reference coefficient from the preset parameter configuration library. The overexpansion coefficient is used to define the spatial range of the weld heat-affected zone and edge transition zone, and the background reference coefficient is used to define the sampling boundary of the pure substrate background area.

[0130] The dynamic scale parameter of the core window is multiplied by the overexpansion coefficient to calculate the expansion radius of the transition buffer window. This size ensures that the window covers the complete grayscale gradient area from the weld body to the substrate.

[0131] The core window's dynamic scale parameter is multiplied by the background reference coefficient to calculate the outer radius of the background reference window. This radius ensures that the window is completely located within a uniform background area outside the weld structure.

[0132] The calculated radius of the transition buffer window and the outer radius of the background reference window are rounded down to the nearest integer to adapt to the discrete coordinate characteristics of the image pixel grid and eliminate the sampling deviation caused by the sub-pixel size.

[0133] The core window dynamic scale parameters, the transition buffer window expansion radius size, and the background reference window outer radius size are encapsulated into a multi-level window scale parameter group containing three levels of radius values.

[0134] Through the above linear mapping and coefficient scaling processing, the core window dynamic scale parameters of the previous step are transformed into a multi-level window scale parameter group covering the weld body, transition zone and background area, realizing the precise quantitative definition of the spatial coverage of the local perception window, and providing a standardized geometric constraint basis for subsequent differential semantic state determination.

[0135] S3.4: Based on the centerline anchor point coordinates in the single anchor point feature vector and the multi-level window scale parameter group, construct concentric annular adjacent core windows, transition buffer windows and background reference windows in the spatial domain of the denoised and enhanced grayscale image, and generate three types of nested perceptual window instances for the current anchor point.

[0136] Receive the multi-level window scale parameter set output from step S3.3 and the single anchor point feature vector generated from step S3.1. The multi-level window scale parameter set includes the dynamic scale parameters of the adjacent core window, the expansion radius size of the transition buffer window, and the outer radius size of the background reference window. The single anchor point feature vector includes the pixel coordinates and local tangent direction angle of the current center line anchor point to be processed.

[0137] Based on the centerline anchor point coordinates and local tangent direction angle in the single anchor point feature vector, a local orthogonal coordinate system with the anchor point as the origin is constructed, where the X-axis extends along the weld tangent direction and the Y-axis extends along the weld normal direction, thus establishing the geometric reference framework for subsequent window construction.

[0138] Based on the dynamic scale parameter of the adjacent core window, a circular area with a radius equal to the dynamic scale parameter is drawn in the spatial domain of the denoised and enhanced grayscale image, with the center line anchor point as the center. This area is defined as the adjacent core window. The window mainly covers the weld pool body area and is used to capture the grayscale features of the defect core.

[0139] Based on the expansion radius of the transition buffer window, a concentric circular region with a radius equal to the expansion radius is drawn at the same center position, and the area occupied by the core window is removed to form an annular transition buffer window. This window covers the heat-affected zone of the weld and part of the substrate transition zone, and is used to evaluate the rate of change of grayscale gradient.

[0140] Based on the outer radius of the background reference window, a concentric circular region with a radius equal to the outer radius is drawn at the same center position. The area occupied by the inner transition buffer window is removed to form the outermost annular background reference window. This window is located entirely in the pure substrate area far away from the weld center and is used to extract the background statistical benchmark without interference.

[0141] The three concentric annular regions are mapped to the global pixel coordinate system of the denoising enhanced grayscale image. The set of all pixel indexes within the coverage area of ​​each window is extracted by the mask generation algorithm to ensure that the ownership of the pixels at the window boundary is clear and there is no overlap or omission.

[0142] The validity of the generated three types of nested perception window instances is validated to check whether the window exceeds the image boundary. If the window exceeds the boundary, mirror filling or truncation is used to correct the window range to ensure the integrity of subsequent statistical calculations.

[0143] By constructing and mapping concentric annular windows in the aforementioned spatial domain, the abstract scale parameters calculated in the previous step are transformed into specific pixel-level perception regions. This generates three types of nested perception window instances: adjacent core window, transition buffer window, and background reference window for the current anchor point. This achieves refined layered sampling of the local microstructure of the weld, providing a semantic perception basis with clear physical meaning for the subsequent generation of differentiated thresholds.

[0144] S3.5: Repeat the above window construction operation for all remaining centerline anchor points in the weld centerline skeleton data to integrate the three types of nested sensing window instances corresponding to all single anchor points and generate a multi-scale local sensing window set covering the entire weld area.

[0145] Receive the three types of nested sensing window instances generated in step S3.4 for the current anchor point. Each instance contains the spatial geometric definition data of the adjacent core window, transition buffer window, and background reference window, which serve as the basic unit for constructing a multi-scale local sensing window set.

[0146] Initialize an empty multi-scale local sensing window set data structure. This structure is used to store the window parameter group and spatial index information corresponding to all anchor points on the weld centerline, ensuring that subsequent steps can traverse in sequence and extract the statistical features of each local region.

[0147] Obtain the list of remaining unprocessed centerline anchor points in the weld centerline skeleton data. This list consists of the remaining elements after partial processing of the continuous weld centerline pixel coordinate sequence output by step S2 through steps S3.1 to S3.4, representing the geometric sampling points of the remaining part of the weld.

[0148] Perform an iterative traversal operation on the remaining list of centerline anchor points, select the next centerline anchor point to be processed in turn, extract its pixel coordinates, local width estimate and curvature confidence, and reconstruct a single anchor point feature vector containing complete geometric attribute information.

[0149] Based on the reconstructed single-anchor feature vector, the linear mapping and nonlinear correction operations in step S3.2 are repeated. The base radius of the core window adjacent to the local width estimate is calculated using the local width estimate, and the dynamic scale parameters of the core window that adapt to the current local morphology are generated by combining the curvature confidence.

[0150] Based on the logic of step S3.3, the core window dynamic scale parameter is used as the benchmark factor. By multiplying it by the preset overexpansion coefficient and background reference coefficient, the expansion radius of the transition buffer window and the outer radius of the background reference window corresponding to the current anchor point are derived, forming a new multi-level window scale parameter set.

[0151] Based on the centerline coordinates of the current anchor point and the newly generated multi-level window scale parameter set, concentric annular adjacent core windows, transition buffer windows, and background reference windows are constructed in the spatial domain of the denoised and enhanced grayscale image, generating three types of nested perceptual window instances for the remaining anchor point.

[0152] The newly generated three types of nested sensing window instances and their associated anchor point index information are added to the multi-scale local sensing window set data structure to achieve the accumulation and integration of local window data.

[0153] Determine if the remaining list of centerline anchor points has been completely traversed. If there are any unprocessed anchor points, continue the above iterative construction process; if all anchor points have completed window construction, terminate the iteration process.

[0154] Perform integrity checks on the multi-scale local perception window set data structure to ensure that the number of window instances in the set is consistent with the total number of anchor points in the weld centerline skeleton data, and that each window instance contains valid spatial coordinate range and hierarchical radius parameters.

[0155] Through the above iterative traversal and dynamic construction processing method, the window construction logic for a single anchor point in the previous step is extended to the entire weld centerline. The discrete geometric guidance information is transformed into a multi-scale local perception window set covering the entire weld area, realizing adaptive perception coverage of different geometric morphological regions within the entire length of the weld. This provides a complete spatial analysis foundation for subsequent differential threshold segmentation based on local semantic states.

[0156] Step S4: For each window within the multi-scale local perception window set, calculate the gray-level histogram peak-valley distribution, gradient magnitude cumulative ratio, and edge continuity score. Based on these statistical characteristics, determine whether the current local region belongs to a high-contrast flat segment, a low-contrast curved segment, or a multi-interference transition segment, and generate a local semantic state label sequence. Specifically, this includes: S4.1: Perform histogram statistical modeling on the gray values ​​of pixels within the adjacent core window in the multi-scale local perception window set to calculate the gray-level frequency distribution curve and extract the main peak position and valley depth parameters, generating gray-level histogram peak and valley distribution data that characterizes the local contrast characteristics.

[0157] Sub-step S4.1 aims to perform histogram statistical modeling on the grayscale values ​​of pixels within the adjacent core windows in the multi-scale local perceptual window set. This process calculates the grayscale frequency distribution curve and extracts the peak position and valley depth parameters, generating grayscale histogram peak-valley distribution data that characterizes local contrast properties. This step is located before the semantic state determination and directly relies on the geometric constraints of the nested perceptual windows generated in S3. Its output will serve as the basic input for gradient analysis in S4.2 and logical decision-making in S4.4.

[0158] Read the spatial coordinate range of the adjacent core window generated by S3.4 for the current centerline anchor point, extract the set of all pixel gray values ​​within the rectangular or circular area from the denoised and enhanced grayscale image, and construct a local grayscale sampling matrix.

[0159] Perform a traversal operation on the local grayscale sampling matrix, count the frequency of each grayscale level, and build a normalized local grayscale histogram, where the horizontal axis is the grayscale level index from 0 to 255, and the vertical axis is the probability density of the occurrence of the grayscale level within the window.

[0160] A Gaussian kernel function is used to smooth the original discrete histogram, eliminating histogram spikes caused by microscopic texture noise on the metal surface, and generating a continuous and smooth gray-level probability density distribution curve to ensure the stability of subsequent extreme value detection.

[0161] The first derivative zero-point search algorithm is executed on the smoothed probability density distribution curve to identify all local maxima. The two peaks with the highest amplitude are selected and marked as the background main peak and the weld foreground main peak, respectively. Their corresponding gray level coordinates and peak intensities are recorded.

[0162] Within the interval between the background peak and the foreground peak of the weld, search for local minima of the probability density distribution curve to determine the location of the valley bottom, calculate the depth difference between the gray level of the valley bottom and the gray levels of the two main peaks, and quantify the contrast significance of the local area.

[0163] Based on the extracted parameters of main peak position, peak intensity and valley depth, a multi-dimensional histogram statistical feature vector including mean, variance, skewness and kurtosis is constructed to form structured data representing the gray-scale distribution pattern of the current local area.

[0164] By using histogram statistical modeling and extreme value feature extraction, the spatial window data from the previous step is transformed into grayscale histogram peak-valley distribution data that characterizes local contrast properties. This enables a quantitative description of the local grayscale distribution morphology of the weld, providing crucial statistical basis for distinguishing between high-contrast straight sections and low-contrast curved sections.

[0165] S4.2: Perform multi-directional Sobel operator convolution operation on the transition buffer window region corresponding to the grayscale histogram peak and valley distribution data to calculate the gradient magnitude of each pixel in the window and perform cumulative normalization processing to generate gradient magnitude cumulative ratio data that reflects the degree of drastic texture change.

[0166] Multi-directional gradient feature extraction is performed on the pixel data within the transition buffer window region to quantify the degree of drastic change in local texture and generate cumulative gradient magnitude ratio data. This step follows the spatial region positioning information corresponding to the grayscale histogram peak-valley distribution data generated in S4.1, and performs refined texture analysis on the transition buffer window, a key region that includes weld edges and heat-affected zones.

[0167] Based on the set of pixel coordinates covered by the transition buffer window in the denoised and enhanced grayscale image, Sobel convolution kernel matrices are constructed in the horizontal, vertical and two diagonal directions to capture edge response features in different directions.

[0168] The Sobel convolution kernels in four directions are sequentially subjected to two-dimensional discrete convolution operations with the local gray-level matrix within the transition buffer window. The approximate values ​​of the first-order gray-level derivatives of each pixel in the four specific directions are calculated to generate a four-channel directional gradient component map.

[0169] Using the Pythagorean theorem or an approximation algorithm based on the sum of absolute values, the four directional gradient components of the same pixel are vector-synthesized to calculate the comprehensive gradient magnitude of the pixel, forming a gradient magnitude matrix that reflects the intensity of local grayscale changes.

[0170] The sum of gradient magnitudes of all valid pixels within the transition buffer window is used as the texture energy benchmark for the current local region, which is then used for subsequent normalization processing to eliminate the dimensional effects caused by differences in window size.

[0171] A gradient significance threshold is set, and pixels with gradient magnitudes exceeding this threshold are selected to form a high-gradient set. The ratio of the cumulative gradient magnitude of pixels in the high-gradient set to the sum of the gradient magnitudes of all pixels within the transition buffer window is calculated as the cumulative gradient magnitude ratio data. The calculated cumulative gradient magnitude ratio data is then subjected to linear mapping and smoothing filtering to suppress gradient abrupt changes caused by individual noise points, ensuring the stability and robustness of the ratio data.

[0172] By using the above-mentioned multi-directional S-operator convolution and normalized cumulative calculation processing method, the transition buffer window region determined in the previous step is transformed into gradient magnitude cumulative ratio data reflecting the degree of drastic texture change. This achieves a quantitative characterization of weld edge ambiguity and background interference intensity, providing a key texture dimension basis for subsequent differentiation between low-contrast curved sections and multi-interference transition sections.

[0173] S4.3: Utilize the background reference window edge pixels associated with the gradient magnitude cumulative ratio data to perform chain code tracing and curvature continuity calculation to evaluate the number of edge breaks and the consistency score of the direction, and generate edge continuity score data that quantifies the intensity of background interference.

[0174] High-gradient pixels on the boundary of the background reference window are extracted as seed points for edge tracking. Candidate edge pixels with gradient values ​​higher than a preset noise threshold are selected based on the gradient magnitude accumulation ratio data generated by S4.2, constructing an initial edge point set. An eight-neighborhood connectivity search is performed on each pixel in the initial edge point set. The edge direction is recorded using Freeman chain code encoding rules, converting the relative positional relationships of adjacent edge points into a discrete direction code sequence from 0 to 7, forming a preliminary edge chain code trajectory. Curvature continuity is calculated for the preliminary edge chain code trajectory. The local angle change rate is obtained by calculating the first-order difference of the chain code direction angle. A sliding window mechanism is used to count the number of direction abrupt changes per unit length, quantifying the smoothness and breakage risk of the edge path. An edge continuity evaluation function is constructed based on the local angle change rate and the number of direction abrupt changes. A penalty factor is introduced to weight and deduct scores for discontinuous breakpoints and violently jittery segments, calculating an edge continuity score reflecting the intensity of background interference. Through the above chain derivation process, the gradient magnitude data of the previous step is transformed into quantified edge continuity score data, which realizes the accurate measurement of the structural complexity of the background region and the degree of noise interference, and provides key semantic discrimination basis for the subsequent threshold optimization of multiple interference transition segments.

[0175] S4.4: Construct a multi-dimensional feature vector based on the grayscale histogram peak and valley distribution data, gradient magnitude cumulative ratio data, and edge continuity score data, and perform a logical matching judgment operation based on a preset rule base to determine whether the current local area belongs to a high-contrast flat segment, a low-contrast curved segment, or a multi-interference transition segment, and generate a local semantic state label sequence containing a unique state identifier.

[0176] The grayscale histogram peak-valley distribution data generated by sub-step S4.1, the gradient magnitude cumulative ratio data generated by sub-step S4.2, and the edge continuity score data generated by sub-step S4.3 are received as multi-dimensional feature input sources for determining the local semantic state of the current centerline anchor point.

[0177] The gray-level histogram peak-valley distribution data is normalized, and the gray-level difference between the main peak and the secondary peak is extracted as a local contrast index. The ratio of valley depth to main peak height is calculated as a bimodal separation index, thus constructing the first-dimensional feature component characterizing the gray-level distribution morphology of the weld area.

[0178] The gradient magnitude cumulative ratio data is truncated by a threshold, and the proportion of pixels exceeding the preset high gradient threshold is counted to generate a gradient sparsity index that reflects the degree of drastic change in local texture. A second-dimensional feature component is constructed to characterize the sharpness of the weld edge.

[0179] Linear mapping is performed on the edge continuity score data to convert the number of breakpoints obtained from chain code tracing into continuity confidence values ​​in the range of 0 to 1, thus constructing a third-dimensional feature component that characterizes background interference and structural integrity.

[0180] The first, second, and third feature components are sequentially concatenated to form a three-dimensional local semantic feature vector that includes contrast, gradient sparsity, and continuity confidence.

[0181] A pre-defined rule base based on expert experience is established, which defines the decision boundary conditions for three types of semantic states in the three-dimensional feature space: high-contrast straight segments, low-contrast curved segments, and multi-interference transition segments.

[0182] To determine the high-contrast flat segment, a logical AND condition is set where the local contrast index is greater than a first preset threshold and the continuity confidence is greater than a second preset threshold. When the three-dimensional local semantic feature vector meets this condition, the current local region is determined to be a high-contrast flat segment.

[0183] To determine low-contrast curved segments, a logical combination condition is set where the local contrast index is less than a third preset threshold and the gradient sparsity index is in the medium range. When the three-dimensional local semantic feature vector meets this condition, the current local region is determined to be a low-contrast curved segment.

[0184] To determine the multi-interference transition segment, a logical OR condition is set where the continuity confidence is less than the fourth preset threshold or the gradient sparsity index is higher than the fifth preset threshold. When the three-dimensional local semantic feature vector satisfies any of the sub-conditions, the current local region is determined to be a multi-interference transition segment.

[0185] The priority arbitration mechanism is implemented. If the feature vector of the current local region satisfies the determination conditions of multiple states at the same time, the final semantic state is determined according to the priority order of multi-interference transition segment over low-contrast curved segment and low-contrast curved segment over high-contrast straight segment.

[0186] Each determined semantic state is assigned a unique integer-type state identifier, where a high-contrast flat segment is identified by 1, a low-contrast curved segment by 2, and a multi-interference transition segment by 3.

[0187] The unique state identifier of the current centerline anchor point is stored in the corresponding index position of the local semantic state label sequence to complete the semantic classification of a single anchor point.

[0188] Iterate through all remaining anchor points in the weld centerline skeleton data, and repeat the above feature vector construction, rule matching, and status label assignment operations until the entire perception window is covered.

[0189] By constructing multi-dimensional feature vectors and using a logical matching and decision-making process based on a preset rule base, the statistical feature data obtained in the previous step is transformed into a sequence of local semantic state labels with clear physical meaning. This enables refined classification of complex local morphology of welds and provides an accurate decision-making basis for the selection of subsequent differentiated threshold generation mechanisms.

[0190] For example, in the weld inspection scenario of a certain type of stainless steel kitchenware, the first preset threshold for the local contrast index is set to 45 gray levels, the second preset threshold is 0.85, the third preset threshold is 20 gray levels, the fourth preset threshold is 0.6, and the fifth preset threshold is 0.7. For a certain centerline anchor point located in the straight section of the weld, the gray level histogram in the adjacent core window shows that the main peak is at 180, the secondary peak is at 120, the local contrast index is 60, the valley depth ratio is 0.4, and the normalized first-dimensional feature component is 0.6; in the gradient amplitude accumulation ratio in the transition buffer window, the proportion of high gradient pixels is 0.15, and the second-dimensional feature component is 0.15; the background reference window edge continuity score is 0.92, and the third-dimensional feature component is 0.92. The three-dimensional local semantic feature vector is constructed as [0.6, 0.15, 0.92]. Substituting into the preset rule base, since the original value 60 corresponding to a local contrast of 0.6 is greater than 45, and the continuity confidence of 0.92 is greater than 0.85, it meets the criteria for a high-contrast straight segment and does not meet other higher priority conditions. Therefore, the anchor point is determined to be a high-contrast straight segment and assigned state identifier 1. For another anchor point located in the heat-affected zone of the weld, its local contrast index is 15, its gradient sparsity index is 0.5, and its continuity confidence is 0.75. The feature vector is constructed as [0.15, 0.5, 0.75]. Since the local contrast of 15 is less than 20, and the gradient sparsity of 0.5 is in the medium range, it is determined to be a low-contrast curved segment and assigned state identifier 2. For an anchor point with scratch interference, its continuity confidence drops to 0.4. Although the contrast is high, it is preferentially determined to be a multi-interference transition segment because it meets the condition that the continuity confidence is less than 0.6, and assigned state identifier 3. The final generated local semantic state label sequence accurately reflects the morphological changes of the weld along the centerline direction, ensuring the pertinence of the subsequent threshold generation strategy.

[0191] like Figure 3 As shown, step S5: Based on the classification results of different semantic states in the local semantic state label sequence, a differentiated threshold generation mechanism is activated. For high-contrast flat segments, a weighted local mean shift method is used; for low-contrast curved segments, a one-dimensional gray-level trend fitting residual compensation term is introduced; and for multi-interference transition segments, a bimodal search strategy based on neighborhood gray-level entropy weighting is activated to generate an adaptive threshold discrete point set. Specifically, this includes: S5.1: Based on the classification label of the high-contrast flat segment in the local semantic state label sequence, a weighted local mean shift processing is performed on the gray-level histogram peak-valley distribution data adjacent to the core window to suppress baseline drift caused by metallic luster and extract stable baseline gray-level values, generating the initial threshold parameter of the high-contrast flat segment.

[0192] Obtain the centerline anchor point index of the high-contrast flat segment in the local semantic state label sequence, and extract the gray-level histogram peak and valley distribution data of the adjacent core window area corresponding to the anchor point as the input benchmark.

[0193] The probability density function is reconstructed for the gray-level histogram data adjacent to the core window, the normalized frequency of each gray level is calculated, and a discrete probability distribution model reflecting the statistical characteristics of local pixels is constructed.

[0194] Based on the discrete probability distribution model, the kernel density estimation method is used to smooth the histogram to eliminate the small fluctuations caused by quantization noise and generate a continuous and unimodal gray-level probability density curve.

[0195] Locate the gray center position corresponding to the main peak on the continuous gray probability density curve, and define it as the local background baseline gray value. This value represents the main brightness level of the metal substrate or weld body in the current high contrast area.

[0196] The absolute deviation of all pixel gray values ​​within the immediate core window from the local background baseline gray value is calculated, and these deviation values ​​are weighted and averaged. The weight coefficient is determined by the reciprocal of the Euclidean distance from the pixel to the center line anchor point to enhance the contribution of the central region.

[0197] The local background baseline gray value is linearly combined with the weighted local mean offset, and a preset contrast enhancement factor is introduced to adjust the sensitivity of the threshold to the defect edge, generating an initial adaptive threshold candidate value.

[0198] Boundary constraint checks are performed on the initial adaptive threshold candidate values ​​to ensure that their value range falls within the valley range of the gray-level histogram of the core window. If they exceed the range, they are forcibly truncated to the nearest valid valley gray level.

[0199] By using weighted local mean shift processing, the grayscale histogram peak and valley distribution data from the previous step is transformed into an initial threshold parameter for a high-contrast flat segment with high robustness. This effectively suppresses baseline drift caused by metallic luster and ensures the stability and accuracy of threshold segmentation in uniformly illuminated areas.

[0200] S5.2: Using the classification identifier of the low-contrast bending segment and the cumulative ratio data of gradient amplitude within the transition buffer window, perform a one-dimensional grayscale trend fitting operation along the centerline direction and calculate the fitting residual to compensate for the nonlinear grayscale decay caused by the change in weld curvature, and generate dynamic compensation threshold parameters for the low-contrast bending segment.

[0201] The system receives the classification identifier of the low-contrast curved segment and the cumulative gradient magnitude ratio data within the transition buffer window as input conditions for calculating the dynamic compensation threshold.

[0202] Extract the pixel coordinate sequence of the current anchor point on the weld centerline skeleton, and extend the sampling interval to both sides along the tangent direction of the centerline by a preset length to construct a one-dimensional grayscale trend analysis window.

[0203] Within the one-dimensional grayscale trend analysis window, a local arc length coordinate system is established along the tangent direction with the center line anchor point as the origin. The grayscale intensity value and the corresponding arc length position parameter of each sampling point under this coordinate system are extracted.

[0204] The least squares method was used to perform polynomial fitting on the extracted gray intensity values ​​and arc length position parameters to construct a benchmark curve model describing the local nonlinear gray intensity decay trend.

[0205] The fitting residual is calculated using the following formula to quantify the degree of deviation of the actual gray-level distribution from the ideal smooth trend:

[0206] in, To fit the root mean square value of the residuals, The total number of sampling points. For the first The actual gray value of each sampling point For the fitted curve in the th... The predicted grayscale value at each sampling point.

[0207] By combining the cumulative gradient magnitude ratio data within the transition buffer window, the calculated fitting residuals are weighted and corrected to eliminate the artificially high residuals caused by background texture noise. The dynamic compensation threshold parameter is obtained by adding the product of the basic local mean threshold with the weighted fitting residuals, the cumulative gradient magnitude ratio, the curvature confidence score, and other factors.

[0208] The curvature correction factor C is adjusted based on the local curvature confidence level. When the curvature is large and causes severe asymmetry in the gray-scale distribution, the compensation weight is increased to enhance the sensitivity to defect edges.

[0209] The calculated dynamic compensation threshold parameter is linearly superimposed with the basic local mean threshold to generate the final adaptive threshold for the current low-contrast bending segment anchor point.

[0210] Through the above chain derivation process, the low-contrast semantic state and gradient statistical features of the previous step are transformed into dynamic compensation threshold parameters containing curvature compensation information, which realizes effective compensation for grayscale nonlinear attenuation caused by weld geometric bending and significantly improves the detection integrity of small defects in low-contrast areas.

[0211] S5.3: For the classification labels of multi-interference transition segments and the edge continuity score data within the background reference window, activate the bimodal search strategy based on neighborhood gray-level entropy weighting. This strategy can lock the best segmentation valley within the specified interval on both sides of the main peak of the histogram and remove scratch noise interference, generating optimized threshold parameters for multi-interference transition segments.

[0212] For local regions identified as multi-interference transition segments, grayscale pixel data from the adjacent core window, transition buffer window, and background reference window are extracted and used as the original input source for threshold calculation. Histogram statistical operations are performed on the pixel grayscale values ​​within the background reference window to construct a local background grayscale probability distribution model, quantifying the texture complexity and noise floor level of the metal substrate surface. Based on the local background grayscale probability distribution model, the Shannon information entropy value of the background region is calculated to characterize the degree of disorder and interference intensity of grayscale changes within the current local window. The grayscale entropy value of the background reference window is calculated using the following formula:

[0213] in, The grayscale entropy value of the background reference window. This represents the total number of gray levels (usually 256). grayscale Normalized frequency probability of appearance within the background reference window.

[0214] The calculated gray-level entropy value H is mapped to a noise suppression weight coefficient. A higher entropy value indicates more severe background interference, and a higher noise penalty weight is assigned; conversely, a lower entropy value is assigned a lower weight. The original gray-level histogram adjacent to the core window is weighted and smoothed using the noise suppression weight coefficient to suppress high-frequency random fluctuation peaks caused by scratches or reflections, generating a denoised target histogram. In the denoised target histogram, the high-gray-level main peak corresponding to the weld metal body and the low-gray-level secondary peak corresponding to defects or shadows are identified, determining the characteristic interval of the bimodal distribution. Within the valley search interval between the high-gray-level main peak and the low-gray-level secondary peak, a local minimum traversal search is performed to find the candidate set of valley points with the lowest gray-level frequency. Edge continuity score data is introduced as a search constraint. If the edge continuity score is lower than a preset threshold, the width of the valley search interval is expanded to accommodate the histogram broadening effect caused by interference; if the score is higher than the preset threshold, the search interval is narrowed to improve positioning accuracy. For each candidate valley location found, the sum of the absolute values ​​of the slopes on its left and right sides is calculated, and the point with the most drastic slope change and the lowest gray-level frequency is selected as the optimal segmentation valley. Based on the gray-level value corresponding to the optimal segmentation valley, fine-tuning compensation is performed using the gradient magnitude accumulation ratio data within the transition buffer window to generate the final optimized threshold parameters for the multi-interference transition segment. By employing a bimodal search strategy based on neighborhood gray-level entropy weighting, the histogram statistical features under complex background interference are transformed into a robust optimal segmentation threshold, achieving the technical effect of effectively removing scratch noise and accurately locking defect boundaries in the multi-interference transition segment.

[0215] For example, when processing a local area of ​​a stainless steel weld image with obvious mechanical scratch interference, this area is identified as a "multi-interference transition section" in step S4. 225 pixels are extracted from the background reference window (radius 15 pixels) of this area, and their grayscale histogram is calculated. Assuming the grayscale range is 0-255, the frequency p of each grayscale level is calculated. iSubstituting into the entropy calculation formula above, if the background is relatively cluttered, the calculated grayscale entropy H value is 6.8 bits. The maximum entropy threshold is set to 7.0, and the minimum entropy threshold to 3.0. H=6.8 is mapped to a noise suppression weighting coefficient w=0.85. This weighting coefficient is used to perform Gaussian weighted smoothing on the original histogram within the immediate core window (radius of 8 pixels), with a standard deviation σ set to 2.0. The smoothed histogram shows that the sharp noise peak originally located at grayscale level 180 is significantly suppressed, while the main weld peak near grayscale level 120 and the defect peak near grayscale level 40 remain clear. The main peak position is determined to be 120, the secondary peak position to be 40, and the search interval is set to [40, 120]. Since the edge continuity score of this region is 0.6 (below the threshold of 0.75), the interference is considered strong. The search interval is expanded by 10 grayscale levels to both sides, becoming [30, 130]. The lowest frequency point was found by traversing the interval and identifying gray level 75 as the lowest frequency. The slope to its left is -0.05, and the slope to its right is 0.08, with the sum of the absolute values ​​of the slopes being 0.13, satisfying the minimum condition. The cumulative gradient magnitude ratio within the transition buffer window was read as 0.4. According to the preset compensation rule, when the gradient ratio is between 0.3 and 0.5, the threshold is finely adjusted downwards by two gray levels. Therefore, the final optimized threshold parameter is 75-2=73. This threshold successfully avoids the scratch noise interference band between gray levels 80-90, accurately separating real micro-pore defects (gray level approximately 50-60) from the background without misjudging scratches as defects, significantly improving the segmentation signal-to-noise ratio in this complex region.

[0216] S5.4: Integrating the initial threshold parameters of the high-contrast straight segment, the dynamic compensation threshold parameters of the low-contrast curved segment, and the optimized threshold parameters of the multi-interference transition segment, perform multi-source threshold fusion and spatial coordinate mapping operations to eliminate threshold abrupt changes at the boundaries of different semantic states and ensure spatial continuity, thereby generating an adaptive threshold discrete point set.

[0217] The system receives initial threshold parameters for high-contrast straight sections, dynamic compensation threshold parameters for low-contrast curved sections, and optimized threshold parameters for multi-interference transition sections. Combining these with the spatial coordinate indices of each anchor point in the weld centerline skeleton data, a multidimensional discrete dataset containing location information and threshold strength is constructed. The semantic state labels of adjacent anchor points in the multidimensional discrete dataset are validated for consistency. Transition anchor point pairs located at the boundaries of different semantic states are identified and marked as potential threshold mutation risk areas. For homomorphic anchor points in non-boundary areas, their original threshold parameters generated through a differentiation mechanism are directly retained as local baseline threshold points, ensuring the purity of the physical meaning of threshold generation within a single semantic region. For transition anchor point pairs marked as potential threshold mutation risk areas, the absolute value of the threshold difference between the two anchor points and the spatial Euclidean distance are extracted to calculate the local threshold gradient modulus, quantifying the drastic change of the threshold in the spatial domain. When the local threshold gradient modulus exceeds a preset smoothness constraint threshold, a linear interpolation correction factor based on inverse distance weighting is introduced to perform a weighted average of the thresholds of the two anchor points, generating a smooth threshold intermediate value for the transition zone to suppress threshold step phenomena caused by semantic classification boundary jitter. An anchor point threshold mapping matrix is ​​established in a global coordinate system. All anchor point threshold parameters, after smoothing correction, are filled into the corresponding positions of the sparse matrix according to their pixel row and column coordinates. Uncovered areas are filled with null values, forming a preliminary adaptive threshold discrete point set. A neighborhood connectivity check is performed on this discrete point set to remove isolated and invalid anchor points caused by image edge cropping or interrupted centerline extraction, ensuring that the threshold distribution topology remains consistent with the geometry of the weld centerline. Through the above multi-source threshold fusion and spatial coordinate mapping operations, the scattered and potentially abrupt threshold parameters from the previous step are transformed into a spatially continuous and logically consistent adaptive threshold discrete point set, achieving the expected technical effect of eliminating threshold abrupt changes at the boundaries of different semantic states and ensuring spatial continuity.

[0218] Step S6: Map the adaptive threshold discrete point set to a continuous threshold surface covering the entire image using a bicubic interpolation algorithm, and perform pixel-by-pixel thresholding segmentation between the continuous threshold surface and the original grayscale image to generate a binary mask image of the weld defect. Specifically, this includes: S6.1: Perform gridded resampling on the adaptive threshold discrete point set to construct a regular sparse matrix containing pixel coordinate indices and corresponding threshold intensities, generating the threshold grid data to be interpolated.

[0219] Receive the adaptive threshold discrete point set generated in step S5. This dataset contains the two-dimensional pixel coordinates of each sampling point on the weld centerline and its corresponding optimal segmentation threshold intensity value, which serves as the sparse control node for constructing the global threshold surface.

[0220] Establish a blank two-dimensional grid matrix with the same size as the original denoised and enhanced grayscale image, initialize the threshold storage units of all grid nodes to null or default placeholders, and establish the spatial index framework of the threshold grid data to be interpolated.

[0221] Iterate through each data item in the set of discrete points with adaptive threshold, extract the row and column indices of the current anchor point in the image coordinate system, and map them to the corresponding discrete grid node positions in the blank two-dimensional grid matrix.

[0222] The extracted anchor point threshold strength values ​​are written into the mapped grid node storage unit to complete the resampling and positioning of sparse control points on the regular grid, forming a sparse threshold matrix that contains only the effective threshold information at the centerline anchor points.

[0223] For empty areas in the grid that are not covered by anchor points, a neighborhood search strategy is performed to identify the pixels to be interpolated, and the distribution of the nearest valid anchor points around each empty area is recorded to provide a local support set for subsequent bicubic interpolation.

[0224] Boundary condition processing is performed on the sparse threshold matrix. For regions located at the image edge and lacking sufficient neighborhood anchors, the nearest neighbor copying method is used to fill the boundary threshold, ensuring the integrity of the grid data and preventing boundary overflow effects during the interpolation process.

[0225] By using a gridded resampling process, the unstructured adaptive threshold discrete point set generated in the previous step is transformed into interpolation threshold grid data with a regular row and column index structure. This achieves the format conversion from discrete semantic guide points to the basic data for constructing continuous spatial surfaces, providing a standardized input data structure for the high-precision bicubic interpolation operation in step S6.2, and ensuring the topological consistency and computational feasibility of the threshold surface in spatial distribution.

[0226] S6.2: Perform bicubic interpolation algorithm operation based on the threshold grid data to be interpolated, and use the gray-level gradient information of the sixteen neighboring control points to calculate the smooth threshold estimate of the non-anchor position, and generate a continuous threshold surface matrix covering the entire map range.

[0227] Based on the spatial distribution characteristics of discrete anchor points in the threshold grid data to be interpolated, a regularized two-dimensional interpolation grid coordinate system is constructed to map the non-uniformly distributed anchor point coordinates to a unified pixel index space, thus establishing the control point topology required by the bicubic interpolation algorithm.

[0228] For a non-anchor pixel to be calculated, the 16 nearest known threshold anchors in its surrounding neighborhood are retrieved as a set of control points. These 16 control points form a 4×4 local matrix, covering a range of two pixel units above, below, left, and right of the target pixel, ensuring the integrity of the effective support domain of the interpolation kernel function.

[0229] Calculate the normalized relative coordinates of the target pixel relative to the center of the nearest neighbor control point, and obtain the horizontal offset u and the vertical offset v respectively. The values ​​of u and v are both limited to the interval [-0.5, 0.5], which provides standardized input variables for the subsequent weight calculation of the bicubic basis function.

[0230] Using the bicubic (x) convolution kernel function The interpolation weighting coefficients for four adjacent control points in the horizontal and vertical directions are calculated separately. This kernel function is defined as a piecewise polynomial and is used to balance the smoothness and edge preservation ability of the interpolation results. Its mathematical expression is as follows:

[0231] in, Represents the normalized relative distance, when When the value is less than 1, a nearest neighbor weighted strategy is used to preserve local details. When a distant neighbor attenuation strategy is used to suppress the ringing effect, The time weight is set to zero to limit the scope of influence.

[0232] Using the calculated horizontal and vertical weight vectors, combined with the threshold intensity values ​​in the 4×4 control point matrix T, matrix multiplication is performed to synthesize the final threshold estimate at the target pixel. The specific calculation formula is as follows:

[0233] in, The smoothed threshold estimate obtained through interpolation. It is a column vector containing BiCubic weights in four horizontal directions. It is a column vector containing BiCubic weights in four vertical directions. Given a 4×4 local threshold intensity matrix, smooth interpolation in two-dimensional space is achieved through two matrix-vector multiplications.

[0234] Traverse all non-anchor pixel positions in the entire image, and repeatedly perform the above operations of control point retrieval, relative coordinate calculation, weight coefficient solution and matrix synthesis to gradually fill the blank areas in the threshold grid, ensuring that each pixel obtains a dynamic threshold intensity that is adapted to its spatial position.

[0235] Boundary overflow checks and numerical truncation are performed on the generated full-image threshold matrix. Abnormal thresholds that exceed the dynamic range [0,255] of the original grayscale image are forced to be clamped to the legal range, eliminating numerical oscillations caused by the sidelobe effect of the interpolation kernel function, and generating a continuous threshold surface matrix covering the entire image range.

[0236] By using bicubic interpolation, the sparse adaptive threshold discrete point set generated in the previous step is transformed into a smooth threshold surface with second-order continuous derivatives. This enables spatial mapping from discrete semantic guide points to continuous pixel-level segmentation benchmarks, solving the technical problem that traditional global thresholds cannot adapt to changes in the local geometric shape of welds. This significantly improves the positioning accuracy and segmentation continuity of multi-scale defect edges.

[0237] For example, for a denoising and enhanced grayscale image of a stainless steel kitchenware weld seam with a resolution of 1920×1080, after processing in step S5, approximately 300 adaptive threshold anchor points distributed along the weld seam centerline are obtained. In step S6.1, these anchor points are mapped to a regular 1920×1080 grid to form a sparse threshold matrix. For the image coordinates (960, 540...)... For non-anchor pixels, retrieve 16 anchor control points within their surrounding 4×4 neighborhood. Assume the nearest neighbor anchor point is located at (958, 538). The normalized relative coordinates u=0.4 and v=0.6 were calculated. Substituting these values ​​into the BiCubic kernel function, the horizontal weight vector W(u)=[0.064,0.784,0.144,0.008] and the vertical weight vector W(v)=[0.028,0.648,0.288,0.036] were calculated. Assuming the threshold intensity value at the corresponding position in the local 4×4 threshold matrix T is distributed between 110 and 130, the interpolation threshold for this pixel was calculated to be 121.5 using the matrix multiplication method described above. This operation was performed on all pixels in the entire image, taking approximately 45ms (based on an embedded ARM Cortex-A72 processor). In the generated continuous threshold surface matrix, the threshold gradient between adjacent pixels was smooth, without any step-like abrupt changes. Tests showed that, compared to the nearest neighbor interpolation method, the threshold surface generated by bicubic interpolation improved the accuracy of edge pixel assignment for micropores (diameter less than 0.5 mm) in welds, effectively reduced the jagged defect contour caused by threshold jumps, and did not introduce additional artifact noise, ensuring the stability of subsequent binarization processing.

[0238] S6.3: Perform spatial alignment verification on the continuous threshold surface matrix to ensure that the row and column indices of each pixel in the surface matrix strictly match the pixel coordinates of the original grayscale image, and generate a spatially registered dynamic threshold reference image.

[0239] Receive the continuous threshold surface matrix generated by step S6.2, which contains the full-map range smooth threshold estimate calculated based on the bicubic interpolation algorithm, as the input data object for spatial alignment verification processing.

[0240] Obtain the original pixel dimension information of the denoised and enhanced grayscale image, including the image width W, height H, and the origin definition of the pixel coordinate system, and establish a reference frame for spatial registration.

[0241] Perform boundary consistency checks on the row and column indices of the continuous threshold surface matrix to verify whether the number of rows is strictly equal to the image height H and the number of columns is strictly equal to the image width W, ensuring that the spatial coverage of the data structure completely overlaps with the original image.

[0242] For non-finite values ​​(such as NaN or Inf) that may exist in the continuous threshold surface matrix due to interpolation boundary effects, a neighborhood mean filling repair operation is performed to replace abnormal pixels with threshold estimates in the effective neighborhood to ensure the numerical continuity of the threshold surface.

[0243] Establish from the continuous threshold surface matrix coordinates (u,v) To denoise and enhance grayscale image coordinates (x, y) The one-to-one mapping relationship confirms that both use the same top-left origin coordinate system and the same pixel spacing unit, eliminating the risk of spatial misalignment caused by differences in coordinate system definition.

[0244] If a subpixel-level geometric offset is detected between the continuous threshold surface matrix and the denoised and enhanced grayscale image, the translation deviation between the two is calculated based on the phase correlation method, and a subpixel-precision rigid translation correction is performed on the threshold surface matrix to make the threshold distribution center and the weld structure center coincide precisely in space.

[0245] The corrected continuous threshold surface matrix is ​​subjected to data type normalization processing to constrain its numerical range to the same dynamic range as the denoised and enhanced grayscale image, thus preventing subsequent comparison errors caused by data type mismatch.

[0246] The continuous threshold surface matrix, after boundary checks, outlier repair, coordinate mapping verification, and geometric correction, is encapsulated into a spatially registered dynamic threshold reference image.

[0247] Through the above spatial alignment verification process, the interpolation threshold data generated in the previous step is transformed into a dynamic threshold reference image that is strictly consistent with the original image in terms of spatial position, size specifications and numerical benchmark. This achieves a precise pixel-level correspondence between the threshold surface and the weld defect features, providing a judgment basis with no geometric distortion and high spatial consistency for subsequent pixel-by-pixel binarization segmentation.

[0248] S6.4: Perform a pixel-by-pixel grayscale comparison operation based on the spatially registered dynamic threshold reference image and the denoised and enhanced grayscale image to determine whether the grayscale value of each pixel exceeds the dynamic threshold intensity at its corresponding position, and generate an initial weld defect binarization logic matrix.

[0249] Read the local adaptive threshold intensity value corresponding to each pixel coordinate in the spatially registered dynamic threshold reference image, and construct a threshold matrix with the same row and column dimensions as the denoised and enhanced grayscale image.

[0250] Iterate through each pixel in the denoised and enhanced grayscale image and obtain the grayscale response value of the current pixel in the spatial domain.

[0251] Extract dynamic threshold baseline data from the threshold matrix that is strictly consistent with the row and column index of the current pixel.

[0252] Perform pixel-by-pixel numerical comparison logic operations to determine whether the grayscale response value of the current pixel is less than its corresponding dynamic threshold baseline data.

[0253] When the grayscale response value is less than the dynamic threshold reference data, the pixel is determined to belong to the weld defect area or the low reflectivity background area, and the element at the corresponding position in the initial weld defect binarization logic matrix is ​​assigned the logical truth value 1.

[0254] When the grayscale response value is greater than or equal to the dynamic threshold reference data, the pixel is determined to belong to the normal weld metal surface or the high reflectivity substrate area, and the element at the corresponding position in the initial weld defect binarization logic matrix is ​​assigned the logical false value 0.

[0255] A parallel processing mechanism is used to simultaneously perform the above comparison and assignment operations on all pixels of the image, ensuring full accuracy. Figure 2 Real-time performance and consistency of value-based processing.

[0256] By using a pixel-by-pixel grayscale comparison processing method, the continuous threshold surface and the denoised and enhanced grayscale image generated in the previous step are transformed into an initial weld defect binarized logical matrix that reflects the topological structure of the defect distribution, thereby achieving the expected technical effect of refined preliminary defect segmentation based on local semantic perception.

[0257] S6.5: Perform data type conversion and format encapsulation processing on the initial weld defect binarized logic matrix to map the logical truth value to the standard single-channel mask pixel value and retain the spatial geometric features, thereby generating a weld defect binarized mask image.

[0258] Step S7: Based on the spatial location information of the weld centerline skeleton data, perform centerline-guided morphological post-processing on the binary mask image of weld defects. Perform hole filling and burr trimming operations only within the centerline neighborhood and forcibly remove isolated noise points far from the centerline to generate an optimized weld defect detection image. Specifically, this includes: S7.1: Based on the pixel coordinate sequence and local width estimate in the weld centerline skeleton data, perform normal distance field construction and dynamic buffer generation processing to expand the discrete skeleton points into a continuous effective neighborhood mask covering the weld width and heat-affected zone, and generate a spatial constraint range matrix guided by the centerline.

[0259] The system receives the pixel coordinate sequence, local width estimate, and curvature confidence score from the weld centerline skeleton data as initial input parameters for constructing the spatial constraint range. A discrete point traversal operation is performed on the pixel coordinate sequence to extract the two-dimensional image coordinates of the current anchor point and its corresponding normal direction vector, establishing a local geometric reference system.

[0260] The half-width radius adjacent to the core window is calculated based on the local width estimate. This radius is defined as half the local width plus a preset safety margin coefficient to ensure coverage of the main weld pool area. The base radius is nonlinearly corrected based on the curvature confidence level. In areas with large curvature, the search range is appropriately expanded to compensate for positioning errors caused by geometric distortion, generating dynamically adjusted core window scale parameters. Using the core window scale parameters as a benchmark, and multiplying them by preset overexpansion factors and background reference factors, the outer boundary radii of the transition buffer window and the background reference window are derived, forming a multi-level concentric ring structure of scale parameter sets.

[0261] Within the spatial domain of the denoised and enhanced grayscale image, concentric annular regions are drawn using the current anchor point coordinates as the center and the aforementioned multi-level scale parameter set. Pixels inside the annulus are marked as effective neighbor pixels, while pixels outside are excluded from the background. The above window construction and marking operations are repeated for all remaining anchor points in the weld centerline skeleton data. The effective neighbor pixel sets generated by all single anchor points are then merged using a logical OR operation. Morphological closing operations are performed on the merged binarized neighborhood mask to fill the tiny gaps caused by the discrete sampling of the centerline, ensuring the spatial connectivity and integrity of the effective neighborhood.

[0262] By constructing a normal distance field and generating a dynamic buffer, discrete skeleton points are expanded into a continuous and effective neighborhood mask covering the weld width and heat-affected zone, generating a spatial constraint range matrix guided by the centerline. This achieves precise spatial definition of the subsequent defect detection area and significantly reduces background noise interference.

[0263] S7.2: The spatial constraint range matrix guided by the centerline is used to perform a logical AND operation masking process on the binary mask image of the weld defect to separate the candidate defect connected domains located in the effective neighborhood and mark the isolated noise regions located outside the constraint range, thereby generating a spatially filtered defect logic graph to be optimized.

[0264] Receive the spatial constraint range matrix guided by the centerline generated in step S7.1. This matrix is ​​a binary logic mask with the same size as the denoised and enhanced grayscale image. Pixels with a value of 1 constitute an effective neighborhood containing the weld width and heat-affected zone, while pixels with a value of 0 are identified as background or non-interest areas.

[0265] Obtain the weld defect binarized mask image output by step S6. In this image, the white area with a pixel value of 255 represents the initially detected suspected defect connected region, and the black area with a pixel value of 0 represents the background or normal metal surface.

[0266] A pixel-by-pixel logical AND operation is performed on the binary mask image of the weld defect and the spatial constraint range matrix guided by the center line to construct a spatial filtering operator, which retains only pixels that simultaneously meet the dual conditions of "being judged as a defect" and "being located within the effective neighborhood of the weld".

[0267] During the logical AND operation, for any coordinate position (i,j) If the pixel value of the defect mask at that position is 255 and the pixel value of the spatial constraint matrix at that position is 1, then the output result at that position remains 255, and it is confirmed as a candidate defect pixel.

[0268] If the defect mask is at position (i,j) The pixel value is 255, but the pixel value of the spatial constraint matrix at this position is 0, indicating that the suspected defect is located in the outer region where the normal distance of the weld centerline exceeds the preset threshold. It is determined to be background noise or artifact far away from the main body of the weld, and the output result is forcibly set to 0 at this position.

[0269] If the defect mask is at position (i,j) The pixel value is 0, and the output result remains 0 at this position regardless of the value of the spatial constraint matrix, ensuring that non-defect areas are not erroneously activated.

[0270] Traverse all pixel coordinates of the entire image, complete the logical masking process for the entire image range, and generate an intermediate spatially filtered binary image. At this point, isolated bright noise points located in the background area of ​​the original image have been completely removed.

[0271] After spatial filtering, a connected component labeling algorithm is performed on the binary image. An eight-neighbor search strategy is used to identify all interconnected white pixel sets. A unique label ID is assigned to each independent connected component, and a list of pixel coordinates contained therein is recorded.

[0272] Calculate the minimum bounding rectangle and centroid coordinates of each marked connected component, and map the centroid coordinates back to the spatial constraint range matrix guided by the centerline for secondary verification to confirm whether the main body of the connected component truly falls within the effective neighborhood.

[0273] For connected domains whose centroids are located within the effective neighborhood but whose edges extend beyond the neighborhood, their complete shape is preserved to maintain the integrity of the defect geometry and avoid distortion of defect area measurement due to excessive clipping.

[0274] For original defective connected regions that are completely outside the spatial constraints (i.e., all pixels are 0 after a logical AND operation), they are marked as "isolated noise regions" and their original coordinate indices are recorded for subsequent tracing or statistical analysis of the distribution of interference sources.

[0275] The candidate defect pixel set retained after logical AND operation is repackaged into a standard single-channel binary image format, where the effective defect area has a pixel value of 255 and the remaining area has a pixel value of 0, forming a spatially filtered defect logic diagram to be optimized.

[0276] By using logical AND operation masking, the global defect mask generated in the previous step, which contains background noise, is transformed into a spatially filtered defect logic graph containing only candidate defects within the effective neighborhood of the weld. This achieves the expected noise suppression effect based on structural semantic prior knowledge, significantly reducing the computational load of subsequent morphological processing and improving the signal-to-noise ratio of defect localization.

[0277] S7.3: For candidate defect connected regions located within the effective neighborhood in the defect logic graph to be optimized after spatial filtering, perform closed operation filling processing of structuring element adaptive matching to repair the small holes caused by threshold segmentation discontinuity and maintain the topological integrity of defect edges, and generate a continuous defect region map after hole repair.

[0278] After receiving the spatially filtered defect logic graph, extract the set of candidate defect connected pixels located in the effective neighborhood guided by the center line, and use it as the input data object for morphological repair processing.

[0279] Eight-neighbor connectivity analysis is performed on the extracted candidate defect connected components. The system traverses the adjacent positions above, below, left, right, and diagonally of each foreground pixel to identify the internal hole boundary pixel chain caused by the discontinuity of threshold segmentation.

[0280] Based on the identified hole boundaries, the equivalent diameter and area ratio of each isolated hole region are calculated. The size parameters of the structural elements are dynamically matched according to the hole size distribution characteristics to ensure that the structural elements can cover the tiny pores without excessively eroding the crack edges.

[0281] Construct circular or elliptical structural elements that adaptively match the size of each hole, anchor the center of the structural elements on the geometric centroid of the hole region, and prepare to perform local closure operations.

[0282] An expansion operation is performed on the connected domain of the candidate defect using an adaptive structuring element, causing the hole boundary to expand outward until the hole is completely closed, while maintaining the basic topological structure of the outer contour without significant deformation.

[0283] Next, an erosion operation is performed on the expanded region, using an adaptive structuring element of the same size to shrink the boundary in the opposite direction, restoring the original edge position of the defect region, and completing a full closed loop.

[0284] Through the above-mentioned closing operation, the binarized fracture gaps caused by metal reflection or texture interference are filled, the false background pixels inside the defect are eliminated, and a defect area map after hole repair with complete topological structure and continuous edges is generated.

[0285] S7.4: Based on the continuous defect area map after hole repair, perform morphological opening operation and boundary smoothing filtering to remove small burr artifacts attached to the weld edge and sharpen the defect contour features, generating a fine mask of weld defects with regularized edges.

[0286] S7.5: Based on the coordinates of isolated noise regions marked in the defect logic diagram to be optimized after spatial filtering, perform forced zeroing and clearing processing on the edge-normalized weld defect fine mask to completely remove false defect signals generated by background interference and generate an optimized weld defect detection image.

[0287] For those skilled in the art, various other corresponding changes and modifications can be made based on the technical solutions and concepts described above, and all such changes and modifications should fall within the protection scope of the claims of this invention.

[0288] Unless otherwise defined, the technical or scientific terms used herein shall have the ordinary meaning as understood by one of ordinary skill in the art to which this application pertains. The terms “first,” “second,” “third,” and similar terms used in this patent application specification and claims do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Similarly, the terms “an” or “a” and similar terms do not indicate a quantity limitation, but rather indicate the presence of at least one. The terms “comprising” or “including” and similar terms mean that the element or object preceding “comprising” or “including” encompasses the element or object listed following “comprising” or “including” and its equivalents, and do not exclude other elements or objects. The “multiple” mentioned in the embodiments of this application refers to two or more. A and / or B indicate three possibilities: A; B; and A and B.

[0289] The above description is merely an exemplary embodiment of this application, but the scope of protection of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and such modifications or substitutions should all be covered within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A visual inspection method for weld quality of stainless steel kitchenware based on threshold segmentation, characterized in that, include: The original grayscale image of the weld seam area of ​​stainless steel kitchenware is acquired and preprocessed to generate a noise-reduced and enhanced grayscale image; Perform Fast Hough Transform on the denoised and enhanced grayscale image and extract features by combining topological constraints to extract the weld centerline skeleton data; Based on the local width estimate and curvature confidence in the weld centerline skeleton data, a multi-scale local perception window set is generated with each anchor point on the centerline as a reference. For each window in the multi-scale local perception window set, the gray-scale histogram peak and valley distribution, gradient magnitude cumulative ratio, and edge continuity score are calculated. Based on the above statistical characteristics, the current local region is determined to belong to one of the following: high-contrast flat segment, low-contrast curved segment, or multi-interference transition segment, and a local semantic state label sequence is generated. Based on the classification results of different semantic states in the local semantic state label sequence, a differentiated threshold generation mechanism is enabled to generate an adaptive threshold discrete point set; The adaptive threshold discrete point set is mapped to a continuous threshold surface covering the entire image range by bicubic interpolation, and pixel-by-pixel threshold segmentation is performed to generate a binary mask image of weld defects. Based on the spatial location information of the weld centerline skeleton data, centerline-guided morphological post-processing is performed on the binary mask image of the weld defect. Hole filling and burr trimming operations are performed only in the neighborhood of the centerline, and isolated noise points far from the centerline are forcibly removed to generate an optimized weld defect detection image.

2. The visual inspection method for weld quality of stainless steel kitchenware based on threshold segmentation according to claim 1, characterized in that, After generating the optimized weld defect detection image, the following steps are included: Based on the defect distribution characteristics in the optimized weld defect detection image, a quality judgment conclusion is output, and the judgment conclusion is fed back to the automated quality control process to complete the closed-loop detection of the weld quality of stainless steel kitchenware.

3. The visual inspection method for weld quality of stainless steel kitchenware based on threshold segmentation according to claim 1, characterized in that, The extracted weld centerline skeleton data includes: Multi-scale directional gradient operator convolution is performed on the denoised and enhanced grayscale image to calculate the directional response intensity value of each pixel under a preset angle set and suppress non-weld seam texture interference, generating a multi-channel directional response feature map. An improved fast Hough transform accumulator voting mechanism is implemented based on the multi-channel directional response feature map to map the spatial domain edge points to the parameter domain and filter out a high-confidence peak candidate set to generate a preliminary weld line parameter cluster. A topological constraint filtering operation is performed by combining the preliminary weld line parameter set with the prior knowledge of the continuity of the macroscopic strip structure of the weld to remove discrete false line segments caused by metal scratches or reflection artifacts and connect the fracture edges, thereby generating a continuous weld centerline pixel coordinate sequence. Based on the pixel coordinate sequence of the continuous weld centerline, perform local grayscale profile scanning and half-width measurement calculation along the normal direction to quantify the weld width distribution characteristics at each anchor point and generate a sequence of local width estimates for associated coordinate points. Based on the pixel coordinate sequence of the continuous weld centerline, three-point radius of curvature calculation and smoothness scoring are performed to evaluate the local curvature and geometric stability of the centerline and output reliability index, generating weld centerline skeleton data containing pixel coordinate sequence, local width estimate and curvature confidence.

4. The visual inspection method for weld quality of stainless steel kitchenware based on threshold segmentation according to claim 1, characterized in that, The generation of the adaptive threshold discrete point set includes: Based on the classification identifier of the high-contrast flat segment in the local semantic state label sequence, a weighted local mean shift processing is performed on the gray-level histogram peak-valley distribution data adjacent to the core window to suppress baseline drift caused by metallic luster and extract stable baseline gray-level values, thereby generating the initial threshold parameter for the high-contrast flat segment. Using the classification identifier of the low-contrast bending segment and the gradient amplitude cumulative ratio data within the transition buffer window, a one-dimensional grayscale trend fitting operation is performed along the centerline direction and the fitting residual is calculated to compensate for the nonlinear grayscale decay caused by the change in weld curvature, thereby generating dynamic compensation threshold parameters for the low-contrast bending segment. For the classification labels of the multi-interference transition segments and the edge continuity score data in the background reference window, a bimodal search strategy based on neighborhood gray-level entropy weighting is activated to lock the best segmentation valley in the specified interval on both sides of the main peak of the histogram and remove scratch noise interference, thereby generating optimized threshold parameters for the multi-interference transition segments. By combining the initial threshold parameters of the high-contrast straight segment, the dynamic compensation threshold parameters of the low-contrast curved segment, and the optimized threshold parameters of the multi-interference transition segment, multi-source threshold fusion and spatial coordinate mapping operations are performed to eliminate threshold abrupt changes at the boundaries of different semantic states and ensure spatial continuity, thereby generating the adaptive threshold discrete point set.

5. The visual inspection method for weld quality of stainless steel kitchenware based on threshold segmentation according to claim 1, characterized in that, The process of generating the denoised and enhanced grayscale image includes: sequentially performing multi-directional gradient operator convolution on the original grayscale image to generate a directional response feature map, extreme value filtering and non-maximum suppression to generate a local overexposure artifact mask, performing adaptive gain compensation and smoothing filtering fusion based on the mask, and global dynamic range mapping and contrast equalization to generate the denoised and enhanced grayscale image.

6. The visual inspection method for weld quality of stainless steel kitchenware based on threshold segmentation according to claim 1, characterized in that, The process of generating a multi-scale local sensing window set includes: traversing the anchor points in the weld centerline skeleton data, linearly mapping the core window base radius using its local width estimate, and obtaining the core window dynamic scale parameter using nonlinear correction with curvature confidence. Then, multiplying this parameter by a preset coefficient to obtain the radii of the transition buffer window and the background reference window, thereby constructing adjacent core windows, transition buffer windows, and background reference windows in the denoised and enhanced grayscale image, and generating the multi-scale local sensing window set.

7. A visual inspection method for weld quality of stainless steel kitchenware based on threshold segmentation according to claim 6, characterized in that, The nonlinear correction is as follows: when the curvature confidence is higher than a preset threshold, the core window base radius is reduced; when it is lower, it is expanded. The correction magnitude is nonlinearly positively correlated with the degree of deviation of the curvature confidence.

8. The visual inspection method for weld quality of stainless steel kitchenware based on threshold segmentation according to claim 1, characterized in that, The process of generating the local semantic state label sequence includes: extracting the peak and valley distribution of the histogram of the adjacent core window in the multi-scale local perception window set, calculating the cumulative ratio of the gradient magnitude of the transition buffer window, calculating the edge continuity score of the background reference window, and then constructing the three into a multi-dimensional feature vector and performing logical matching judgment based on a preset rule base to generate the local semantic state label sequence.

9. A visual inspection method for the weld quality of stainless steel kitchenware based on threshold segmentation according to claim 8, characterized in that, The logical matching judgment of the preset rule base is as follows: if the peak-valley depth is greater than the first threshold and the gradient accumulation ratio is higher than the second threshold and the edge continuity score is higher than the third threshold, it is judged as a high-contrast flat segment; if the peak-valley depth is less than the fourth threshold and the gradient accumulation ratio is lower than the fifth threshold, it is judged as a low-contrast curved segment; otherwise, it is judged as a multi-interference transition segment.

10. A visual inspection method for weld quality of stainless steel kitchenware based on threshold segmentation according to claim 1, characterized in that, The multi-scale directional gradient operator convolution uses a Sobel or equivalent template that includes horizontal, vertical and diagonal directions, and the convolution kernel size is small or medium scale.