Defect detection method based on image processing

By using an image processing-based method, integrating integral images and multi-scale gradient operators to extract crack features, adaptively adjusting the threshold, and combining morphological operations, the high computational complexity of existing technologies is solved, achieving efficient and accurate crack detection for non-standard industrial products.

CN121120618AInactive Publication Date: 2025-12-12WEIFANG UNIV OF SCI & TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511605946.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-05
Publication Date
2025-12-12
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

In existing technologies, when using the CA algorithm to detect crack defects in non-standard industrial products, the computational complexity of gradient difference calculation and CA iteration process is high, resulting in a large amount of computation, which is not suitable for real-time industrial inspection scenarios.

Method used

An image processing-based defect detection method is adopted. By calculating the integral image and square integral image of the grayscale image, the gradient magnitude is extracted using the multi-scale Sobel or Scharr operator. The average gray level and variance of the neighborhood window are calculated by combining the integral image, the gradient fluctuation degree is quantified, the threshold is adaptively adjusted, the crack area is located, and the detection results are optimized through morphological operations.

Benefits of technology

It significantly reduces computational complexity from O(N2) to O(1), supports online detection of high-definition images, improves detection speed and accuracy, adapts to defects of different sizes, reduces false detections, and meets the timeliness requirements of industrial scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121120618A_ABST
    Figure CN121120618A_ABST
Patent Text Reader

Abstract

The invention discloses a defect detection method based on image processing, and the method comprises the following steps: data input and preprocessing: obtaining a surface grayscale image of a non-standard industrial product through an industrial camera, and calculating an integrogram and a square integrogram of the grayscale image; multi-scale feature extraction and fusion: calculating a multi-scale gradient amplitude, calculating an average gray scale and a gray scale variance in different neighborhood windows in combination with an integrogram, fusing each scale crack prediction factor through a maximum value to obtain a crack tendency feature, and retaining the response of the most significant scale of the crack; evaluating crack degree and adjusting a self-adaptive threshold: calculating a variance of a gradient difference value of a pixel point and a neighborhood of the pixel point as a gradient difference, and adjusting an initial threshold by utilizing an exponential function to obtain a self-adaptive threshold; positioning a crack area: selecting the first K pixels with the highest crack degree as seed points to focus the high-risk area, and defining a growth rule; post-processing and defect output: outputting defect detection results of marked crack positions and outlines.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of defect detection, in particular to a defect detection method based on image processing. BACKGROUND

[0002] With the acceleration of industrial manufacturing towards high precision, high automation and intelligence, in the manufacturing process of non-standard industrial products, processing techniques such as cutting, stamping and welding may leave geometric features such as sharp edges or uneven marks on the surface of the product. When there is a crack on the surface of the product, the edge of the crack may be similar to the edge of these geometric features, making crack detection complex. The non-standard industrial product defect detection technology based on image processing integrates advanced technologies such as computer vision, machine learning and deep learning, and combines image acquisition, preprocessing, feature extraction and defect classification, etc. key processes, which can realize high-precision, non-contact and real-time online detection of surface or internal defects of non-standard industrial products. Its background significance lies in breaking through the bottleneck of traditional detection methods, improving detection efficiency and stability, reducing labor costs, ensuring product quality consistency, and providing technical support for the intelligent and digital transformation of industrial manufacturing. It realizes the automatic and intelligent identification and classification of defects, improves detection accuracy and production efficiency, reduces enterprise operating costs, promotes the quality control, process optimization and production process improvement of the whole process of industrial manufacturing, enhances the market competitiveness of enterprises, and meets the urgent needs of modern industry for high-quality, high-efficiency and high-reliability production system.

[0003] In the prior art, CA algorithm is used for crack defect detection of non-standard industrial products, and the gradient difference calculation and CA iteration process calculation have high complexity, resulting in large amount of calculation, which is not suitable for real-time industrial detection scene. Therefore, a defect detection method based on image processing is proposed. SUMMARY

[0004] The purpose of the present application is to solve the shortcomings of the prior art and propose a defect detection method based on image processing.

[0005] In order to achieve the above purpose, the present application adopts the following technical scheme: A defect detection method based on image processing, comprising the following steps: Data input and preprocessing: obtaining a non-standard industrial product surface gray image through an industrial camera, calculating the integral image and square integral image of the gray image; Multi-scale feature extraction and fusion: calculating multi-scale gradient amplitude using different sizes of Sobel or Scharr operators, calculating the average gray value and gray variance in different neighborhood windows combined with the integral image, and obtaining crack tendency features by fusing crack prediction factors of each scale through maximum value, and retaining the response of the most significant scale of crack; Crack degree evaluation and adaptive threshold adjustment: the variance of the gradient difference between a pixel and its neighborhood is calculated as the gradient difference, and then the gradient fluctuation degree is quantified, and the comprehensive crack degree is obtained by the normalized product of the crack tendency feature after fusion, and the adaptive threshold is obtained by adjusting the initial threshold using the exponential function; Crack region localization: the top K pixels with the highest crack degree are selected as seed points to focus on the high-risk area, and the growth rule is defined, which requires that the new pixel point meets the significant value less than the adaptive threshold, the gradient direction angle with the average gradient direction of the region less than the threshold, and the texture feature similarity higher than the threshold, so as to locate the crack region; Post-processing and defect output: through connected component analysis, filter the small noise region with the pixel number less than the threshold and retain the real crack, combine with morphological opening and closing operation to optimize the shape of crack region, and output the defect detection result of labeled crack position and contour.

[0006] The above further comprises: Further, in the data input and preprocessing, the specific steps of calculating the integral image and the square integral image of the gray image are: Gray image acquisition: acquire the surface image of non-standard industrial products through industrial camera or sensor, and convert it into gray image; Integral image calculation: the integral image Int(x, y) represents the sum of all pixel values in the rectangular region from the top left corner (0, 0) to the current pixel point (x, y) in the original image I, and the calculation formula is represented as ; Square integral image calculation: the square integral image SqInt(x, y) represents the sum of squares of all pixel values in the rectangular region from the top left corner (0, 0) to the current pixel point (x, y) in the original image I, and the calculation formula is represented as: ; Fast region statistics: through integral image and square integral image, the mean And variance Of any rectangular region R can be calculated in constant time.

[0007] Further, in the multi-scale feature extraction and fusion, the specific steps of obtaining the crack tendency feature by fusing the crack prediction factors of each scale through maximum value are: Multi-scale gradient amplitude calculation: capture the edges of cracks with different widths through different sizes of Sobel / Scharr operators; Multi-scale region statistics: calculate the average gray And gray variance Of different neighborhood windows through integral image, which adapts to the difference of surface material; Crack prediction factor calculation and fusion: calculate the crack prediction factor and maximum fusion is performed; Single-scale crack predictor: for each scale, calculate: where, is the number of pixels in the gray image with the same gray value as the i-th pixel; Multi-scale fusion: take the maximum value of the crack predictor of each scale as the final crack tendency feature: .

[0008] Further, in the crack degree evaluation and adaptive threshold adjustment, the specific steps of calculating the gradient difference are: Step 1: Calculate the gradient value G(x,y) of the pixel point (x,y); Step 2: Calculate the gradient value of all pixel points in the neighborhood window where, ; Step 3: Calculate the variance of the gradient difference, the calculation formula is represented as: where, is the mean value of the gradient difference, and N is the number of neighborhood pixels.

[0009] Further, in the crack degree evaluation and adaptive threshold adjustment, the specific steps of adjusting the initial threshold value to obtain the adaptive threshold value using the exponential function are: Comprehensive crack degree calculation: combine the gradient difference and the crack tendency feature , quantify the crack degree by normalizing the product, represented as , where the normalization operation linearly maps the result to the [0,1] interval: ; Initial threshold setting: set the initial threshold ; Adaptive threshold adjustment: dynamically adjust the threshold value through the exponential function, the threshold value of the high crack risk area is raised, and the threshold value of the low risk area is lowered, represented as where, is the adjustment coefficient.

[0010] Further, in the positioning of the crack area, the specific steps of introducing the ecological correction coefficient and the implicit value correction coefficient to negatively adjust the economic contribution value are: Seed point selection: select the first K maximum values corresponding to the pixels as the seed points by calculating the comprehensive crack degree of all pixel points and sorting them in descending order; Define growth rules: including the significance value being less than the adaptive threshold value, the gradient direction consistency, and the texture feature similarity; Region growing: initialize the seed point set S and take each seed point as an independent region iteratively check its 8-neighborhood of pixels p, if all the above conditions are satisfied, pixel p is incorporated into region and the average gradient direction and average LBP feature of region R are updated until all the neighborhood pixels do not satisfy the growing conditions.

[0011] Further, the definition of growing rules includes: a saliency value less than an adaptive threshold: wherein, is the crack degree of pixel p, is its adaptive threshold; a gradient direction consistency: calculate the gradient direction of pixel p, denoted as , calculate the average gradient direction of current region R, denoted as wherein, N is the number of pixels in region R, judge whether the angle between the gradient direction of pixel p and the average gradient direction of region is less than a threshold , denoted as ; a texture feature similarity: calculate the LBP texture feature LBP(p) of pixel p, calculate the average LBP feature of current region R, denoted as , judge whether the Hamming distance between the LBP feature of pixel p and the average LBP feature of region is less than a threshold , denoted as .

[0012] Further, in the post-processing and defect output, the specific steps of filtering small noise regions with pixel number less than a threshold and retaining real cracks by connected component analysis are: Step 1: perform connected component labeling on the crack region mask output by the region growing algorithm, use the Flood Fill algorithm or two-pass scanning method to assign a unique label to each independent crack region; Step 2: count the number of pixels in each connected component; Step 3: set a pixel threshold, filter the connected components that satisfy the pixel number less than the pixel threshold.

[0013] Further, in the post-processing and defect output, the specific steps of optimizing the shape of the crack region by morphological opening and closing operation are: Step 1: define a morphological structure element B; Step 2: perform opening operation to remove crack edge burrs, denoted as wherein, is the erosion operation, for inflation operation; Step 3: Perform the close operation, fill the crack inside the hole: .

[0014] Further, in the post-processing and defect output, the specific steps of outputting the defect detection result of marking the crack position and contour; Step 1: Superimpose the crack region mask after morphological processing on the original gray image; Step 2: Extract the crack contour using the boundary tracking algorithm, draw the bounding box or contour line; Step 3: Generate a detection report.

[0015] The present application has the following beneficial effects: 1、In the present application, the integral image and the square integral image of the gray image are calculated, the pixel sum and the square sum of any rectangular region are obtained in constant time through the integral image, and then the mean and the variance are calculated, the gray difference statistics are used instead of the traditional entropy calculation, the calculation complexity of the neighborhood statistics is reduced from O(N2) to O(1), the processing speed is significantly improved, the online detection of high-definition images is supported, and the demand for timeliness in industrial scenes is met.

[0016] 2、In the present application, the previous point with the maximum multi-scale crack tendency feature value is taken as a seed point, a high crack tendency region is preferentially grown, if the significance condition, the direction consistency and the texture similarity are met, the pixel is merged into the region and the average gradient direction and the average LBP feature of the region are updated, the direction consistency constraint simulates the physical property that the crack expands along a certain direction, avoids the connected domain from being broken due to the disorderly direction, the texture similarity constraint filters the noise with a significant difference from the crack texture, reduces the false detection, and the effective detection region is dynamically adjusted through the seed point selection and the growth condition, a fixed pixel threshold is replaced, and different size defects are adapted. BRIEF DESCRIPTION OF DRAWINGS

[0017] Figure 1 A step diagram of a defect detection method based on image processing is provided in the present application. DETAILED DESCRIPTION

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

[0019] Please refer to Figure 1 The present application is a defect detection method based on image processing, which comprises the following steps: Data input and preprocessing: Acquire grayscale images of non-standard industrial product surfaces using industrial cameras to simplify computational complexity and highlight grayscale abrupt changes (such as cracks), and calculate the integral and square integral images of the grayscale images; Multi-scale feature extraction and fusion: Multi-scale gradient magnitudes are calculated using Sobel or Scharr operators of different sizes to capture cracks of different widths (small-scale operators are needed for fine cracks, and large-scale operators are needed for wide cracks). The average gray level and gray level variance within different neighborhood windows are calculated by combining integral images to adapt to the gray level distribution differences of surface materials (rough / smooth). Crack tendency features are obtained by fusing crack prediction factors at each scale (calculated based on gray level differences and neighborhood sparsity) by the maximum value. The response of the most significant crack scale is retained to improve detection sensitivity. Crack severity assessment and adaptive threshold adjustment: The variance of the gradient difference between a pixel and its neighborhood is calculated as the gradient difference, which quantifies the severity of gradient fluctuation. Combined with the fused crack tendency features, the comprehensive crack severity is obtained through normalized multiplication. The initial threshold is adjusted using an exponential function (the initial threshold is based on a globally fixed value or automatically calculated by the Otsu algorithm) to obtain an adaptive threshold. This achieves dynamic adaptive adjustment by increasing the threshold in high-risk crack areas to suppress noise and decreasing the threshold in low-risk areas to avoid missed detections. Locating crack regions: Select the top K pixels with the highest crack severity as seed points to focus on high-risk areas. Define growth rules that require new pixels to meet the following conditions: the significance value (crack severity) is less than the adaptive threshold (original condition), the angle between the gradient direction and the average gradient direction of the region is less than the threshold (direction consistency to avoid edge noise and false connectivity), and the similarity of texture features (such as LBP) is higher than the threshold (filtering periodic texture interference). Post-processing and defect output: By analyzing connected components, tiny noise regions with fewer than a threshold pixels are filtered out while retaining real cracks. Morphological opening and closing operations (erosion followed by dilation to remove burrs, dilation followed by erosion to fill voids) are combined to optimize the shape of the crack region and output defect detection results with marked crack locations and contours.

[0020] In one embodiment, the specific steps for calculating the integral image and square integral image of the grayscale image during data input and preprocessing are as follows: Grayscale image acquisition: Acquire surface images of non-standard industrial products (usually RGB color images) through industrial cameras or sensors and convert them into grayscale images. Grayscale images simplify computational complexity and highlight grayscale abrupt changes such as cracks. If the original image is in color, the conversion formula is as follows: ,in, These are the red, green, and blue channel values ​​of the pixel (x, y), respectively, and I(x, y) is the converted grayscale value (range 0-255). Integral image calculation: The integral image Int(x,y) represents the sum of all pixel values ​​within the rectangular region from the top left corner (0,0) to the current pixel (x,y) in the original image I. The calculation formula is expressed as follows: Alternatively, it can be calculated efficiently using a recursive formula: ( ); Square integral image calculation: The square integral image SqInt(x,y) represents the sum of the squares of all pixel values ​​within the rectangular region from the top left corner (0,0) to the current pixel (x,y) in the original image I. The calculation formula is as follows: Alternatively, it can be calculated efficiently using a recursive formula: ; Rapid region statistics: Calculates the mean of any rectangular region R in constant time using integral and square integral plots. and variance ; Sum of regions and sum of squares: The upper left corner of region R is... The bottom right corner is ; and: ; Sum of squares: ; Mean and variance: Number of pixels: ; Mean: ; variance: .

[0021] In one embodiment, the specific steps for obtaining crack tendency features by fusing crack prediction factors at each scale through maximum value fusion in multi-scale feature extraction and fusion are as follows: Multi-scale gradient magnitude calculation: Crack edges of different widths are captured by Sobel / Scharr operators of different sizes (small-scale operators are needed for fine cracks, and large-scale operators are needed for wide cracks). 3×3 Sobel operator (standard small scale): , ; 5×5 Sobel operator (medium scale): , ; 7×7 Sobel operator (large scale): , ; Scharr operator: , ; Gradient magnitude calculation: For each pixel (x, y), calculate the horizontal gradient using operators of different scales. and vertical gradient The gradient magnitude is: ; Small-scale operators (such as 3×3) are sensitive to fine crack edges and capture details; Large-scale operators (such as 7×7) are more robust to wide crack edges and suppress noise; Multi-scale regional statistics: Quickly calculate the average gray level of different neighborhood windows (e.g., 3×3, 5×5, 7×7) using integral images. and gray variance Adaptable to differences in surface materials; Neighborhood window definition: Scale 1 (Small): 3×3 window; Scale 2 (Medium): 5×5 window; Scale 3 (Large): 7x7 window; Mean and variance calculation: Using the integral image Int and square integral image SqInt calculated in the preprocessing stage, the mean and variance are calculated within the corresponding scale window for each pixel (x,y); Small-scale windows (3×3) focus on local details and adapt to smooth surfaces; Large-scale windows (7×7) can statistically cover a wider area and are suitable for rough surfaces (with large differences in grayscale distribution). Crack predictor calculation and fusion: Calculating crack predictors at each scale And perform maximum fusion to retain the response at the most salient scale; Single-scale crack predictor: For each scale, calculate: ,in, The number of pixels in the grayscale image that have the same grayscale value as the i-th pixel (neighborhood sparsity term); Multi-scale fusion: The maximum value of the predictor at each scale is taken as the final crack tendency feature. ; Single scale factor Measure local grayscale contrast and sparsity to highlight abnormal grayscale points (potential cracks). Maximum value fusion preserves the response at the most significant scale of the crack, avoiding missed detection at a single scale (such as fine cracks being blurred at large scales).

[0022] In this embodiment: Suppose that there is a fine crack (1 pixel wide) and a wide crack (3 pixels wide) on the surface of a non-standard industrial product.

[0023] The local area of ​​the grayscale image is shown below (the higher the brightness, the larger the grayscale value; the crack is represented by a dark band): ; Step 1: Multi-scale gradient calculation 3×3 Sobel operator: The gradient amplitude of the fine crack edge (2nd row, 2nd column) is high (gray level jumps from 200 to 100).

[0024] The gradient amplitude is low at the center of the wide crack (3rd row, 3rd column) (uniform grayscale 100).

[0025] 7×7 Sobel operator: The edges of fine cracks are blurred, and the gradient amplitude is reduced.

[0026] The gradient amplitude is high at the edge of the wide crack (overall 100→200 jump).

[0027] Step 2: Multi-scale regional statistics 3×3 window (fine crack area): mean ≈150, variance ≈2500.

[0028] 7×7 window (wide crack area): mean ≈150, variance ≈1000.

[0029] Step 3: Crack Prediction Factor Calculation 3×3 scale (fine crack): The absolute value is 1. 7×7 scale (wide crack): The absolute value is 1.58; Step 4: Multi-scale fusion Fine cracks show a significant response at the 3×3 scale. =1), with a weak response at a 7×7 scale ( ≈0.5).

[0030] Wide cracks show a significant response at the 7×7 scale. =1.58), with a weak response at a 3×3 scale ( ≈0.8).

[0031] Features after fusion: =1.58 (Most significant for wide cracks) =max(1,0.5,0.8)=1 (Fine cracks are most noticeable) Results: Fine cracks were detected at a 3×3 scale, and wide cracks were detected at a 7×7 scale. Both were preserved after fusion.

[0032] In one embodiment, the specific steps for calculating the gradient difference in crack severity assessment and adaptive threshold adjustment are as follows: Step 1: Calculate the gradient value G(x,y) of pixel (x,y) (e.g., using the Scharr operator); Step 2: Calculate the gradient values ​​of all pixels within its neighborhood window (e.g., 3×3). ,in, ; Step 3: Calculate the variance of the gradient difference. The formula is as follows: ,in, Let N be the mean of the gradient difference, and N be the number of neighboring pixels.

[0033] In one embodiment, the specific steps for adjusting the initial threshold using an exponential function to obtain the adaptive threshold in crack severity assessment and adaptive threshold adjustment are as follows: Comprehensive crack severity calculation: combining gradient differences and crack tendency characteristics The degree of cracking is quantified by normalized product, and expressed as: The normalization operation linearly maps the result to the [0,1] interval (e.g., through min-max normalization): Product fusion takes grayscale contrast into account. and gradient fluctuations To improve crack characterization capabilities; Initial threshold setting: Set the initial threshold ; Calculated in two ways: Method 1 (Global Fixed Value): =A fixed value (e.g., 0.7 times the average grayscale value) Method 2 (Automatic calculation using Otsu's algorithm): Calculate the globally optimal threshold using Otsu's algorithm to maximize the inter-class variance. ,in, , Background / foreground pixel ratio , Mean value for background / foreground; Adaptive threshold adjustment: The threshold is dynamically adjusted through an exponential function, targeting high crack risk areas ( The high threshold increases, and the low-risk area ( The low threshold is reduced, which is expressed as ,in, This is an adjustment coefficient (controlling the threshold adjustment range, which can be optimized through experiments or AutoML).

[0034] In one embodiment, the specific steps for negatively adjusting the economic contribution value by introducing an ecological correction coefficient and a latent value correction coefficient in the location crack region are as follows: Seed point selection: After calculating the comprehensive crack severity of all pixels and sorting them in descending order, select the pixels corresponding to the top K maximum values ​​as seed points; Growth rules are defined, including significance values ​​less than an adaptive threshold, gradient direction consistency, and texture feature similarity. Region growing: This is achieved by initializing a seed point set S and treating each seed point as an independent region. Iteratively check the 8-neighborhood of its neighboring pixel p. If all the above conditions are met, then pixel p is merged into the region. And update the region average gradient direction and average LBP characteristics (Through dynamic feature update technology), the algorithm terminates when all neighboring pixels no longer meet the growth conditions.

[0035] In one embodiment, the defined growth rules include: Significance value less than adaptive threshold: ,in, The degree of cracking at pixel p. Set its adaptive threshold; Gradient direction consistency: Calculate the gradient direction of pixel p. , represented as Calculate the average gradient direction of the current region R. , represented as Where N is the number of pixels in region R, and the angle between the gradient direction of pixel p and the average gradient direction of the region is less than a threshold. , represented as ; Texture feature similarity: Calculate the LBP (Local Binary Pattern) texture feature LBP(p) of pixel p, and calculate the average LBP feature of the current region R. , represented as Determine whether the Hamming distance between the LBP feature of pixel p and the average LBP feature of the region is less than a threshold. , represented as .

[0036] In one embodiment, the specific steps for filtering out tiny noise regions with fewer than a threshold pixels and retaining real cracks through connected component analysis in post-processing and defect output are as follows: Step 1: Mark the connected components of the crack region mask output by the region growing algorithm, and assign a unique label to each independent crack region using the Flood Fill algorithm or the two-pass scanning method. Step 2: Count the number of pixels in each connected component; Step 3: Set a pixel threshold to filter connected components that have fewer than the pixel threshold.

[0037] In one embodiment, the specific steps for optimizing the shape of the crack region through morphological opening and closing operations in post-processing and defect output are as follows: Step 1: Define morphological structural element B (such as a 3×3 rectangular or circular core); Step 2: Perform an opening operation (corrosion followed by expansion) to remove burrs from the crack edges, as shown below. ,in, For corrosion operation, For expansion operation; Step 3: Perform a closing operation (expansion followed by erosion) to fill the voids inside the crack: .

[0038] In one embodiment, the specific steps for outputting defect detection results with marked crack locations and contours in post-processing and defect output are as follows: Step 1: Overlay the morphologically processed crack region mask onto the original grayscale image; Step 2: Use a boundary tracking algorithm (such as the Moore-Neighbor algorithm) to extract the crack contour and draw the bounding box or contour line; Step 3: Generate an inspection report, which includes information such as crack location (coordinates), area (number of pixels), and contour length.

[0039] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and variations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.

Claims

1. A defect detection method based on image processing, characterized in that, Includes the following steps: Data input and preprocessing: Acquire grayscale images of non-standard industrial product surfaces using an industrial camera, and calculate the integral image and square integral image of the grayscale images; Multi-scale feature extraction and fusion: The multi-scale gradient magnitude is calculated using Sobel or Scharr operators of different sizes. The average gray level and gray level variance in different neighborhood windows are calculated by combining the integral image. The crack tendency features are obtained by fusing the crack prediction factors of each scale through the maximum value, and the response of the most significant crack scale is retained. Crack severity assessment and adaptive threshold adjustment: The variance of the gradient difference between a pixel and its neighborhood is calculated as the gradient difference, which is then used to quantify the severity of gradient fluctuation. Combined with the fused crack tendency features, the comprehensive crack severity is obtained by normalization multiplication. The initial threshold is adjusted using an exponential function to obtain an adaptive threshold. Locating crack regions: Select the top K pixels with the highest crack severity as seed points to focus on high-risk areas. Define growth rules that require new pixels to meet the following conditions: the significance value is less than the adaptive threshold, the angle between the gradient direction and the average gradient direction of the region is less than the threshold, and the texture feature similarity is higher than the threshold, thereby locating crack regions. Post-processing and defect output: By analyzing connected components, tiny noise regions with fewer than a threshold pixels are filtered out while retaining real cracks. Morphological opening and closing operations are combined to optimize the shape of the crack region, and the defect detection results with labeled crack locations and contours are output.

2. The defect detection method based on image processing according to claim 1, characterized in that, The specific steps for calculating the integral image and square integral image of a grayscale image in data input and preprocessing are as follows: Grayscale image acquisition: Acquire images of the surface of non-standard industrial products using industrial cameras or sensors and convert them into grayscale images; Integral image calculation: The integral image Int(x,y) represents the sum of all pixel values ​​within the rectangular region from the top left corner (0,0) to the current pixel (x,y) in the original image I. The calculation formula is expressed as follows: ; Square integral image calculation: The square integral image SqInt(x,y) represents the sum of the squares of all pixel values ​​within the rectangular region from the top left corner (0,0) to the current pixel (x,y) in the original image I. The calculation formula is expressed as follows: ; Rapid region statistics: Calculates the mean of any rectangular region R in constant time using integral and square integral plots. and variance .

3. The defect detection method based on image processing according to claim 1, characterized in that, In multi-scale feature extraction and fusion, the specific steps for obtaining crack tendency features by fusing crack prediction factors at each scale through maximum value fusion are as follows: Multi-scale gradient magnitude calculation: Crack edges of different widths are captured by Sobel / Scharr operators of different sizes; Multi-scale regional statistics: Quickly calculate the average gray level of different neighborhood windows using integral images. and gray variance Adaptable to differences in surface materials; Crack predictor calculation and fusion: Calculating crack predictors at each scale And perform maximum value fusion; Single-scale crack predictor: For each scale, calculate: ,in, This represents the number of pixels in the grayscale image that have the same grayscale value as the i-th pixel. Multi-scale fusion: The maximum value of the predictor at each scale is taken as the final crack tendency feature. .

4. The defect detection method based on image processing according to claim 1, characterized in that, The specific steps for calculating gradient differences in crack severity assessment and adaptive threshold adjustment are as follows: Step 1: Calculate the gradient value G(x,y) of pixel (x,y); Step 2: Calculate the gradient values ​​of all pixels within its neighborhood window. ,in, ; Step 3: Calculate the variance of the gradient difference, expressed by the formula: ,in, Let N be the mean of the gradient difference, and N be the number of neighboring pixels.

5. The defect detection method based on image processing according to claim 4, characterized in that, In crack severity assessment and adaptive threshold adjustment, the specific steps for obtaining the adaptive threshold by adjusting the initial threshold using an exponential function are as follows: Comprehensive crack severity calculation: combining gradient differences and crack tendency characteristics The degree of cracking is quantified by normalized product, and expressed as: The normalization operation linearly maps the result to the [0,1] interval: ; Initial threshold setting: Set the initial threshold ; Adaptive threshold adjustment: The threshold is dynamically adjusted using an exponential function to target high-crack-risk areas. The threshold increases, and the threshold decreases in low-risk areas, which is represented as... ,in, This is the adjustment coefficient.

6. The defect detection method based on image processing according to claim 1, characterized in that, The specific steps for negatively adjusting the economic contribution value by introducing ecological correction coefficients and implicit value correction coefficients in the location crack region are as follows: Seed point selection: After calculating the comprehensive crack severity of all pixels and sorting them in descending order, select the pixels corresponding to the top K maximum values ​​as seed points; Growth rules are defined, including significance values ​​less than an adaptive threshold, gradient direction consistency, and texture feature similarity. Region growing: This is achieved by initializing a seed point set S and treating each seed point as an independent region. Iteratively check the 8-neighborhood of its neighboring pixel p. If all the above conditions are met, then pixel p is merged into the region. And update the region average gradient direction and average LBP characteristics The algorithm terminates when all neighboring pixels no longer meet the growth conditions.

7. The defect detection method based on image processing according to claim 6, characterized in that, The defined growth rules include: Significance value less than adaptive threshold: ,in, The degree of cracking at pixel p. Set its adaptive threshold; Gradient direction consistency: Calculate the gradient direction of pixel p. , represented as Calculate the average gradient direction of the current region R. , represented as Where N is the number of pixels in region R, and the angle between the gradient direction of pixel p and the average gradient direction of the region is less than a threshold. , represented as ; Texture feature similarity: Calculate the LBP texture feature LBP(p) of pixel p, and calculate the average LBP feature of the current region R. , represented as Determine whether the Hamming distance between the LBP feature of pixel p and the average LBP feature of the region is less than a threshold. , represented as .

8. The defect detection method based on image processing according to claim 1, characterized in that, In post-processing and defect output, the specific steps for filtering out tiny noise regions with fewer than a threshold pixels and retaining real cracks through connected component analysis are as follows: Step 1: Mark the connected components of the crack region mask output by the region growing algorithm, and assign a unique label to each independent crack region using the Flood Fill algorithm or the two-pass scanning method. Step 2: Count the number of pixels in each connected component; Step 3: Set a pixel threshold to filter connected components that have fewer than the pixel threshold.

9. The defect detection method based on image processing according to claim 8, characterized in that, In post-processing and defect output, the specific steps for optimizing the shape of the crack region through morphological opening and closing operations are as follows: Step 1: Define morphological structural element B; Step 2: Perform an opening operation to remove burrs from the crack edges, represented as... ,in, For corrosion operation, For expansion operation; Step 3: Perform a closing operation to fill the voids inside the crack: .

10. The defect detection method based on image processing according to claim 9, characterized in that, The specific steps for outputting defect detection results with marked crack locations and contours in post-processing and defect output; Step 1: Overlay the morphologically processed crack region mask onto the original grayscale image; Step 2: Use the boundary tracking algorithm to extract the crack contour and draw the bounding box or contour line; Step 3: Generate a test report.