A container corrosion defect detection method and system based on visual detection

By employing an adaptive image processing workflow, including preprocessing, noise analysis, and edge feature extraction, and combining historical data for optimization, the problem of low detection accuracy of container corrosion defects under complex imaging conditions has been solved, achieving high-precision and reliable detection.

CN122244054APending Publication Date: 2026-06-19广东省特种设备检测研究院茂名检测院

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
广东省特种设备检测研究院茂名检测院
Filing Date
2026-05-22
Publication Date
2026-06-19

AI Technical Summary

Technical Problem

Existing technologies lack adaptive image quality assessment and processing mechanisms under complex imaging conditions, resulting in low accuracy in visual detection of container corrosion defects.

Method used

By acquiring raw surface images for preprocessing and region segmentation, analyzing noise distribution density, performing enhancement processing, extracting edge feature data, calculating contrast differences and defect areas, and combining historical image data to optimize the detection process, an adaptive boundary determination strategy and dual thresholds are adopted to confirm defects.

Benefits of technology

It significantly improves the accuracy and precision of defect detection in complex environments, reduces the false alarm rate, and ensures the reliability and long-term adaptability of detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122244054A_ABST
    Figure CN122244054A_ABST
Patent Text Reader

Abstract

This invention relates to the field of industrial equipment inspection and image processing technology, and discloses a method and system for detecting corrosion defects in containers based on vision inspection. The method includes acquiring and preprocessing an original surface image to obtain an initial segmented image; enhancing the initial segmented image to obtain an optimized surface image; calculating contrast differences and defect region divisions based on the optimized surface image to obtain a preliminary defect region map; calculating the defect area ratio to obtain a defect candidate map; extracting corrosion depth distribution data to obtain quantified defect results; obtaining morphological matching coefficients and local contrast differences based on the quantified defect results to obtain corrosion detection results; and acquiring historical adjustment data and comparing the corrosion detection results with the historical adjustment data to obtain optimized image processing rules. This method realizes an adaptive image quality evaluation and processing mechanism under complex imaging conditions, improving the accuracy of visual detection of corrosion defects in containers.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of industrial equipment inspection and image processing technology, and in particular to a method and system for detecting corrosion defects in containers based on visual inspection. Background Technology

[0002] Currently, in industrial fields such as petrochemicals, energy storage and transportation, and pressure vessels, with the development of technology, image-based visual inspection methods have gradually become an important means of monitoring the surface condition of industrial equipment due to their advantages of non-contact and high efficiency.

[0003] In a current technology, visual inspection of container corrosion defects typically employs an image processing workflow based on a fixed threshold. First, an image of the container surface is acquired. After preprocessing, contour features such as edge length, area, and color difference are extracted. During inspection, the extracted contour features are directly compared to a pre-set empirical threshold. If the feature value exceeds the threshold, the area is determined to have a corrosion defect.

[0004] However, industrial environments are complex and variable. Container surface images often exhibit quality fluctuations due to uneven lighting, oil contamination, and complex background textures. When image quality is poor, direct feature extraction generates significant noise or erroneous edges, easily leading to misjudgments when compared to fixed thresholds. Furthermore, existing technologies rely on a single, fixed image processing workflow and judgment threshold, resulting in insufficient stability and generalization ability of the detection results. Therefore, current methods lack adaptive image quality assessment and processing mechanisms under complex imaging conditions, leading to low accuracy in visual detection of container corrosion defects. Summary of the Invention

[0005] This invention provides a visual inspection-based method and system for detecting corrosion defects in containers, which addresses the problem of low accuracy in visual inspection of corrosion defects in containers due to the lack of an adaptive image quality assessment and processing mechanism under complex imaging conditions.

[0006] In a first aspect, to solve the above-mentioned technical problems, the present invention provides a method for detecting corrosion defects in containers based on visual inspection, comprising: The original surface image is acquired, and the original surface image is preprocessed and divided into regions to obtain an initial segmented image; Based on the initial segmented image, the noise distribution density is analyzed. If the noise distribution density does not meet the preset image standard, the initial segmented image is enhanced to obtain an optimized surface image. Based on the optimized surface image, edge feature data is extracted, and contrast difference and defect region division are calculated based on the edge feature data to obtain a preliminary defect region map. The defect area ratio is calculated based on the preliminary defect area map, and the defect area ratio is compared with the preset defect standard to obtain a defect candidate map. Based on the defect candidate map, corrosion depth distribution data is extracted, and the corrosion depth distribution data is analyzed to obtain quantitative defect results. Based on the quantitative defect results, the morphological matching coefficient and local comparison difference are obtained, and compared with the preset corrosion standard to confirm the corrosion defects and obtain the corrosion detection results. Historical image data is acquired, preprocessed to obtain adjusted historical data, the corrosion detection results are compared with the adjusted historical data, the quality assessment parameters of the corrosion defect detection process are updated, and optimized image processing rules are generated.

[0007] In one optional implementation, the step of acquiring the original surface image, preprocessing and region segmenting the original surface image to obtain an initial segmented image includes: Obtain the original surface image of the container, and perform grayscale conversion and brightness equalization processing on the original surface image to obtain the first processed image; Brightness features are extracted from the first processed image. If the brightness features exceed a preset uniformity threshold, the local contrast of the first processed image is adjusted to obtain the second processed image. The second processed image is refined to obtain the boundary sharpness. If the boundary sharpness reaches the preset sharpness standard, the initial segmented image is output.

[0008] In one optional implementation, the step of analyzing the noise distribution density based on the initial segmented image, and if the noise distribution density does not meet a preset image standard, then enhancing the initial segmented image to obtain an optimized surface image, includes: The initial segmented image is subjected to layer processing to extract sharpness distribution data; Based on the sharpness distribution data, noise density is detected in the initial segmented image to determine the noise distribution density; If the noise distribution density exceeds the preset image standard, the initial segmented image is subjected to brightness adjustment and image enhancement processing to obtain an optimized surface image.

[0009] In one optional implementation, the step of extracting edge feature data based on the optimized surface image, calculating contrast differences and defect region division based on the edge feature data, and obtaining a preliminary defect region map includes: Edge features are extracted from the optimized surface image to obtain edge feature data, which includes an edge blur index. Based on the edge feature data, the contrast difference of the optimized surface image is calculated to obtain contrast deviation data; The edge blur index and the contrast deviation data are weighted and calculated to obtain the boundary sharpness data; Based on the boundary sharpness data, the optimized surface image is divided and labeled to generate a preliminary defect area map.

[0010] In one optional implementation, the step of calculating the defect area ratio based on the preliminary defect area map and comparing the defect area ratio with a preset defect standard to obtain a defect candidate map includes: Based on the preliminary defect area map, the defect area ratio and defect aggregation degree are calculated, and the pixel gray value variance and gray matrix contrast are obtained. Based on the pixel gray value variance and the gray matrix contrast, local feature difference and texture anomaly index are calculated respectively. By combining the local feature difference and the texture anomaly index, boundary division is performed to determine the extended boundary range data. Based on the extended boundary range data, if the extended boundary range data meets a preset extension threshold, the extended boundary range data is marked as a region to be confirmed, and the distribution data of the region to be confirmed is obtained. Based on the distribution data of the areas to be confirmed, the abnormal distribution density is calculated, and the abnormal distribution density is compared with the degree of defect aggregation to determine the priority ranking of the areas. Based on the region priority ranking, the defect area ratio is compared with the preset defect standard to obtain a defect candidate map.

[0011] In one optional implementation, the step of extracting corrosion depth distribution data based on the defect candidate map, analyzing the corrosion depth distribution data, and obtaining quantitative defect results includes: Based on the defect candidate image, local image blocks are extracted, and the boundaries of the local image blocks are divided to obtain boundary pixel distribution data; Based on the boundary pixel distribution data, the pixel change amplitude is calculated, gradient distribution data is obtained based on the pixel change amplitude, and corrosion depth distribution data is determined based on the gradient distribution data. If the corrosion depth distribution data exceeds the preset corrosion depth threshold, then the morphology matching coefficient is calculated, and the defect type is matched according to the morphology matching coefficient. Based on the gradient distribution data and the defect type, the quantified defect result is obtained.

[0012] In one optional implementation, the step of obtaining morphological matching coefficients and local contrast differences based on the quantified defect results, and comparing them with preset corrosion standards to confirm corrosion defects and obtain corrosion detection results includes: Based on the quantitative defect results, the morphological matching coefficient and local contrast difference are obtained and compared with the preset corrosion standard. If the morphological matching coefficient and the local contrast difference are higher than the preset corrosion standard, they are determined to be corrosion defects. Based on the corrosion defects, candidate images of the defects are identified and processed to obtain corrosion detection results.

[0013] In one optional implementation, the steps of acquiring historical image data, preprocessing the historical image data to obtain adjusted historical data, comparing the corrosion detection results with the adjusted historical data, updating the quality assessment parameters of the corrosion defect detection process, and generating optimized image processing rules include: Acquire historical image data, which includes the degree of image distortion and noise distribution density; clean the historical image data to obtain adjusted historical data. The corrosion detection results are compared with the historical adjustment data to obtain the comparison difference results. The original surface image is then adjusted based on the comparison difference results to obtain optimized image parameters. Based on the optimized image parameters, the quality assessment parameters of the corrosion defect detection process are updated, and optimized image processing rules are generated.

[0014] Secondly, the present invention provides a container corrosion defect detection system based on visual inspection, for implementing the above-mentioned container corrosion defect detection method based on visual inspection, comprising: The image acquisition and processing module is used to acquire the original surface image, preprocess the original surface image and divide it into regions to obtain an initial segmented image. The image quality assessment and enhancement module is used to analyze the noise distribution density based on the initial segmented image. If the noise distribution density does not meet the preset image standard, the initial segmented image is enhanced to obtain an optimized surface image. The feature extraction and defect identification module is used to extract edge feature data based on the optimized surface image, calculate contrast difference and defect region division based on the edge feature data, and obtain a preliminary defect region map. The expansion and filtering module is used to calculate the defect area ratio based on the preliminary defect area map, compare the defect area ratio with the preset defect standard, and obtain a defect candidate map. The quantification and classification module is used to extract corrosion depth distribution data based on the defect candidate image, analyze the corrosion depth distribution data, and obtain quantified defect results. The defect confirmation module is used to obtain the morphological matching coefficient and local comparison difference based on the quantitative defect results, and compare them with the preset corrosion standard to confirm the corrosion defect and obtain the corrosion detection result. The rule optimization and update module is used to acquire historical image data, preprocess the historical image data to obtain adjusted historical data, compare the corrosion detection results with the adjusted historical data, update the quality assessment parameters of the corrosion defect detection process, and generate optimized image processing rules.

[0015] Thirdly, the present invention also provides an electronic device, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor executes the computer program to implement a visual inspection-based container corrosion defect detection method as described in any one of the above.

[0016] Fourthly, the present invention also provides a computer-readable storage medium comprising a stored computer program, wherein, when the computer program is executed, it controls the device where the computer-readable storage medium is located to perform any of the above-described visual inspection-based container corrosion defect detection methods.

[0017] Compared with the prior art, the present invention has the following beneficial effects: (1) This invention introduces an image quality assessment and dynamic enhancement mechanism based on noise distribution density to actively identify and correct imaging defects such as uneven illumination and noise interference during the preprocessing stage. This step provides a clear and stable image base for subsequent steps, reducing feature extraction deviations caused by image quality problems from the source, thereby significantly improving the accuracy of defect detection.

[0018] (2) This invention identifies defect boundaries by using a weighted analysis method that combines edge blur index and local contrast difference. By comprehensively considering edge sharpness and regional contrast, it can effectively distinguish between low-contrast blurred edges of real corrosion and image noise or texture. This adaptive boundary determination strategy significantly improves the accuracy of boundary positioning for subtle and blurred corrosion traces in complex backgrounds.

[0019] (3) This invention constructs a dual verification process from quantitative description to final confirmation, and performs closed-loop optimization by combining historical detection data. By confirming defects through dual thresholds of morphological matching and local comparison difference, the false alarm rate is reduced; at the same time, the image processing parameters and rules are dynamically optimized using historical comparison results, enabling this invention to continuously adapt to different detection environments and objects, and ensuring the reliability and accuracy of long-term detection. Attached Figure Description

[0020] Figure 1 This is a schematic diagram of a container corrosion defect detection method based on visual inspection provided in the first embodiment of the present invention; Figure 2 This is a schematic diagram of a container corrosion defect detection system based on vision inspection provided in the second embodiment of the present invention. Detailed Implementation

[0021] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0022] Reference Figure 1 The first embodiment of the present invention provides a method for detecting corrosion defects in containers based on visual inspection, comprising the following steps: S11, acquire the original surface image, preprocess and divide the original surface image into regions to obtain the initial segmented image; S12, Based on the initial segmentation image, the noise distribution density is analyzed and obtained. If the noise distribution density does not meet the preset image standard, the initial segmentation image is enhanced to obtain an optimized surface image. S13, based on the optimized surface image, extract edge feature data, calculate contrast difference and defect area division based on the edge feature data, and obtain a preliminary defect area map; S14, calculate the defect area ratio based on the preliminary defect area map, compare the defect area ratio with the preset defect standard, and obtain a defect candidate map; S15, Based on the defect candidate map, extract corrosion depth distribution data, analyze the corrosion depth distribution data, and obtain quantitative defect results; S16. Based on the quantitative defect results, obtain the morphological matching coefficient and local comparison difference, and compare them with the preset corrosion standard to confirm the corrosion defect and obtain the corrosion detection result. S17, acquire historical image data, preprocess the historical image data to obtain adjusted historical data, compare the corrosion detection results with the adjusted historical data, update the quality assessment parameters of the corrosion defect detection process, and generate optimized image processing rules.

[0023] In step S11, the original surface image is acquired, and the original surface image is preprocessed and divided into regions to obtain an initial segmented image, including: Obtain the original surface image of the container, and perform grayscale conversion and brightness equalization processing on the original surface image to obtain the first processed image; Brightness features are extracted from the first processed image. If the brightness features exceed a preset uniformity threshold, the local contrast of the first processed image is adjusted to obtain the second processed image. The second processed image is refined to obtain the boundary sharpness. If the boundary sharpness reaches the preset sharpness standard, the initial segmented image is output.

[0024] Specifically, the original color image data of the container surface is acquired through a vision sensor, the original color image is processed by grayscale conversion, and a weighted average method is used according to the formula. The RGB value of each pixel is converted into a single grayscale value, and then the grayscale image is subjected to global brightness equalization using the histogram equalization method to obtain the first processed image.

[0025] It is worth noting that extracting brightness features from the first processed image specifically involves dividing the image into several non-overlapping pixel blocks (e.g., 16×16 pixels), calculating the standard deviation of the grayscale values ​​of all pixels within each block, and using this as an indicator of the block's brightness uniformity. By statistically analyzing a sample library of at least 500 images of typical normal areas of a container surface without strong reflections or shadows, an upper limit for the grayscale standard deviation within an image block is calculated, and this value is preset as the uniformity threshold. Traversing all pixel blocks, if more than 20% of the pixel blocks have a standard deviation greater than the preset uniformity threshold, the overall brightness distribution of the image is determined to be uneven. For areas with uneven brightness, the Limited Contrast Adaptive Histogram Equalization (CLAHE) algorithm is used for local contrast adjustment. This algorithm divides the image into multiple small regions (typically using an 8×8 or 16×16 pixel grid) and performs histogram equalization independently within each small region. To limit noise amplification caused by over-enhancement, a contrast limit (ClipLimit) is set to 1.5 to 2.5 times the maximum value of the gray-level distribution after histogram equalization. For example, for a 256-level gray-level image, a typical value is set to 2.0. Subsequently, bilinear interpolation is used to eliminate artifacts at region boundaries, thereby significantly improving the visibility of local details and obtaining the second processed image.

[0026] Furthermore, the second processed image undergoes boundary refinement to improve the accuracy of region segmentation. The Canny edge detection algorithm is used to extract edge contours from the image, a Gaussian filter is used to smooth the image to remove noise, the gradient magnitude and direction of each pixel in the image are calculated, and non-maximum suppression (NMS) is applied to refine the edges, retaining only local maxima along the gradient direction. For adaptive settings, a histogram of the gradient magnitudes of all pixels after NMS is calculated, and its statistical distribution is obtained. A high threshold is set to the value corresponding to the 85th quantile of the gradient magnitude distribution, used to filter strong edge pixels; a low threshold is set to the value corresponding to the 30th quantile of the gradient magnitude distribution, used to connect weak edge pixels. Any pixel with a gradient magnitude higher than the high threshold is directly marked as a strong edge; a pixel with a gradient magnitude between the high and low thresholds, if connected to a strong edge pixel, is marked as part of an edge; pixels below the low threshold are suppressed. By detecting and connecting edge pixels in this way, a continuous edge map is obtained.

[0027] The average gradient magnitude of all edge pixels in the edge image is calculated as an indicator of boundary sharpness. Based on edge gradient analysis of clearly segmented container surface images, it is determined that the average gradient magnitude of edge pixels is typically higher than a benchmark value. For example, through statistical analysis of 500 qualified segmented images, the lower quartile of the average gradient magnitude is 25, therefore, the preset sharpness standard is set to 25. If the average gradient magnitude reaches the preset sharpness standard, the boundary is considered sharp and meets the segmentation requirements. Based on the detected edge contours, the image is divided into regions, and continuous regions enclosed by the edges are marked as different initial segmentation regions, ultimately outputting the initial segmented image.

[0028] In step S12, based on the initial segmented image, the noise distribution density is analyzed and obtained. If the noise distribution density does not meet the preset image standard, the initial segmented image is enhanced to obtain an optimized surface image, including: The initial segmented image is subjected to layer processing to extract sharpness distribution data; Based on the sharpness distribution data, noise density is detected in the initial segmented image to determine the noise distribution density; If the noise distribution density exceeds the preset image standard, the initial segmented image is subjected to brightness adjustment and image enhancement processing to obtain an optimized surface image.

[0029] Specifically, the initial segmented image is processed in layers to evaluate its sharpness. A Gaussian pyramid multi-scale analysis method is employed. First, the initial segmented image is Gaussian blurred and downsampled to construct multiple image layers with different resolutions, such as the original scale (L0), half-scale (L1), and quarter-scale (L2). Then, the gradient magnitude of each scale is calculated using the Laplacian operator and upsampled to the original image size to obtain the sharpness response map for the corresponding scale. The sharpness response maps at different scales are then weighted and fused. Through statistical analysis of a standard sharp image library, the weight assigned to the original resolution (L0) is 0.5, the weight assigned to downsampling to half-resolution (L1) is 0.3, and the weight assigned to downsampling to quarter-resolution (L2) is 0, resulting in the sharpness distribution data for the entire image.

[0030] It is worth noting that noise density is detected based on the aforementioned sharpness distribution data. Noise typically manifests as isolated points or small regions with high response at high-frequency scales (i.e., small scales), but with a rapidly decaying response at lower-frequency scales. Therefore, a noise pixel can be defined as a pixel whose sharpness response value at the highest resolution scale (L0) is greater than 1.5 times the median of all sharpness response values ​​at that scale, while its sharpness response value at the next scale (L1) is less than 0.2 times the median of all sharpness response values ​​at the L1 scale. The image is traversed, and based on the visual sensor calibration parameters (e.g., image resolution of 100 pixels / cm), the number of marked noise pixels is converted to the number per square centimeter, which is taken as the noise density of that region. Statistical analysis is performed on a large number of known defect-free container surface images acquired under controlled lighting to determine the normal fluctuation range of the noise density. For example, statistical analysis of 1000 clean images shows that the 99th percentile of the noise density is 8 noise pixels per square centimeter; based on this, the preset image standard is set to 8 pixels per square centimeter. If the noise density in a certain region of the image exceeds the preset image standard, local enhancement of the initial segmented image is required.

[0031] The enhancement processing employs a local brightness correction and contrast enhancement method based on Retinex theory for grayscale images. For each non-zero pixel value, calculate its natural logarithm: The initial segmented image is transformed from grayscale space to the logarithmic domain. Then, a guided filter is applied to the logarithmic domain image. Filtering is performed with a filter radius of 4 and a regularization parameter of 0.01. The low-frequency illumination component of the image is calculated. The low-frequency illumination component is subtracted from the original logarithmic domain image to obtain the high-frequency detail component, which reflects the object's reflectivity—the enhanced image. Adaptive histogram stretching is then applied to the enhanced image, mapping its pixel values ​​to the full display range (0-255). The image is then smoothed using a bilateral filter. For each pixel p in the enhanced image, its bilaterally filtered value... It is obtained by weighted averaging of pixels q in its neighborhood, with the weights determined by two Gaussian functions, one of which is the spatial domain weight. One is the spatial distance between pixels; the other is the value range (grayscale range) weight. This measures the similarity of pixel values. The calculation formula is as follows: .in, It is a normalization factor, the value of which is the sum of the weights of all pixels in the neighborhood. It is a neighborhood window centered on p (e.g., 9×9 pixels). and These are the standard deviation parameters for controlling spatial and gray-level similarity, respectively, and can be set according to the image noise level, for example... , This allows for the acquisition of an optimized surface image.

[0032] For example, when inspecting the inner wall of a chemical reactor, the initial segmented image may contain numerous fine noise points due to trace amounts of water vapor or oil film adhering to the surface. Multi-scale sharpness analysis revealed that these noise points are abnormally active at high-frequency scales. The calculated noise density was 12 points per square centimeter, exceeding the preset image standard. A local enhancement process based on Retinex and bilateral filtering was then initiated. After processing, water vapor artifacts in the image were significantly suppressed, while the contours and textures of genuine pitting were enhanced and preserved, resulting in an optimized surface image more suitable for subsequent accurate defect identification.

[0033] In step S13, edge feature data is extracted based on the optimized surface image, and contrast difference and defect region division are calculated based on the edge feature data to obtain a preliminary defect region map, including: Edge features are extracted from the optimized surface image to obtain edge feature data, which includes an edge blur index. Based on the edge feature data, the contrast difference of the optimized surface image is calculated to obtain contrast deviation data; The edge blur index and the contrast deviation data are weighted and calculated to obtain the boundary sharpness data; Based on the boundary sharpness data, the optimized surface image is divided and labeled to generate a preliminary defect area map.

[0034] Specifically, edge features are extracted from the optimized surface image. First, a multi-directional Sobel operator is used for preliminary edge detection, calculating the gradient components of the image in the horizontal, vertical, and two diagonal directions to obtain a more comprehensive edge response. For a pixel, its edge strength is defined as the square root of the sum of the squares of the gradient magnitudes in each direction. Subsequently, to quantify the blurriness of the edges, the Edge Blur Index (EBI) is calculated. For each initially detected edge point, a short line segment is taken along its normal direction (i.e., the gradient direction), and the grayscale profile of the pixels on that line segment is obtained. The Edge Blur Index is defined as the ratio of the maximum absolute value of the first derivative (i.e., the gradient) of this grayscale profile to the total grayscale variation range spanned by the grayscale profile. A higher EBI value indicates a sharper edge. The calculation formula can be expressed as follows: ,in This represents the absolute value of the difference in grayscale values ​​between the two endpoints of the line segment. By iterating through all edge points, we can obtain edge feature data containing the location, intensity, and corresponding edge blur index of each edge point.

[0035] It is worth noting that the contrast difference is calculated based on the edge feature data. For each identified edge point, a local neighborhood window (e.g., 5×5 pixels) is defined centered on it. To calculate the average gray value of pixels located on both sides of the edge line, it is necessary to divide the area into sub-regions according to the gradient direction θ of that point (usually calculated using atan2(gy, gx), where gx and gy are the horizontal and vertical gradients, respectively). Specifically, a local coordinate system is established centered on the edge point, with the x-axis representing the gradient direction and the y-axis representing the edge tangent direction. All pixels within the neighborhood window are divided into positive and negative subsets based on the sign of their projections relative to the center point on the local x-axis. All pixels projected on the positive side constitute one sub-region, and all pixels projected on the negative side constitute the other sub-region. The average gray value of the two sub-regions is calculated, and the local contrast of the edge point is defined as the absolute value of the average gray value difference between the two sub-regions. To evaluate the significance of this local contrast relative to the overall image background, the global average contrast of the image is calculated, which is the average of the absolute values ​​of the gray value differences between random sampling point pairs within all non-edge regions (smooth regions). The contrast deviation data of this edge point is defined as the ratio of local contrast to global average contrast. A value greater than 1 indicates that the contrast of this edge is higher than the normal background of the image, and it is more likely to be a real defect boundary; a value less than 1 indicates that the contrast is not significant, and it may be texture or noise.

[0036] Furthermore, the edge blur index and contrast deviation data are weighted and calculated to comprehensively evaluate the boundary sharpness. Since sharp and high-contrast edges are more likely to be the boundaries of real defects, the formula for calculating the boundary sharpness data S is defined as follows: .in, This refers to the contrast deviation data of the edge points mentioned above. and The weighting coefficients are preset based on the contributions of balancing blur and contrast to boundary credibility. Their signs and magnitudes reflect the negative contribution of the blur index to sharpness and the positive contribution of contrast deviation. Through analysis of the training set, these weighting coefficients can be set. =-0.6, =0.4, so that the S value increases with the improvement of edge sharpness and contrast. It is a normalization function of the edge blurring index EBI, which maps it to the interval [-1,1] and is transformed using the hyperbolic tangent function. ,in For all edge points of the current image The median value is used for centering, and k is a scaling factor, which can be set to 0.1 based on historical data analysis and experience, to control the slope of the function. This ensures that the lower the blur index and the more blurred the edges, the closer the value is to -1. Through this weighted calculation, each edge point obtains a boundary sharpness data S; the higher the value, the greater the probability that the location is a clear, high-contrast defect boundary.

[0037] The optimized surface image is divided and labeled based on the boundary sharpness data. Offline analysis is performed on a training set containing at least 300 container surface images whose defect categories and precise boundaries have been confirmed by non-destructive testing methods (such as ultrasonic testing). The distribution of boundary sharpness data S for all manually labeled "real defect boundaries" in the training set is calculated, and its 25th quantile is calculated. Simultaneously, the 75th quantile of the S value distribution for all explicitly excluded non-defect edges (such as textures, scratches, and noise) in the training set is calculated. The midpoint between these two values ​​is selected to preset a sharpness threshold S. thAll edge points with boundary sharpness data greater than a preset sharpness threshold are marked as highly sharp edge points. A region growing algorithm is used, with these highly sharp edge points as seed points. For each seed point, its eight neighboring pixels are checked. If a pixel is also an edge point (even if its S-value does not reach the threshold) and its grayscale value differs from the seed point by less than 10 grayscale levels, it is included in the current region. This growing process is terminated with a maximum number of iterations (e.g., 1000) to avoid infinite loops or excessive region expansion. This process is repeated until the region no longer expands. All grown connected regions are labeled, and their minimum bounding rectangle or precise contour is calculated. Small regions with a centroid distance of less than 5 pixels are merged to eliminate fragmentation. Finally, these labeled regions are superimposed on the optimized surface image to generate a preliminary defect region map, clearly marking the potential defect boundaries and extents.

[0038] In step S14, the defect area ratio is calculated based on the preliminary defect area map, and the defect area ratio is compared with a preset defect standard to obtain a defect candidate map, including: Based on the preliminary defect area map, the defect area ratio and defect aggregation degree are calculated, and the pixel gray value variance and gray matrix contrast are obtained. Based on the pixel gray value variance and the gray matrix contrast, local feature difference and texture anomaly index are calculated respectively. By combining the local feature difference and the texture anomaly index, boundary division is performed to determine the extended boundary range data. Based on the extended boundary range data, if the extended boundary range data meets a preset extension threshold, the extended boundary range data is marked as a region to be confirmed, and the distribution data of the region to be confirmed is obtained. Based on the distribution data of the areas to be confirmed, the abnormal distribution density is calculated, and the abnormal distribution density is compared with the degree of defect aggregation to determine the priority ranking of the areas. Based on the region priority ranking, the defect area ratio is compared with the preset defect standard to obtain a defect candidate map.

[0039] Specifically, based on the preliminary defect area map, the core evaluation metrics are first calculated. The defect area ratio is the ratio of the total number of pixels marked as preliminary defect areas to the total number of pixels in the entire image. The degree of defect clustering is quantified by calculating the average nearest neighbor distance between the centroids of all defect areas. For N preliminary defect areas, the Euclidean distance between the centroid of each area and the centroids of all other areas is calculated, and the smallest one is taken as the nearest neighbor distance for that area. Then, the arithmetic mean of the nearest neighbor distances of all areas is calculated to obtain the average nearest neighbor distance. The shorter the average nearest neighbor distance, the more concentrated the defect distribution and the higher the degree of clustering. Simultaneously, to characterize the grayscale changes and structural information within the areas, the pixel grayscale value variance and grayscale matrix contrast of each preliminary defect area are calculated. The grayscale matrix contrast is obtained by calculating the contrast feature value of the grayscale co-occurrence matrix within the area at a distance of 1 and an orientation of 0°. This value reflects the clarity of the texture and the depth of the grooves.

[0040] It is worth noting that two key features are further extracted using the pixel grayscale value variance and grayscale matrix contrast calculated above. The local feature difference is defined as the ratio of the pixel grayscale value variance of the current defective region to the pixel grayscale value variance of its directly adjacent external annular background region. The texture anomaly index is defined as the ratio of the grayscale matrix contrast of the current defective region to the average grayscale matrix contrast of all non-defective regions in the entire image, used to measure the degree of deviation between the texture of this region and the normal background texture.

[0041] It should be noted that, combining local feature differences and texture anomaly indices, a region growing algorithm is used to expand the boundaries of the initial defect region. Starting from the original boundary pixel, its neighboring pixels are checked. If the gray value of a neighboring pixel differs from the average gray value of the current region by within ±15 gray levels, and the temporary local feature difference and texture anomaly index calculated based on the pixel's location differ from the original features of the region by less than 20%, then the pixel is included in the current region.

[0042] The temporary local feature difference is defined as an 11x11 pixel temporary image patch centered on the given pixel. The grayscale variance of this temporary image patch is calculated. A ring-shaped region formed by expanding the outline of this temporary image patch outwards by 5 pixels is used as its background, and the grayscale variance of the background region is calculated. The ratio of the two is the temporary local feature difference. The texture anomaly index is the ratio of the grayscale co-occurrence matrix contrast value of the temporary region to the average contrast value of the non-defective region in the entire image. This process is iterated until no new pixels satisfy the conditions, thus obtaining the extended boundary range data, which contains the extended region outline.

[0043] Furthermore, by analyzing the expansion behavior of confirmed corrosion defects in historical data, a preset expansion threshold (e.g., 20%) is set based on the percentage increase in the expanded area relative to the original area. If the expansion rate of a region exceeds the preset threshold, the region is considered to have outward spreading characteristics, conforming to the morphology of corrosion diffusion, and is marked as a region to be confirmed. Its outline is recorded to obtain the distribution data of the regions to be confirmed. For all regions to be confirmed, their abnormal distribution density is calculated, which is the proportion of pixels in the region whose absolute difference between their grayscale value and the average grayscale value of the region exceeds a dynamic threshold. The formula for calculating this dynamic threshold is as follows: ,in and These are the maximum and minimum grayscale values ​​within the current area to be confirmed, respectively. The higher this density, the stronger the non-uniformity within the area.

[0044] Region priority is determined based on the density of abnormal distributions and the previously calculated degree of defect clustering. Priority scores are defined. ,in For anomalous distribution density, The average nearest neighbor distance mentioned above, This is a reference distance, for example, 1 / 20 of the image diagonal length, used for normalization and to prevent the logarithmic parameter from being too small. α and β are weighting coefficients, for example, α=0.7, β=0.3. All regions to be confirmed are sorted in descending order based on priority scores. A defect standard is preset based on an area percentage threshold set according to industry standards and expert experience. For each sorted region, its defect area percentage is compared with the preset defect standard. For example, for general pressure vessel inspection, this standard can be set to 0.5%, meaning the defect area accounts for 0.5% of the total area. Only regions with a defect area percentage greater than or equal to the preset standard are ultimately marked as candidate corrosion regions. The contour information of all candidate corrosion regions is integrated to generate the final defect candidate map.

[0045] In step S15, based on the defect candidate image, corrosion depth distribution data is extracted, and the corrosion depth distribution data is analyzed to obtain quantitative defect results, including: Based on the defect candidate image, local image blocks are extracted, and the boundaries of the local image blocks are divided to obtain boundary pixel distribution data; Based on the boundary pixel distribution data, the pixel change amplitude is calculated, gradient distribution data is obtained based on the pixel change amplitude, and corrosion depth distribution data is determined based on the gradient distribution data. If the corrosion depth distribution data exceeds the preset corrosion depth threshold, then the morphology matching coefficient is calculated, and the defect type is matched according to the morphology matching coefficient. Based on the gradient distribution data and the defect type, the quantified defect result is obtained.

[0046] Specifically, for each candidate erosion region in the defect candidate image, a fixed number of pixels (e.g., 5 pixels) are extended outward from its minimum bounding rectangle as the analysis region, and this region is divided into a series of non-overlapping local image patches (e.g., each patch is 32×32 pixels in size). For each local image patch, an ActiveContour Model is used to refine the boundary delineation of the defect portion contained within it. The evolution process of the ActiveContour Model is based on the level set method, by defining a high-dimensional function Φ(x,y), where x and y represent the two-dimensional spatial coordinates of pixels in the image, and its zero level set (Φ=0) represents the currently evolving contour. The evolution of the contour is driven by partial differential equations: in, For level set functions, Weights for the curvature term (to smooth the contour). Weights for the expansion term; Since the velocity term is constant, in this application, the initial profile is set inside the defect region, therefore... Taking a positive value will cause the contour to expand. The weights of the image gradient attraction term. Let be the image gradient magnitude. Solve this equation iteratively until... If the change in the zero-level set is less than a threshold, the contour is considered stable. Specifically, in container surface defect detection, an optimized surface image is used as input. The gray-level difference between the defect and the background generates a significant image gradient, thereby guiding the contour to converge precisely to the defect boundary. By iteratively solving this partial differential equation until the contour is stable, accurate boundary pixel distribution data is obtained, which includes the set of contour points of the defect within the image block.

[0047] It is worth noting that the pixel variation amplitude is calculated based on the boundary pixel distribution data to assess the local erosion depth. For each pixel on the boundary, sampling is performed along its normal direction towards both the defect region and the normal substrate region. The sampling distance is dynamically determined based on the size and grayscale variation of the current local image patch. First, the equivalent diameter of the defect region within the local image patch is estimated by taking the square root of the region area. The sampling distance is set to Each pixel is recorded. The gray values ​​of pixels sampled from the defect area and the gray values ​​of pixels sampled from the normal substrate area are recorded. The absolute value sequence of the difference between the gray values ​​of corresponding sampling points on the two paths is calculated, and the maximum value in the absolute value sequence is taken as the pixel change amplitude at that boundary point. For each local image block, the average and standard deviation of the pixel change amplitudes of all boundary points within it are calculated to obtain gradient distribution data characterizing the overall abrupt change intensity of the defect edge within the image block.

[0048] For example, the corrosion depth distribution data is obtained by mapping it from the gradient distribution data using an empirical transformation function. This function is established based on regression analysis of a large number of samples with known true corrosion depths obtained through laser scanning or probe measurement and their corresponding image gradient data. For each sample at the defect location in the image, its gradient distribution data is extracted using the above method, and the average pixel variation amplitude of all boundary points within the defect region is calculated, denoted as . Simultaneously, the average actual corrosion depth of the sample was recorded using high-precision instruments. Establish a linear regression model: ,in, The model outputs the estimated corrosion depth, where 'a' is the slope (sensitivity coefficient, unit: mm / grayscale unit) and 'b' is the intercept (unit: mm). This is achieved by analyzing all sample data. By performing a least-squares fit, the model parameters a and b can be obtained. For example, the fitting result might be a=0.01, b=0.05, which means... For every 10 grayscale units added, the estimated corrosion depth increases by 0.1 mm.

[0049] For example, based on the safety usage specifications of container materials, industry testing standards (such as the corrosion allowance requirements for containers with different wall thicknesses in the "Non-destructive Testing of Pressure Equipment" standard), and historical failure case data, a preset corrosion depth threshold is comprehensively calculated. For instance, for a carbon steel container with a wall thickness of 10 mm, the initial corrosion depth warning value might be set to 0.5 mm. The calculated corrosion depth distribution data is compared with the preset corrosion depth threshold. If the corrosion depth distribution data corresponding to a certain local image patch exceeds the preset corrosion depth threshold, it is determined that there is significant corrosion in that area, and further analysis of its type is required. The morphological matching coefficient is calculated using Hu moment invariants. First, the binarized shape contour of the significantly corroded area is extracted (based on the aforementioned active contour model results), and its first seven Hu moments are calculated. Hu moments are seven moment invariants that describe shape features and are invariant to translation, rotation, and scaling, forming a seven-dimensional feature vector. The max-min normalization method is used to combine the Hu moment vectors of all templates in the template library with the Hu moment vector of the current region to be tested. Normalize for each dimension (i.e., each Hu moment component): , in and These represent the minimum and maximum values ​​of all templates in the template library at the i-th Hu moment component, respectively. The Hu moment vector of this region is compared with the pre-calculated standard Hu moment vectors of various defects in the known defect type template library. The morphological matching coefficient is defined as the cosine similarity between two vectors, with a value between 0 and 1, where 1 indicates a perfect match. By finding the defect type with the highest matching coefficient in the template library, the specific defect classification of the current region can be determined.

[0050] By combining gradient distribution data with defect type, quantitative defect results are obtained. These results include at least the defect location, defect type, severity level, estimated depth, and edge gradient statistics. The severity level is determined based on the defect type and estimated depth, referring to a predefined grading rule table. For example, for "pitting corrosion," a depth less than 0.3 mm is considered mild, 0.3 to 1.0 mm is moderate, and greater than 1.0 mm is severe.

[0051] In step S16, based on the quantified defect results, morphological matching coefficients and local contrast differences are obtained, and compared with preset corrosion standards to confirm corrosion defects and obtain corrosion detection results, including: Based on the quantitative defect results, the morphological matching coefficient and local contrast difference are obtained and compared with the preset corrosion standard. If the morphological matching coefficient and the local contrast difference are higher than the preset corrosion standard, they are determined to be corrosion defects. Based on the corrosion defects, candidate images of the defects are identified and processed to obtain corrosion detection results.

[0052] Specifically, from the quantization defect results output in step S15, the morphological matching coefficient and local contrast difference are extracted. The morphological matching coefficient has been calculated in S15 using Hu moments and a template library, and its value is between 0 and 1. For the local contrast difference, supplementary calculations are required. For each defect region corresponding to the quantization defect result, based on the precise boundary obtained in S15, the average grayscale value within that region is calculated, and the average grayscale value of the outer annular buffer band (e.g., with a width of 3 pixels) directly adjacent to that region is also calculated. The absolute value of the difference between the two is the local contrast difference of that region.

[0053] It is worth noting that by analyzing thousands of defect samples confirmed as genuine corrosion by ultrasonic thickness measurement or metallographic analysis, their morphological matching coefficients and local contrast differences were calculated. These morphological matching values ​​and local contrast difference values ​​were used as preset corrosion standards. For example, the analysis found that 75% of the morphological matching coefficients of genuine corrosion defects were higher than 0.72, and statistically, 75% of these differences were higher than 18 gray levels. Therefore, the morphological matching threshold was set to 0.72, and the local contrast difference threshold was set to 18. The two together constitute the preset corrosion standards.

[0054] Furthermore, the acquired morphological matching coefficients and local contrast differences are compared with preset corrosion standards. For each item in the quantified defect results, both its morphological matching coefficient and local contrast difference are checked simultaneously. Both data must simultaneously meet the preset corrosion threshold for the area corresponding to that item to be identified as a corrosion defect. If only one is met, for example, if the morphological matching coefficient is high but the contrast difference is small, it may only be a change in surface texture; if the contrast difference is large but the morphology does not match, it may be due to lighting shadows or stains. This dual verification mechanism can effectively filter false alarms and improve the accuracy of confirmation.

[0055] Specifically, based on the confirmed list of corrosion defects, the original candidate defect images are labeled to generate the final corrosion detection result image. The labeling process involves drawing a precise outline of each confirmed corrosion defect in red on the image, labeling the defect's number, type, and severity level near the outline, and generating a structured inspection report listing detailed information for all confirmed corrosion defects, including location coordinates, type, severity level, estimated depth, morphological matching coefficient, and local contrast difference value. This result image and the report together constitute the system's final output and can be directly used to guide equipment maintenance or safety assessments.

[0056] In step S17, historical image data is acquired, preprocessed to obtain adjusted historical data, the corrosion detection results are compared with the adjusted historical data, the quality assessment parameters of the corrosion defect detection process are updated, and optimized image processing rules are generated, including: Acquire historical image data, which includes the degree of image distortion and noise distribution density; clean the historical image data to obtain adjusted historical data. The corrosion detection results are compared with the historical adjustment data to obtain the comparison difference results. The original surface image is then adjusted based on the comparison difference results to obtain optimized image parameters. Based on the optimized image parameters, the quality assessment parameters of the corrosion defect detection process are updated, and optimized image processing rules are generated.

[0057] It should be noted that the historical image data originates from stored original surface images of the same or similar containers detected at different times, along with their corresponding real defect annotations verified manually or by high-precision equipment. These historical original images undergo unified distortion correction and noise assessment and suppression to obtain adjusted historical data. During distortion correction, if the camera lens parameters are known, the Zhang Zhengyou calibration method based on camera intrinsic parameters is used for radial and tangential distortion correction; if unknown, geometric correction is performed using known linear features in the image (such as container welds) through perspective transformation constrained by linear lines. In noise assessment and suppression, the noise distribution density of each image is calculated using the method in step S12. For images with high noise density, a non-local means denoising algorithm is used for overall noise reduction. This algorithm performs a weighted average by searching all similar regions in the image.

[0058] Specifically, for each pixel i in the image, a square neighborhood of size (2r+1)×(2r+1) centered on it is defined (e.g., r=3, i.e., a 7x7 neighborhood). The grayscale vectors of all pixels within this neighborhood are calculated. Then, for each other pixel j in the image, the weighted Euclidean distance between the grayscale vectors of the neighborhoods of pixel i and pixel j is calculated to measure the similarity of the neighborhood structures of the two pixels. The smaller the distance, the higher the similarity. The contribution weight of pixel j to pixel i is... The formula is calculated using a Gaussian function: .in and are the neighborhood grayscale vectors of pixels i and j, respectively, and h is a filtering parameter that controls the attenuation level and is related to the noise level. The denoised grayscale value of pixel i is... This is the weighted average of the gray values ​​of all pixels j, calculated using the following formula: The processed data becomes the historical benchmark adjustment data used for comparison.

[0059] It is worth noting that the corrosion detection results obtained in step S16 are compared with the corresponding historical adjustment data, and the comparison difference is calculated. The consistency difference in defect detection is statistically analyzed, including the percentage of areas missed in the current detection within the areas marked as true corrosion in the historical adjustment data, and the percentage of areas detected by the system but not marked in the historical adjustment data. Within the corrosion defect areas confirmed by both systems, the same image quality parameters, including the image sharpness rating and noise distribution density used in step S12, are calculated from both the original surface image and the preprocessed image corresponding to the historical adjustment data, and the absolute difference between the two is calculated. The consistency difference in defect detection and the difference in image quality parameters together constitute the comparison difference result.

[0060] Furthermore, based on the comparison results, the parameters for preprocessing in step S11 and quality assessment enhancement in step S12 are adjusted. The adjustment strategy is based on difference analysis. If the percentage of missed detections exceeds 15% in three consecutive scans of the same inspected container area, or exceeds 25% in a single scan, it indicates insufficient sensitivity. In this case, the noise distribution density threshold used in step S12 to determine whether image enhancement should be performed should be lowered (e.g., gradually reduced from a baseline of 8 points per square centimeter to 6 points), and the contrast limit of the CLAHE algorithm in step S11 should be appropriately increased. If the percentage of false detections exceeds 10% in three consecutive scans, or exceeds 20% in a single task, it indicates insufficient system specificity. In this case, the noise distribution density value in step S12 should be increased (e.g., gradually increased from a baseline of 8 points per square centimeter to 10 points), and the contrast limit of CLAHE should be reduced.

[0061] The above parameter adjustments are performed incrementally with a fixed step size. Specifically, the baseline noise density threshold is set to T0 (e.g., 8 points per square centimeter). When the false negative rate adjustment condition is met, the new noise density threshold T_new is set to max(T_min, T_old - ΔT), where ΔT is the downward adjustment step size (e.g., 0.5 points per square centimeter), and T_min is the preset lower limit (e.g., 6 points). The contrast limit value ClipLimit_new of the CLAHE algorithm is simultaneously set to min(ClipLimit_max, ClipLimit_old + ΔC), where ΔC is the upward adjustment step size (e.g., 0.1), and ClipLimit_max is the preset upper limit (e.g., 3.0). When the false positive rate triggers an upward adjustment, the adjustment direction is reversed. The adjustment strategy for the sharpness analysis weights is similar; for example, the adjustment step size for the weight w0 at the high resolution scale (L0) is Δw = 0.05.

[0062] It should be noted that, based on the optimized image parameters, the quality assessment parameters in the entire corrosion defect detection process are updated. The noise density value, CLAHE parameter, and sharpness analysis weight obtained in this optimization are used to replace the corresponding parameters in the original process. The optimized image processing rules include parameter preset rules based on scene classification. First, the illumination mode is quantized. In the initial stage of image preprocessing in step S11, the grayscale mean M_raw and variance V_raw are calculated from the original grayscale image. At the same time, the Sobel operator is used to calculate the overall gradient magnitude mean G_avg of the image to characterize the saliency of texture and edges.

[0063] The following classifications are then defined: if V_raw < 300 and G_avg < 20, it is classified as uniform lighting; if V_raw > 800 or G_avg > 50, it is classified as high contrast and complex texture; if M_raw < 60, it is classified as generally low lighting; and all other cases are classified as normal lighting. This classification aims to distinguish macroscopic image types that require different enhancement strategies.

[0064] The rule generation process includes recording the illumination mode, parameter set used, and false positive and false negative rates for each detection task. A historical parameter-result database is maintained for each illumination mode. When the historical average false positive rate for a certain mode exceeds the preset false positive rate target value (e.g., 15%) for three consecutive calculations, the rule optimization process for that mode is triggered. The optimization process involves selecting all tasks with a false negative rate lower than the preset false negative rate target value (e.g., 15%) from the historical data of that mode, then selecting the 5 tasks with the lowest false positive rates, and taking the median of each parameter in the parameter set used by these tasks (noise distribution density threshold, CLAHEClip Limit, etc.) to form a new optimized parameter set. This optimized parameter set will directly replace the original recommended parameter set for that mode.

[0065] For example, for high-contrast / complex texture modes, if the historical average false detection rate continuously exceeds the preset target, the above optimization is triggered. The generated new optimized parameter set includes a noise distribution density threshold of 10 points per square centimeter and CLAHEClip Limit=1.5. This optimized parameter set will be automatically loaded and applied in the next detection of the same type.

[0066] In summary, this invention discloses a visual inspection-based method for detecting corrosion defects in containers, which realizes an adaptive image quality assessment and processing mechanism under complex imaging conditions, thereby improving the accuracy of visual inspection of corrosion defects in containers.

[0067] Reference Figure 2 The second embodiment of the present invention provides a container corrosion defect detection system based on vision inspection, comprising: The image acquisition and processing module is used to acquire the original surface image, preprocess the original surface image and divide it into regions to obtain an initial segmented image. The image quality assessment and enhancement module is used to analyze the noise distribution density based on the initial segmented image. If the noise distribution density does not meet the preset image standard, the initial segmented image is enhanced to obtain an optimized surface image. The feature extraction and defect identification module is used to extract edge feature data based on the optimized surface image, calculate contrast difference and defect region division based on the edge feature data, and obtain a preliminary defect region map. The expansion and filtering module is used to calculate the defect area ratio based on the preliminary defect area map, compare the defect area ratio with the preset defect standard, and obtain a defect candidate map. The quantification and classification module is used to extract corrosion depth distribution data based on the defect candidate image, analyze the corrosion depth distribution data, and obtain quantified defect results. The defect confirmation module is used to obtain the morphological matching coefficient and local comparison difference based on the quantitative defect results, and compare them with the preset corrosion standard to confirm the corrosion defect and obtain the corrosion detection result. The rule optimization and update module is used to acquire historical image data, preprocess the historical image data to obtain adjusted historical data, compare the corrosion detection results with the adjusted historical data, update the quality assessment parameters of the corrosion defect detection process, and generate optimized image processing rules.

[0068] It should be noted that the container corrosion defect detection system based on vision inspection provided in this embodiment of the invention is used to execute all the process steps of the container corrosion defect detection method based on vision inspection in the above embodiment. The working principles and beneficial effects of the two are one-to-one, so they will not be described again.

[0069] This invention also provides an electronic device. The electronic device includes a processor, a memory, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the steps in the various embodiments of the vision-based container corrosion defect detection method described above, for example... Figure 1 The step S11 shown. Alternatively, when the processor executes the computer program, it implements the functions of each module / unit in the above-described device embodiments.

[0070] For example, the computer program may be divided into one or more modules / units, which are stored in the memory and executed by the processor to complete the present invention. The one or more modules / units may be a series of computer program instruction segments capable of performing a specific function, which describe the execution process of the computer program in the electronic device.

[0071] The electronic device may be a desktop computer, laptop, handheld computer, or smart tablet, etc. The electronic device may include, but is not limited to, a processor and memory. Those skilled in the art will understand that the above components are merely examples of electronic devices and do not constitute a limitation on the electronic device. It may include more or fewer components than described above, or combine certain components, or different components. For example, the electronic device may also include input / output devices, network access devices, buses, etc.

[0072] The processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor. The processor is the control center of the electronic device, connecting all parts of the electronic device via various interfaces and lines.

[0073] The memory can be used to store the computer programs and / or modules. The processor implements various functions of the electronic device by running or executing the computer programs and / or modules stored in the memory and by calling data stored in the memory. The memory may mainly include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the mobile phone (such as audio data, phonebook, etc.). In addition, the memory may include high-speed random access memory, and may also include non-volatile memory, such as hard disk, memory, plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, at least one disk storage device, flash memory device, or other volatile solid-state storage device.

[0074] Wherein, if the modules / units integrated in the electronic device are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments of the present invention can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium can be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electrical carrier signals and telecommunication signals.

[0075] It should be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Furthermore, in the accompanying drawings of the device embodiments provided by this invention, the connection relationships between modules indicate that they have communication connections, which can be specifically implemented as one or more communication buses or signal lines. Those skilled in the art can understand and implement this without any creative effort.

[0076] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. In particular, it should be noted that any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention for those skilled in the art.

Claims

1. A method for detecting corrosion defects in containers based on visual inspection, characterized in that, include: The original surface image is acquired, and the original surface image is preprocessed and divided into regions to obtain an initial segmented image; Based on the initial segmented image, the noise distribution density is analyzed. If the noise distribution density does not meet the preset image standard, the initial segmented image is enhanced to obtain an optimized surface image. Based on the optimized surface image, edge feature data is extracted, and contrast difference and defect region division are calculated based on the edge feature data to obtain a preliminary defect region map. The defect area ratio is calculated based on the preliminary defect area map, and the defect area ratio is compared with the preset defect standard to obtain a defect candidate map. Based on the defect candidate map, corrosion depth distribution data is extracted, and the corrosion depth distribution data is analyzed to obtain quantitative defect results. Based on the quantitative defect results, the morphological matching coefficient and local comparison difference are obtained, and compared with the preset corrosion standard to confirm the corrosion defects and obtain the corrosion detection results. Historical image data is acquired, preprocessed to obtain adjusted historical data, the corrosion detection results are compared with the adjusted historical data, the quality assessment parameters of the corrosion defect detection process are updated, and optimized image processing rules are generated.

2. The method for detecting container corrosion defects based on visual inspection according to claim 1, characterized in that, The process of acquiring the original surface image, preprocessing the original surface image, and dividing it into regions to obtain an initial segmented image includes: Obtain the original surface image of the container, and perform grayscale conversion and brightness equalization processing on the original surface image to obtain the first processed image; Brightness features are extracted from the first processed image. If the brightness features exceed a preset uniformity threshold, the local contrast of the first processed image is adjusted to obtain the second processed image. The second processed image is refined to obtain the boundary sharpness. If the boundary sharpness reaches the preset sharpness standard, the initial segmented image is output.

3. The method for detecting container corrosion defects based on visual inspection according to claim 1, characterized in that, The step involves analyzing the noise distribution density based on the initial segmented image. If the noise distribution density does not meet a preset image standard, the initial segmented image is then enhanced to obtain an optimized surface image, including: The initial segmented image is subjected to layer processing to extract sharpness distribution data; Based on the sharpness distribution data, noise density is detected in the initial segmented image to determine the noise distribution density; If the noise distribution density exceeds the preset image standard, the initial segmented image is subjected to brightness adjustment and image enhancement processing to obtain an optimized surface image.

4. The method for detecting container corrosion defects based on visual inspection according to claim 1, characterized in that, The step of extracting edge feature data based on the optimized surface image, calculating contrast differences and defect region division based on the edge feature data, and obtaining a preliminary defect region map includes: Edge features are extracted from the optimized surface image to obtain edge feature data, which includes an edge blur index. Based on the edge feature data, the contrast difference of the optimized surface image is calculated to obtain contrast deviation data; The edge blur index and the contrast deviation data are weighted and calculated to obtain the boundary sharpness data; Based on the boundary sharpness data, the optimized surface image is divided and labeled to generate a preliminary defect area map.

5. The method for detecting container corrosion defects based on visual inspection according to claim 1, characterized in that, The step of calculating the defect area ratio based on the preliminary defect area map, comparing the defect area ratio with a preset defect standard, and obtaining a defect candidate map includes: Based on the preliminary defect area map, the defect area ratio and defect aggregation degree are calculated, and the pixel gray value variance and gray matrix contrast are obtained. Based on the pixel gray value variance and the gray matrix contrast, local feature difference and texture anomaly index are calculated respectively. By combining the local feature difference and the texture anomaly index, boundary division is performed to determine the extended boundary range data. Based on the extended boundary range data, if the extended boundary range data meets a preset extension threshold, the extended boundary range data is marked as a region to be confirmed, and the distribution data of the region to be confirmed is obtained. Based on the distribution data of the areas to be confirmed, the abnormal distribution density is calculated, and the abnormal distribution density is compared with the degree of defect aggregation to determine the priority ranking of the areas. Based on the region priority ranking, the defect area ratio is compared with the preset defect standard to obtain a defect candidate map.

6. The method for detecting container corrosion defects based on visual inspection according to claim 1, characterized in that, The step of extracting corrosion depth distribution data based on the defect candidate map, analyzing the corrosion depth distribution data, and obtaining quantitative defect results includes: Based on the defect candidate image, local image blocks are extracted, and the boundaries of the local image blocks are divided to obtain boundary pixel distribution data; Based on the boundary pixel distribution data, the pixel change amplitude is calculated, gradient distribution data is obtained based on the pixel change amplitude, and corrosion depth distribution data is determined based on the gradient distribution data. If the corrosion depth distribution data exceeds the preset corrosion depth threshold, then the morphology matching coefficient is calculated, and the defect type is matched according to the morphology matching coefficient. Based on the gradient distribution data and the defect type, the quantified defect result is obtained.

7. The method for detecting container corrosion defects based on visual inspection according to claim 1, characterized in that, The step involves obtaining morphological matching coefficients and local contrast differences based on the quantified defect results, and comparing them with preset corrosion standards to confirm corrosion defects and obtain corrosion detection results, including: Based on the quantitative defect results, the morphological matching coefficient and local contrast difference are obtained and compared with the preset corrosion standard. If the morphological matching coefficient and the local contrast difference are higher than the preset corrosion standard, they are determined to be corrosion defects. Based on the corrosion defects, candidate images of the defects are identified and processed to obtain corrosion detection results.

8. The method for detecting container corrosion defects based on visual inspection according to claim 1, characterized in that, The process includes acquiring historical image data, preprocessing the historical image data to obtain adjusted historical data, comparing the corrosion detection results with the adjusted historical data, updating the quality assessment parameters of the corrosion defect detection process, and generating optimized image processing rules, including: Acquire historical image data, which includes the degree of image distortion and noise distribution density; clean the historical image data to obtain adjusted historical data. The corrosion detection results are compared with the historical adjustment data to obtain the comparison difference results. The original surface image is then adjusted based on the comparison difference results to obtain optimized image parameters. Based on the optimized image parameters, the quality assessment parameters of the corrosion defect detection process are updated, and optimized image processing rules are generated.

9. A visual inspection-based container corrosion defect detection system, used to implement the visual inspection-based container corrosion defect detection method according to any one of claims 1 to 8, characterized in that, include: The image acquisition and processing module is used to acquire the original surface image, preprocess the original surface image and divide it into regions to obtain an initial segmented image. The image quality assessment and enhancement module is used to analyze the noise distribution density based on the initial segmented image. If the noise distribution density does not meet the preset image standard, the initial segmented image is enhanced to obtain an optimized surface image. The feature extraction and defect identification module is used to extract edge feature data based on the optimized surface image, calculate contrast difference and defect region division based on the edge feature data, and obtain a preliminary defect region map. The expansion and filtering module is used to calculate the defect area ratio based on the preliminary defect area map, compare the defect area ratio with the preset defect standard, and obtain a defect candidate map. The quantification and classification module is used to extract corrosion depth distribution data based on the defect candidate image, analyze the corrosion depth distribution data, and obtain quantified defect results. The defect confirmation module is used to obtain the morphological matching coefficient and local comparison difference based on the quantitative defect results, and compare them with the preset corrosion standard to confirm the corrosion defect and obtain the corrosion detection result. The rule optimization and update module is used to acquire historical image data, preprocess the historical image data to obtain adjusted historical data, compare the corrosion detection results with the adjusted historical data, update the quality assessment parameters of the corrosion defect detection process, and generate optimized image processing rules.