Image Recognition-Based Defect Detection Method and System for Metal Products
By employing techniques such as reflective perturbation elimination and benchmark texture models, the problems of light interference and low boundary processing accuracy in the detection of surface defects in metal products have been solved, achieving high-precision defect detection and classification and reducing the false detection rate.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-02-05
- Publication Date
- 2026-04-17
AI Technical Summary
Existing technologies for detecting surface defects in metal products suffer from problems such as misjudgment due to light interference, low accuracy of boundary treatment, and insufficient refinement of defect classification, making it difficult to meet the needs of high-precision production.
By employing steps such as reflection perturbation resolution, baseline texture model generation, defect texture gradient separation, boundary pixel reconstruction, local variance enhancement, and neighborhood correlation analysis, combined with grayscale inverse stretching and abnormal pixel group feature clustering, the precise location and classification of defective regions are achieved.
It significantly improves the accuracy and precision of surface defect detection in metal products, reduces the false detection rate, and meets the real-time and efficient detection needs of high-precision production lines.
Smart Images

Figure CN121686026B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image analysis technology, and in particular to a method and system for detecting defects in metal products based on image recognition. Background Technology
[0002] In the manufacturing process of metal products, especially high-gloss metal products such as stainless steel and aluminum alloys, surface defect detection is one of the core steps in ensuring product quality. Current technologies primarily rely on machine vision for surface defect detection. The conventional process involves acquiring images of the product surface using an industrial camera, followed by image filtering, threshold segmentation, and feature extraction algorithms to identify defect areas. For defect classification, existing technologies often employ pre-defined defect feature templates, matching the features of the area to be detected against the templates to classify the defect type.
[0003] However, existing technologies are insufficient in handling complex lighting interference such as surface reflection and overexposure on metal surfaces, easily leading to the masking or misjudgment of true defects. Furthermore, the boundary processing accuracy of defect areas is low, resulting in discrepancies and missing contours. Additionally, the current level of detail and precision in defect classification is insufficient to meet the demands of high-precision production. Therefore, improving the accuracy and precision of surface defect detection in metal products to reduce false detection rates is a pressing technical problem that needs to be addressed. Summary of the Invention
[0004] This application provides a method and system for detecting defects in metal products based on image recognition.
[0005] This application provides, in one aspect, an image recognition-based method for detecting defects in metal products, applied to a metal product defect detection system. The method includes:
[0006] The surface image of the metal product to be inspected is subjected to reflective perturbation removal processing to obtain a reflective removal image;
[0007] Obtain the surface reference texture features of the defect-free metal product, and generate a reference texture model based on the texture distribution pattern, grayscale mean, and texture continuity of the surface reference texture features.
[0008] When performing defect texture gradient separation on the reflective decontamination image based on the benchmark texture model, abnormal regions that differ from the benchmark texture are located by comparing texture features, the texture gradient changes of the abnormal regions are calculated and a defect texture gradient map is generated, and suspected defect texture regions are segmented from the defect texture gradient map.
[0009] The supplementation rules for boundary pixels in the suspected defective texture region are determined according to the preset boundary pixel reconstruction strategy. The missing boundary pixels are filled and the discrete boundary pixels are corrected according to the supplementation rules to obtain the defective texture reconstruction region.
[0010] The texture grayscale difference of the defect texture reconstruction region is amplified by local variance enhancement processing to generate a defect texture enhancement region including defect grayscale abrupt change features. Neighborhood correlation analysis is performed on the defect texture enhancement region, and pseudo-defect pixels are removed based on the neighborhood correlation analysis results to obtain the target defect texture region.
[0011] The overexposed area in the target defect texture region is located and grayscale inverse stretching is performed to obtain the preprocessed defect region. The abnormal pixel group feature clustering of the preprocessed defect region is performed to obtain the clustering result. The surface defect detection result of the metal product to be detected is output according to the clustering result.
[0012] One embodiment of this application provides a defect detection system for metal products, including:
[0013] A processor; a storage device having a computer program stored thereon; a network interface for providing network communication functions; when the computer program is executed by the processor, the processor enables the processor to implement any of the image recognition-based metal product defect detection methods described above.
[0014] One embodiment of this application provides a readable storage medium storing a program or instructions that, when executed by a processor, implement the steps of the image recognition-based metal product defect detection method.
[0015] Therefore, the embodiments of this application have achieved a breakthrough in the precision and intelligence of surface defect detection of metal products from a global perspective: First, by eliminating reflective disturbances and adapting the reference texture model to depth, the interference of mirror reflection on texture feature extraction of metal surface is eliminated from the root, ensuring that the basic data for defect detection fits the real surface state of the product; Second, the linkage processing of defect texture gradient separation and boundary pixel reconstruction not only achieves precise positioning of the defect area, but also makes up for the recognition error caused by boundary discreteness and missingness in traditional defect detection through pixel-level reconstruction, which greatly improves the integrity and accuracy of the defect area contour; Furthermore, the combined application of local variance enhancement and neighborhood correlation analysis amplifies the gray-scale abrupt change features of defects while effectively eliminating false defects caused by texture fluctuations and uneven lighting through correlation verification of neighboring pixels, significantly reducing the false detection rate. Finally, the collaborative processing of gray-scale inverse stretching in overexposed areas and clustering of abnormal pixel groups solves the problem of feature loss caused by overexposure in defect areas, and achieves accurate classification and quantification of different types of defects through clustering. The final output detection results have accuracy, completeness and classification refinement, which can meet the real-time and efficient defect detection needs of high-precision metal product production lines. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in the embodiments or related technologies of this application, the accompanying drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 This is a flowchart illustrating a method for detecting defects in metal products based on image recognition, provided in an embodiment of this application.
[0018] Figure 2 This is a schematic diagram of the basic structure of a metal product defect detection system provided in an embodiment of this application.
[0019] Figure 3 This is a functional block diagram of a metal product defect detection device provided in an embodiment of this application. Detailed Implementation
[0020] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0021] Please see Figure 1 , Figure 1 This is a flowchart of a metal product defect detection method based on image recognition provided in an embodiment of this application. The method can be executed by a metal product defect detection system or jointly executed by a metal product defect detection system and a server. The method may include steps 110-160.
[0022] In image processing and machine vision applications for surface defect detection of metal products, core data parameters come from diverse sources, including pixel coordinates, grayscale values, and texture statistics. These parameters naturally possess different dimensions and numerical scales. For example, grayscale values are dimensionless ranges from 0 to 255, spatial distances are measured in pixels, and region areas involve the number of pixels and physical dimensions. When performing joint calculations, comparisons, or fusions on these parameters, directly using the original values can easily lead to dimensional mismatches and scale inconsistencies, resulting in calculation results lacking physical meaning and comparability, thus affecting the accuracy of subsequent judgments. When implementing relevant technical solutions, those skilled in the art can clearly recognize the essential differences in parameters and will eliminate the influence of dimensions and scales through conventional data preprocessing steps such as adaptive normalization or standardization, ensuring the consistency of mathematical operations and the coherence of physical meaning. This processing is a fundamental and conventional technical means necessary to achieve the purpose of the solution.
[0023] For the multi-feature fusion and calculation steps in the embodiments of this application, those skilled in the art will implement targeted normalization processing based on standard data science practices. For example, when generating pixel feature vectors containing grayscale values, texture gradient directions, etc., and performing cluster analysis, Z-score standardization or min-max normalization will be introduced before clustering iteration to map feature parameters with different dimensions and value ranges to a unified dimensionless interval, eliminating scale differences to ensure the mathematical basis and comparability of subsequent calculations. In steps such as texture feature parameter comparison and gradient intensity interval division, parameter scaling and normalization will be combined with feature statistical distribution or prior knowledge to ensure that preset thresholds can be effectively operated under the same standard. When cross-dimensional parameter association or fusion is involved, dimension unification will be achieved by introducing scaling coefficients, unit conversion factors, etc., such as using pixel resolution to convert pixel counts into physical area; when constructing association models or multi-source feature fusion, the input features will be standardized or dimensionless first. All of the above operations are based on common knowledge in the field and are standard preliminary steps to ensure the robustness of the algorithm.
[0024] Adaptive normalization of parameters with different physical meanings and dimensions is a fundamental operation that can be directly implemented by those skilled in the art based on long-term accumulation and existing technical standards. In the fields of computer vision and industrial inspection, feature standardization and data normalization are standard preprocessing modules, widely used in various image analysis, machine learning frameworks, and commercial software libraries. Related technical literature and textbooks also elaborate on their principles and implementation methods, and they are generally considered necessary steps to avoid feature-dominated models, ensure algorithm convergence, and improve accuracy. Therefore, when the embodiments of this application mention multi-feature calculation, comparison, or fusion steps, those skilled in the art will naturally embed the normalization module based on known techniques, without needing further elaboration. Therefore, for the potential scale mismatch problem involving multi-dimensional parameters in the embodiments of this application, those skilled in the art can properly solve it through conventional preprocessing techniques, ensuring the technical feasibility and effectiveness of the entire defect detection process.
[0025] Step 110: Perform reflective perturbation removal processing on the surface image of the metal product to be inspected to obtain a reflective removal image.
[0026] In this embodiment of the application, the metal product to be inspected is a stainless steel stamping part. The metal product defect detection system first acquires the surface image of the stainless steel stamping part captured by an industrial line scan camera. The input data is a three-dimensional array stored in an uncompressed bitmap format. The first two dimensions of the array correspond to the width and height pixel coordinates of the image, and the third dimension stores the grayscale values of the RGB three channels, with a value range of 0 to 255. The metal product defect detection system employs a multi-scale Retinex algorithm combined with adaptive threshold filtering to eliminate reflective disturbances. First, the surface image is decomposed into multiple brightness and reflection components at different scales. The logarithmic transformation result of each brightness component is calculated, and the multi-scale logarithmic transformation results are then weighted and concatenated to obtain the integrated brightness component. Next, the logarithmic form of the original image is subtracted from the integrated brightness component to obtain the preliminary reflection component. Then, an adaptive grayscale threshold is set, determined by the mean and standard deviation of the grayscale values in the local image region. Pixels in the preliminary reflection component with grayscale values above the threshold are compressed, while pixels with grayscale values below the threshold retain their original grayscale, filtering out high-brightness disturbances caused by specular reflection. Finally, the processed reflection component is exponentially transformed back to a linear grayscale space, resulting in a reflective-reduced image. This output data is a three-dimensional grayscale array with the same dimensions as the input image, with the third dimension storing the RGB three-channel grayscale values after reflective reduction. The overall grayscale distribution more closely matches the actual surface texture of the stainless steel stamping parts.
[0027] Step 120: Obtain the surface reference texture features of the defect-free metal product, and generate a reference texture model based on the texture distribution pattern, grayscale mean, and texture continuity of the surface reference texture features.
[0028] In this embodiment, the metal product defect detection system first retrieves 100 sets of surface images of stainless steel stamping parts of the same model from a preset defect-free sample database as a reference sample set. The input data consists of 100 three-dimensional grayscale arrays with the same input format as in step 110. The metal product defect detection system uses Histogram of Oriented Gradients (HOG) combined with Local Binary Pattern (LBP) to extract the surface texture features of each reference sample. The RGB image of each reference sample is converted into a single-channel grayscale image, and the grayscale image is divided into non-overlapping 8×8 pixel units. The gradient magnitudes in eight directions are calculated within each unit, and the proportion of the gradient magnitude in each direction to the total gradient magnitude within the unit is calculated to obtain the HOG feature vector. Simultaneously, the 3×3 neighboring pixels of each pixel are binary encoded, and the frequency of occurrence of the encoded values is calculated to obtain the LBP feature vector. The HOG feature vector and LBP feature vector of each reference sample are weighted and concatenated to obtain a single set of reference texture features.
[0029] Next, statistical analysis was performed on 100 sets of baseline texture features. The probability density function of texture distribution patterns, the mean gray value of all baseline samples, and the correlation coefficient of texture continuity were calculated. Using the above statistical results as constraints, a baseline texture model based on a Gaussian mixture model was constructed. The input of this model is the image pixel coordinates, and the output is the baseline texture feature vector at the corresponding coordinate position, the expected gray value, and the texture continuity parameter. The model contains 5 Gaussian distribution components, each corresponding to a typical baseline texture pattern. The model parameters were iteratively optimized using the expectation-maximization algorithm until the change in the model likelihood function between two adjacent iterations was less than a preset threshold. The output baseline texture model is stored in the form of a serialized file, containing model structure parameters, the weights of each Gaussian component, and feature distribution parameters.
[0030] Step 130: When performing defect texture gradient separation on the reflective decontamination image based on the reference texture model, the abnormal region that differs from the reference texture is located by comparing texture features, the texture gradient change of the abnormal region is calculated and a defect texture gradient map is generated, and the suspected defect texture region is segmented from the defect texture gradient map.
[0031] In this embodiment of the application, the metal product defect detection system inputs the reflective de-flashing image output in step 110 into the reference texture model generated in step 120, locates abnormal areas by texture feature comparison, and further processes to obtain suspected defect texture areas.
[0032] Step 131: Divide the reflected light resolution image into multiple sub-texture regions according to preset texture units, and extract the texture distribution features, grayscale distribution features and texture continuity features of each sub-texture region to obtain a sub-texture feature set.
[0033] The metal product defect detection system first divides the reflective ablation image into a grid of 16×16 pixel preset texture units, with each sub-texture region corresponding to an independent grid unit. The input data is a three-dimensional grayscale array of the reflective ablation image. For each sub-texture region, when extracting texture distribution features, the system uses a gray-level co-occurrence matrix to calculate the contrast, correlation, entropy, and homogeneity parameters of the sub-texture region in four directions: 0°, 45°, 90°, and 135°. When extracting grayscale distribution features, the system calculates the grayscale mean, standard deviation, skewness, and kurtosis of the sub-texture region. When extracting texture continuity features, the system counts the proportion of pixel pairs within the sub-texture region whose grayscale difference is less than a preset value. The above three types of feature parameters for each sub-texture region are weighted and concatenated to obtain a sub-texture feature vector of fixed length. The feature vectors of all sub-texture regions are arranged in spatial order according to the grid units to form a sub-texture feature set. The output data is a two-dimensional array, with each row corresponding to the feature vector of one sub-texture region.
[0034] Step 132: Call the reference texture model, extract the reference sub-texture features corresponding to each sub-texture region from the reference texture model, and establish a one-to-one correspondence between the sub-texture regions and the reference sub-texture features.
[0035] The metal product defect detection system calls the reference texture model generated in step 120, inputting the center pixel coordinates of each sub-texture region into the model. The model matches the corresponding Gaussian components based on these coordinates and outputs the reference texture feature vector corresponding to that coordinate position. The input data consists of a list of center pixel coordinates of the sub-texture regions and the reference texture model file. The output data is a two-dimensional array with the same dimensions as the sub-texture feature set, with each row corresponding to the reference sub-texture feature vector of one sub-texture region. The metal product defect detection system establishes a one-to-one correspondence between each feature vector in the sub-texture feature set and the reference sub-texture feature vector according to the grid arrangement order of the sub-texture regions, forming a feature pair set.
[0036] Step 133: Compare the sub-texture features of each sub-texture region with the corresponding reference sub-texture features dimension by dimension, filter out the sub-texture regions where the sub-texture features differ from the reference sub-texture features, and fuse adjacent sub-texture regions to obtain the abnormal region.
[0037] The metal product defect detection system performs dimension-by-dimensional difference calculations on each pair of feature vectors in the feature pair set. It calculates the absolute difference for each dimension's feature parameter and then sums the weighted absolute differences across all dimensions to obtain the total difference between the sub-texture region and the baseline texture. The weighting coefficients are pre-set based on the influence of each feature dimension on the defect. If the total difference of a sub-texture region exceeds a preset difference threshold, it is marked as a differential sub-texture region. The input data consists of the feature pair set and the preset difference threshold; the output data is a list of coordinates of the marked differential sub-texture regions. The system employs a region growing algorithm to fuse differential sub-texture regions. Starting with any differential sub-texture region as a seed, it incorporates all differential sub-texture regions within its 8-neighborhood into the same region. This process is repeated until all adjacent differential sub-texture regions are fused, resulting in multiple independent abnormal regions. The output data is a set of pixel coordinates corresponding to each abnormal region, with each set containing the pixel range of all sub-texture regions within that region.
[0038] Step 134: Perform texture direction analysis on the abnormal region to determine the dominant direction of the texture within the abnormal region. Calculate the variation range of texture grayscale along the dominant direction and perpendicular to the dominant direction to obtain texture gradient change data.
[0039] The metal product defect detection system first calculates the texture direction of each pixel in each abnormal region using the structure tensor algorithm. It calculates the first-order partial derivatives of the x and y directions for the 3×3 neighborhood of the pixel to construct a structure tensor matrix. The texture direction of the pixel is obtained by solving for the eigenvalues and eigenvectors of the matrix. Next, it statistically analyzes the texture directions of all pixels within the abnormal region, dividing the directions into eight equal intervals. The direction corresponding to the interval with the highest frequency is selected as the dominant direction of the abnormal region. The input data consists of the set of pixel coordinates and the corresponding grayscale value array of the abnormal region, and the output data is the dominant direction parameter for each abnormal region. Then, it calculates the grayscale variation amplitude along the dominant direction and perpendicular to the dominant direction. For each pixel line along the dominant direction, it calculates the absolute value of the grayscale difference between adjacent pixels and calculates the average variation amplitude for that direction by averaging the absolute values of the grayscale differences for each pixel line. Similarly, it calculates the average variation amplitude perpendicular to the dominant direction. The average variation amplitude, standard deviation, and extreme values of the two directions are weighted and concatenated to obtain the texture gradient variation data for each abnormal region. The output data is the gradient feature vector corresponding to each abnormal region, containing direction, amplitude, and dispersion parameters.
[0040] Step 135: Using the spatial coordinates of the abnormal region as a reference, map the texture gradient change data to the corresponding coordinate position to generate a defect texture gradient map containing the gradient change intensity and gradient direction.
[0041] The metal product defect detection system maps the texture gradient change data of each abnormal region to a blank image matrix of the same size as the original reflection-resolved image, according to the corresponding pixel coordinates. For each pixel, if the pixel belongs to the abnormal region, the gradient change intensity and direction of the region are assigned to the pixel. The gradient change intensity is stored in grayscale value, and the gradient direction is stored in numerical value of an additional channel. If the pixel does not belong to the abnormal region, the gradient change intensity is set to 0, and the direction is set to a meaningless value. The input data are the set of pixel coordinates of the abnormal region, texture gradient change data, and original image size parameters. The output data is a four-channel defect texture gradient map. The first three dimensions are RGB grayscale channels, storing the visualization results of the gradient change intensity. The fourth dimension is the encoded value of the gradient direction, ranging from 0 to 7, corresponding to 8 direction intervals.
[0042] Step 136: Based on the distribution characteristics of gradient change intensity in the defect texture gradient map, divide the gradient intensity interval, filter out the target area where the gradient change intensity is within the preset interval, and extract the edge contour of the target area to obtain the suspected defect texture area.
[0043] The metal product defect detection system statistically analyzes the gradient intensity of the defect texture gradient map and automatically divides the gradient intensity into three intervals: low, medium, and high. The preset target interval is the medium-high intensity interval. The system selects pixels with gradient intensity within the medium-high intensity interval to form the initial target region. The input data is the gradient intensity channel data of the defect texture gradient map, and the output data is the set of pixel coordinates of the initial target region. Next, the Canny edge detection algorithm is used to extract the edge contours of the initial target region. First, the grayscale image of the initial target region is Gaussian smoothed. Then, the gradient magnitude and direction of the image are calculated. False edges in the edge response are eliminated by non-maximum suppression. Finally, a double thresholding method is used to determine strong and weak edges, and the part of the weak edge that is connected to the strong edge is retained as the final edge. This yields the set of edge contour coordinates of the suspected defect texture region, and the output data is a list of edge contour pixel coordinates for each suspected defect texture region.
[0044] Step 140: Determine the supplementation rules for boundary pixels in the suspected defect texture region according to the preset boundary pixel reconstruction strategy, fill in the missing boundary pixels and correct the discrete boundary pixels according to the supplementation rules, and obtain the defect texture reconstruction region.
[0045] In this embodiment of the application, the metal product defect detection system corrects the edge discontinuity problem of the suspected defect texture area obtained in step 136 by reconstructing the boundary pixels.
[0046] Step 141: Extract the set of edge pixels of the suspected defective texture region, sort the pixels in the edge pixel set by coordinates, and obtain the edge pixel sequence.
[0047] The metal product defect detection system employs a chain-encoding method to extract the set of edge pixels in suspected defective texture regions. Starting from the initial pixel of the edge, it traverses all edge pixels clockwise, recording the (x, y) coordinates of each pixel. The input data is a list of edge contour pixel coordinates for the suspected defective texture region, and the output data is a set of edge pixels, which is a list containing multiple (x, y) coordinate pairs. Next, the system sorts the coordinates in the edge pixel set in a clockwise traversal order, arranging the coordinate pairs according to the traversal order to obtain the edge pixel sequence. The output data is an ordered list of edge pixel coordinates.
[0048] Step 142: Calculate the coordinate difference between adjacent pixels in the edge pixel sequence, determine the continuity of boundary pixels based on the coordinate difference, and identify discrete pixels whose coordinate difference exceeds the preset range and missing pixel regions where there is a coordinate discontinuity between adjacent pixels.
[0049] The metal product defect detection system calculates the sum of the absolute values of the x-coordinate difference and the y-coordinate difference for each pair of adjacent pixels in the edge pixel sequence. If the sum is greater than a preset continuous threshold, the next pixel is determined to be a discrete pixel. If the coordinate difference between adjacent pixels shows a gap of at least one pixel, the location is determined to be a missing pixel region. The input data is the edge pixel sequence and the preset continuous threshold, and the output data is a list of coordinates of discrete pixels and the start and end coordinate pairs of the missing pixel region.
[0050] Step 143: For the missing pixel region, based on the continuous edge pixels on both sides of the missing pixel region, identify the texture grayscale change trend of the edge pixels, and combine the texture distribution pattern of the corresponding position in the benchmark texture model to determine the grayscale supplementation rule for the missing pixels.
[0051] The metal product defect detection system extracts the grayscale values of three consecutive edge pixels on each side of each missing pixel region. A linear fitting algorithm is then used to fit the trend of these grayscale values, obtaining the slope and intercept of the grayscale change. Simultaneously, the center coordinates of the missing pixel region are input into a reference texture model to obtain the corresponding grayscale value and texture distribution direction of the reference texture. Combining the grayscale change trend and reference texture information, the system determines the grayscale supplementation rule for the missing pixels: the grayscale value of the missing pixel is calculated from the trend of the linear fitting, while fine-tuning is performed with reference to the grayscale distribution of the reference texture. The fine-tuning range is determined by the difference between the grayscale values of the reference texture and the fitted trend. If the difference is large, the reference texture takes precedence; if the difference is small, the fitted trend takes precedence. The input data consists of the coordinates of the edge pixels on both sides of the missing pixel region and the reference texture model. The output data includes grayscale supplementation rule parameters for each missing pixel region, including the fitting slope, intercept, and fine-tuning weights.
[0052] Step 144: For discrete pixels, calculate the grayscale similarity and spatial distance between the discrete pixel and the surrounding pixels in the edge pixel sequence. Based on the grayscale similarity and spatial distance, determine the correction direction and correction magnitude of the discrete pixel to obtain the discrete pixel correction rule.
[0053] The metal product defect detection system selects pixels belonging to the edge pixel sequence within its 8-neighborhood as reference pixels for each discrete pixel. It calculates the absolute difference in grayscale between the discrete pixel and each reference pixel, and uses the reciprocal of this difference as the grayscale similarity. Simultaneously, it calculates the Euclidean distance between the discrete pixel and each reference pixel, and uses the reciprocal of this distance as the spatial distance weight. The system then performs a weighted sum of the grayscale similarity and spatial distance weights of all reference pixels to obtain a comprehensive adjustment coefficient for the discrete pixel. Based on this coefficient, the correction direction of the discrete pixel is determined to be towards the reference pixel with the highest comprehensive weight. The correction magnitude is determined by the product of the comprehensive adjustment coefficient and a preset adjustment step size. The input data includes the coordinates of the discrete pixel and the edge pixel sequence, and the output data includes the correction direction vector and correction magnitude parameters for each discrete pixel.
[0054] Step 145: Fill the pixel values of the missing pixel region according to the grayscale filling rules of the missing pixels, and adjust the coordinates and grayscale values of the discrete pixels according to the discrete pixel correction rules to obtain the initial reconstruction boundary.
[0055] The metal product defect detection system calculates the gray value of each missing pixel in each missing pixel region according to the gray value supplementation rule, and fills the pixel coordinates of the missing position with the calculated gray value. For each discrete pixel, its (x, y) coordinates are adjusted according to the correction direction vector and correction magnitude, and its gray value is adjusted to the gray value difference with the reference pixel within the allowable range. The input data are the coordinates of the missing pixel region, the gray value supplementation rule, the coordinates of discrete pixels and the discrete pixel correction rule. The output data is the corrected edge pixel sequence, i.e. the initial reconstruction boundary.
[0056] Step 146: Compare the texture features of the initial reconstructed boundary with the texture features of the reference texture model, and adjust the grayscale values of the boundary pixels according to the comparison results to complete the boundary pixel reconstruction and obtain the defect texture reconstruction area.
[0057] The metal product defect detection system extracts texture features from the initial reconstructed boundary, including grayscale mean, texture direction, and grayscale co-occurrence matrix parameters. These features are then compared dimension-by-dimensionally with the corresponding features in the baseline texture model to calculate the feature difference. If the feature difference of a boundary pixel exceeds a preset comparison threshold, the grayscale value of that pixel is adjusted towards the grayscale value of the baseline texture. The adjustment magnitude is determined by the product of the feature difference and a preset adjustment coefficient. This adjustment process is repeated until the feature difference of all boundary pixels is less than the preset comparison threshold. The system then performs texture fusion between the adjusted initial reconstructed boundary and the internal pixels of the suspected defect texture region to obtain the defect texture reconstruction region. The output data is a set of pixel coordinates and corresponding grayscale value arrays for the defect texture reconstruction region containing the complete boundary.
[0058] Step 150: Amplify the texture grayscale difference of the defect texture reconstruction region through local variance enhancement processing to generate a defect texture enhancement region including defect grayscale abrupt change features. Perform neighborhood correlation analysis on the defect texture enhancement region and remove pseudo-defect pixels based on the neighborhood correlation analysis results to obtain the target defect texture region.
[0059] In this embodiment of the application, the metal product defect detection system enhances and removes false defects from the defect texture reconstruction area obtained in step 146 to obtain a more accurate target defect area.
[0060] Step 151: Divide the defect texture reconstruction area into multiple local texture blocks, calculate the grayscale variance value of each local texture block, and obtain the local variance distribution matrix.
[0061] The metal product defect detection system divides the defect texture reconstruction area into non-overlapping local texture blocks of 8×8 pixels. For each local texture block, the variance of the gray values of all pixels in the block is calculated. The input data is the gray value array of the defect texture reconstruction area, and the output data is the local variance distribution matrix. Each element of the matrix corresponds to the gray variance value of a local texture block. The size of the matrix is determined by the width and height of the defect texture reconstruction area and the size of the local texture blocks.
[0062] Step 152: Based on the local variance distribution matrix, the gray value of each local texture block is adjusted by variance enhancement to amplify the gray value difference in the first gray value variance region and suppress the gray value fluctuation in the second gray value variance region to obtain the initial enhanced texture region.
[0063] The metal product defect detection system sorts the variance values in the local variance distribution matrix by size, dividing it into a first gray-level variance region and a second gray-level variance region. The first gray-level variance region consists of the top 30% of local texture blocks with larger variance values, corresponding to areas with drastic texture changes. The second gray-level variance region consists of the bottom 70% of local texture blocks with smaller variance values, corresponding to areas with smoother textures. For each local texture block in the first gray-level variance region, the system uses a gray-level stretching algorithm to expand the gray-level value range from the original 0 to 255 to a larger range of 0 to 200 to 0 to 255, amplifying the gray-level differences. For each local texture block in the second gray-level variance region, a Gaussian filter is used to smooth gray-level fluctuations, reducing the dispersion of gray-level values. The input data includes the local variance distribution matrix, the gray-level value array of the defect texture reconstruction region, and the division threshold. The output data is the gray-level value array of the initial enhanced texture region.
[0064] Step 153: Extract gray-level abrupt change points in the initial enhanced texture region, identify the gray-level change amplitude and spatial distribution density of the gray-level abrupt change points, mark the regions where the gray-level change amplitude exceeds the preset threshold and the spatial distribution density meets the preset conditions as defective gray-level abrupt change regions, and integrate all defective gray-level abrupt change regions to obtain the defective texture enhancement region.
[0065] The metal product defect detection system uses the Sobel operator to calculate the grayscale gradient magnitude of each pixel in the initial enhanced texture region. If the grayscale gradient magnitude of a pixel is greater than a preset abrupt change threshold, it is marked as a grayscale abrupt change point. The input data is the grayscale value array of the initial enhanced texture region and the preset abrupt change threshold, and the output data is a list of coordinates of the grayscale abrupt change points. Next, the system performs spatial density statistics on the grayscale abrupt change points, using a 3×3 sliding window to count the number of grayscale abrupt change points within each window. If the number of abrupt change points within a window is greater than a preset density threshold, the window region is marked as a candidate abrupt change region. Adjacent candidate abrupt change regions are merged to obtain the defective grayscale abrupt change region. The input data is the list of coordinates of the grayscale abrupt change points and the preset density threshold, and the output data is a set of pixel coordinates for each defective grayscale abrupt change region. Finally, the system overlays all defective grayscale abrupt change regions with the initial enhanced texture region to obtain the defective texture enhanced region. The output data is a grayscale value array containing the defective grayscale abrupt change features, where the grayscale values of the abrupt change regions retain the enhanced state, and the grayscale values of the non-abrupt change regions retain the initial enhanced state.
[0066] Step 154: Using each pixel in the defect texture enhancement region as the center, select a preset range of neighboring pixels to form a neighboring pixel set, and calculate the grayscale correlation coefficient between the center pixel and each pixel in the neighboring pixel set.
[0067] The metal product defect detection system uses each pixel in the defect texture enhancement region as the center and selects a 5×5 pixel range of neighboring pixels to form a neighboring pixel set. The input data is an array of grayscale values of the defect texture enhancement region, and the output data is a list of coordinates and a set of grayscale values of the neighboring pixels corresponding to each center pixel. For each center pixel and each pixel in the neighboring pixel set, the system calculates the covariance of its grayscale value and divides it by the product of the standard deviations of their grayscale values to obtain a grayscale correlation coefficient. This coefficient reflects the consistency of grayscale changes between the center pixel and its neighboring pixels. The input data is the grayscale value of the center pixel and the set of grayscale values of the neighboring pixels, and the output data is multiple grayscale correlation coefficients corresponding to each center pixel.
[0068] Step 155: Statistically analyze the neighborhood correlation coefficient distribution of each center pixel and determine the correlation coefficient threshold. Mark center pixels with neighborhood correlation coefficients lower than the correlation coefficient threshold as candidate pseudo-defect pixels.
[0069] The metal product defect detection system statistically analyzes all gray-level correlation coefficients of each center pixel, calculates their mean and standard deviation, and uses the mean minus one standard deviation as the correlation coefficient threshold for that center pixel. If the correlation coefficients of most of the neighborhoods of a center pixel are lower than this threshold, it is marked as a candidate false defect pixel. The input data is the set of gray-level correlation coefficients of each center pixel, and the output data is a list of coordinates of the candidate false defect pixels.
[0070] Step 156: Perform region connectivity analysis on the candidate pseudo-defect pixels, divide the connected candidate pseudo-defect pixels into pseudo-defect regions, and eliminate pixel regions that meet the pseudo-defect features by combining the texture features of the baseline texture model to obtain the target defect texture region.
[0071] In this embodiment of the application, the metal product defect detection system eliminates false defect areas by comparing regional connectivity analysis with a reference texture.
[0072] Step 1561: Use the region growing algorithm to perform connectivity analysis on the candidate pseudo-defect pixels. Using the candidate pseudo-defect pixels as seed points, include candidate pseudo-defect pixels in the neighborhood that meet the gray-level similarity condition into the same connected region. By gradually expanding the neighborhood range of the seed point, the connected region is divided, generating multiple pseudo-defect regions.
[0073] The metal product defect detection system uses each candidate pseudo-defect pixel as an initial seed point. Employing an 8-neighborhood growth rule, it calculates the grayscale similarity between the seed point and its neighboring candidate pseudo-defect pixels. If the grayscale similarity exceeds a preset similarity threshold, the neighboring pixel is included in the same connected region. This process is repeated until no candidate pseudo-defect pixels meet the criteria within the seed point's neighborhood. Then, the next candidate pseudo-defect pixel not yet included in any connected region is selected as the new seed point, and the growth process continues until all candidate pseudo-defect pixels are assigned to their corresponding connected regions. The input data includes a list of candidate pseudo-defect pixel coordinates, a grayscale value array, and a preset similarity threshold. The output data is a set of pixel coordinates for each pseudo-defect region.
[0074] Step 1562: Extract the texture feature parameters of each pseudo-defect region, and extract the reference texture feature parameters corresponding to the spatial position of each pseudo-defect region from the reference texture model.
[0075] The metal product defect detection system extracts the grayscale mean, grayscale variance, texture direction, and contrast parameters of the grayscale co-occurrence matrix for each pseudo-defect region, obtaining a texture feature parameter vector. The input data consists of the set of pixel coordinates and grayscale value arrays of the pseudo-defect region, and the output data is the texture feature parameter vector for each pseudo-defect region. Alternatively, the system inputs the center coordinates of each pseudo-defect region to a reference texture model to obtain the corresponding reference texture feature parameter vector. The input data consists of the center coordinates of the pseudo-defect region and the reference texture model, and the output data is the reference texture feature parameter vector for each pseudo-defect region.
[0076] Step 1563: Compare the texture feature parameters of each pseudo-defect region with the corresponding reference texture feature parameters dimension by dimension, calculate the texture feature difference degree, and determine the matching degree between each pseudo-defect region and the reference texture based on the texture feature difference degree.
[0077] The metal product defect detection system calculates the absolute difference of each dimension parameter between the texture feature parameter vectors of each pair of pseudo-defect regions and the reference texture feature parameter vector. The system then performs a weighted sum of all the absolute differences to obtain the texture feature difference degree. The weighting coefficients are pre-set based on the influence of each feature dimension on the defect. The matching degree is calculated as 1 minus the ratio of the texture feature difference degree to the maximum possible difference degree. A smaller texture feature difference degree indicates a matching degree closer to 1. The input data consists of the texture feature parameter vectors of the pseudo-defect regions and the reference texture feature parameter vector. The output data includes the texture feature difference degree and matching degree value for each pseudo-defect region.
[0078] Step 1564: Based on the overall texture distribution pattern of the defect texture enhancement area, construct a texture gradient fusion model, input the texture feature parameters of each pseudo-defect area and the degree of matching with the reference texture into the texture gradient fusion model, and obtain the texture adjustment coefficient of each pseudo-defect area through the calculation of the texture gradient fusion model.
[0079] A texture gradient fusion model is constructed for the metal product defect detection system. This model adopts a deep separable convolutional neural network architecture, containing three convolutional layers and two fully connected layers. The input layer receives the texture feature parameter vector and matching degree value of the pseudo-defect region, and the output layer outputs the texture adjustment coefficients. The metal product defect detection system trains the model using a mixed dataset of defect-free samples of the same model and labeled pseudo-defect samples. The training data input consists of the texture feature parameters and matching degree of the pseudo-defect region, and the output is the manually labeled texture adjustment coefficients. The optimizer uses the Adam optimizer with an initial learning rate of 0.001, a batch size of 32, and 50 training epochs. The mean squared error is used as the loss function, and training continues until the loss function converges.
[0080] In this embodiment of the application, the metal product defect detection system concatenates the texture feature parameter vector and the matching degree value of each pseudo-defect region into an input vector, which is then input into a trained texture gradient fusion model. The model extracts features through a convolutional layer and maps the texture adjustment coefficients through a fully connected layer. The input data consists of the texture feature parameter vector and the matching degree value of the pseudo-defect region, and the output data consists of the texture adjustment coefficient of each pseudo-defect region. The coefficient ranges from 0 to 1, and the closer the coefficient is to 1, the smaller the adjustment range.
[0081] Step 1565: Adjust the grayscale value and texture gradient features of each pseudo-defect region according to the texture adjustment coefficient to optimize the pixel features corresponding to the pseudo-defect region.
[0082] The metal product defect detection system performs a weighted fusion of the grayscale value of each pseudo-defect region with the corresponding grayscale value in the reference texture model. The weights are the texture adjustment coefficient and 1 minus the texture adjustment coefficient. That is, the optimized grayscale value is equal to the original grayscale value of the pseudo-defect region multiplied by the texture adjustment coefficient plus the grayscale value of the reference texture multiplied by (1 minus the texture adjustment coefficient). At the same time, a similar weighted fusion method is used for the texture gradient features of the pseudo-defect region. The original texture gradient features are fused with the gradient features of the reference texture according to the texture adjustment coefficient. The input data are the grayscale value array of the pseudo-defect region, the texture gradient features, the grayscale value of the reference texture, the reference texture gradient features, and the texture adjustment coefficient. The output data are the optimized grayscale value array and texture gradient features of the pseudo-defect region.
[0083] Step 1566: Using the texture gradient features of adjacent regions as the transition basis, perform texture fusion processing on the optimized pseudo-defect region and the region of the defect texture enhancement region that has not been marked as a candidate pseudo-defect pixel to obtain the target defect texture region.
[0084] The metal product defect detection system extracts texture gradient features at the adjacent boundaries of the optimized pseudo-defect region and the unmarked region. A linear gradient method is used to construct a transition region, with a width of 3 pixels. The pixel grayscale values within the transition region linearly transition from the optimized grayscale values of the pseudo-defect region to the original grayscale values of the unmarked region. The texture gradient features within the transition region also undergo a linear transition. The system then concatenates the transition region with the optimized pseudo-defect region and the unmarked region to obtain the target defect texture region. The output data consists of the set of pixel coordinates and the corresponding grayscale value array of the target defect texture region.
[0085] Step 160: Locate the overexposed area in the target defect texture area and perform grayscale inverse stretching to obtain the pre-processed defect area. Perform abnormal pixel group feature clustering on the pre-processed defect area to obtain the clustering result. Output the surface defect detection result of the metal product to be detected based on the clustering result.
[0086] In this embodiment of the application, the metal product defect detection system performs overexposure correction and feature clustering on the target defect texture region obtained in step 1566, and finally outputs the defect detection result.
[0087] Step 161: Extract the grayscale value distribution of the target defect texture region, filter out overexposed pixels with grayscale values higher than the preset grayscale overexposure threshold, merge adjacent overexposed pixels to obtain the overexposed region.
[0088] The metal product defect detection system extracts the grayscale values of all pixels in the target defect texture region, statistically analyzes the grayscale value distribution, sets the 95th quantile of the grayscale value distribution as a preset grayscale overexposure threshold, and filters out pixels with grayscale values higher than this threshold as overexposed pixels. The input data is an array of grayscale values of the target defect texture region, and the output data is a list of coordinates of the overexposed pixels. The system uses 8-neighborhood connectivity analysis to merge overexposed pixel regions, incorporating adjacent overexposed pixels into the same region, generating multiple overexposed regions. The output data is a set of pixel coordinates for each overexposed region.
[0089] Step 162: Perform grayscale range analysis on the overexposed area to determine the maximum grayscale value and grayscale distribution range of the overexposed area. Based on the grayscale distribution range, set the parameters of the inverse stretching function and adjust the grayscale value of the overexposed area by mapping through the inverse stretching function. Compress the grayscale span of the first grayscale value interval and expand the grayscale difference of the second grayscale value interval to obtain the overexposed area after grayscale adjustment.
[0090] The metal product defect detection system calculates the maximum and minimum grayscale values for each overexposed area to determine the grayscale distribution range. The input data is an array of grayscale values for the overexposed area, and the output data includes the maximum, minimum, and distribution range of the grayscale values for the overexposed area. The system uses a piecewise linear inverse stretching function to divide the original grayscale range into a first grayscale interval and a second grayscale interval. The first grayscale interval is approximately one-third of the range closest to the maximum value, and the second grayscale interval is the remaining two-thirds. The inverse stretching function compresses the grayscale span of the first grayscale interval to one-third of the original span and expands the grayscale span of the second grayscale interval to 1.5 times the original span. Substituting the grayscale value of each pixel in the overexposed area into the inverse stretching function yields the adjusted grayscale value. The input data includes the array of grayscale values for the overexposed area and the parameters of the inverse stretching function; the output data is the adjusted array of grayscale values for the overexposed area.
[0091] Step 163: Fuse the overexposed area after grayscale adjustment with the unexposed area in the target defect texture area to obtain the preprocessed defect area; extract the feature parameters of each pixel in the preprocessed defect area and generate a pixel feature vector, the pixel feature vector including grayscale value, texture gradient direction and neighborhood correlation coefficient.
[0092] The metal product defect detection system replaces the original grayscale values at corresponding positions in the target defect texture region with the grayscale values of the overexposed areas after grayscale adjustment, while leaving the unexposed areas unchanged. This results in a pre-processed defect region. The input data includes an array of grayscale values for the overexposed areas after grayscale adjustment, an array of grayscale values for the target defect texture region, and a set of coordinates for the overexposed areas. The output data is the array of grayscale values for the pre-processed defect region. For each pixel in the pre-processed defect region, the system extracts its grayscale value, texture gradient direction, and neighborhood correlation coefficient. These three parameters are weighted and concatenated to obtain a pixel feature vector. The input data includes the array of grayscale values for the pre-processed defect region, the texture gradient feature array, and the set of neighborhood correlation coefficients. The output data is the pixel feature vector corresponding to each pixel.
[0093] Step 164: Use the feature clustering method to cluster all pixel feature vectors. Divide the pixels into different pixel groups according to the similarity of the pixel feature vectors. Each pixel group corresponds to a type of defect feature.
[0094] In this embodiment of the application, the metal product defect detection system uses density peak clustering method to complete the clustering of pixel feature vectors.
[0095] Step 1641: Perform feature standardization on all pixel feature vectors of the preprocessed defect region to eliminate the dimensional differences between different feature parameters and obtain standardized feature vectors.
[0096] The metal product defect detection system uses Z-score standardization for each dimension parameter of the pixel feature vector. Each parameter is subtracted from the mean of all parameters in that dimension, and then divided by the standard deviation of all parameters in that dimension to obtain the standardized parameter. The standardized parameters of the three dimensions are concatenated to form a standardized feature vector. The input data is the set of all pixel feature vectors, and the output data is the set of standardized feature vectors.
[0097] Step 1642: Calculate the Euclidean distance between the standardized feature vectors, and establish a feature similarity matrix using the Euclidean distance as a measure of feature similarity. The elements in the feature similarity matrix correspond to the Euclidean distance between any two standardized feature vectors.
[0098] The metal product defect detection system calculates the Euclidean distance for each pair of vectors in the standardized feature vector set. The Euclidean distance is the square root of the sum of the squares of the differences in the corresponding dimension parameters of the two vectors. All Euclidean distances are arranged in the order of vector pairs to obtain the feature similarity matrix. The input data is the standardized feature vector set, and the output data is a two-dimensional feature similarity matrix. The rows and columns of the matrix correspond to the indices of the pixels, and the matrix elements are the Euclidean distance between the standardized feature vectors of the corresponding two pixels.
[0099] Step 1643: Based on the feature similarity matrix, the density peak clustering method is used to determine the initial cluster centers. By calculating the local density of each standardized feature vector and the minimum Euclidean distance with other standardized feature vectors, standardized feature vectors with larger local density and minimum Euclidean distance satisfying the preset conditions are selected as the initial cluster centers. Each initial cluster center corresponds to an initial pixel group.
[0100] The metal product defect detection system calculates the local density of each standardized feature vector. Local density is the number of vectors whose Euclidean distance to that vector is less than a preset cutoff distance, which is the 10th percentile of all elements in the feature similarity matrix. Simultaneously, it calculates the minimum Euclidean distance between that vector and other vectors with a local density greater than its own, using this minimum Euclidean distance as a parameter. The system plots a two-dimensional scatter plot of local density and minimum Euclidean distance, selecting vectors with both high local density and high minimum Euclidean distance as initial cluster centers. In this embodiment, three initial cluster centers are obtained, each corresponding to an initial pixel group. The input data is the feature similarity matrix, and the output data is a list of indices for the initial cluster centers and their corresponding initial pixel groups.
[0101] Step 1644: Traverse all standardized feature vectors and assign each standardized feature vector to the initial pixel group corresponding to the nearest initial cluster center to complete the first cluster assignment; calculate the mean vector of all standardized feature vectors in each pixel group after the first cluster assignment, use the mean vector as the new cluster center, and calculate the average distance between the standardized feature vector in each pixel group and the corresponding new cluster center; adjust the cluster radius parameter according to the average distance, expand the cluster radius of pixel groups with larger average distances, and shrink the cluster radius of pixel groups with smaller average distances, and re-execute the standardized feature vector assignment step based on the adjusted cluster radius.
[0102] The metal product defect detection system iterates through all standardized feature vectors, calculates the Euclidean distance between each vector and three initial cluster centers, and assigns the vector to the initial pixel group corresponding to the nearest initial cluster center, completing the initial clustering assignment. The input data consists of the set of standardized feature vectors and the index of the initial cluster centers; the output data is the set of pixel groups after the initial clustering assignment, with each pixel group containing a corresponding list of vector indices. For each pixel group, the system calculates the mean vector of all standardized feature vectors within the group as the new cluster center, and calculates the average Euclidean distance between each vector in the group and the new cluster center as the average distance. The input data is the set of standardized feature vectors for each pixel group; the output data is the new cluster center and the average distance for each pixel group. The metal product defect detection system adjusts the cluster radius parameter based on the average distance. The cluster radius is 1.2 times the average distance. The cluster radius of pixel groups with larger average distances increases accordingly, while the cluster radius of pixel groups with smaller average distances decreases accordingly. Based on the adjusted cluster radius, the Euclidean distance between each vector and the cluster center is recalculated. If the Euclidean distance is less than the corresponding cluster radius, the vector is assigned to the pixel group corresponding to that cluster center. Otherwise, the distance to other cluster centers is recalculated. The input data consists of a set of standardized feature vectors, new cluster centers, and adjusted cluster radii. The output data is the adjusted set of pixel groups.
[0103] Step 1645: Repeat the steps of calculating new cluster centers, adjusting cluster radii, and assigning standardized feature vectors until the change in the number of new cluster centers between two consecutive iterations is less than the preset change, thus completing the clustering iteration.
[0104] The metal product defect detection system repeatedly executes step 1644. After each iteration, the average Euclidean distance between two adjacent new cluster centers is calculated. If the average value is less than a preset change amount, the iteration stops. In this embodiment, the preset change amount is 0.01. After 3 iterations, the stopping condition is met, the clustering iteration is completed, and the output data is the final set of pixel groups. Each pixel group contains a corresponding vector index list.
[0105] Step 1646: Match the feature parameter range corresponding to each pixel group after the clustering iteration with the preset defect feature parameter range to determine the defect feature type corresponding to each pixel group and complete the classification of the pixel group.
[0106] The metal product defect detection system presets three defect feature parameter ranges, corresponding to scratches, dents, and pits, respectively. The system compares the parameter ranges of each dimension of the standardized feature vector within each pixel group with the preset ranges. If the parameter range of a certain pixel group matches the preset range of a certain type of defect by more than 90%, the defect feature type corresponding to that pixel group is determined. In this embodiment, the three pixel groups correspond to scratches, dents, and pits, respectively. The input data is the final set of pixel groups and the preset defect feature parameter ranges, and the output data is the defect feature type label corresponding to each pixel group.
[0107] Step 165: Based on the spatial distribution pattern, area and feature parameter distribution of each pixel group, obtain the clustering result, distinguish different types of defects based on the clustering result, generate and output surface defect detection results containing defect type, defect location and defect range.
[0108] In this embodiment of the application, the metal product defect detection system generates the final detection result through pixel group feature analysis.
[0109] Step 1651: Extract the spatial coordinate set of each pixel group, fit the edge contour of the pixel group through the spatial coordinate set, and use a curve fitting algorithm to smooth the coordinate points of the edge contour to obtain the smoothed edge contour. By analyzing the curvature change and tangent direction change of the smoothed edge contour, determine the spatial distribution morphological characteristics of the pixel group.
[0110] The metal product defect detection system extracts the corresponding pixel coordinate set based on the vector index of each pixel group. The input data includes the final pixel group set and a pixel coordinate mapping table of the pre-processed defect area. The output data is the spatial coordinate set of each pixel group. The system then uses the least squares method to fit the edge contour of the spatial coordinate set, obtaining an initial edge contour curve. The input data is the spatial coordinate set, and the output data is the parameters of the initial edge contour curve. Next, the system uses Gaussian filtering to smooth the coordinate points of the initial edge contour. The smoothing window size is 5×5, resulting in a smoothed edge contour. The input data is the coordinate points of the initial edge contour, and the output data is a list of smoothed edge contour coordinates. Finally, the system calculates the curvature and tangent direction of each point on the smoothed edge contour, statistically analyzing the frequency of curvature changes and the amplitude of tangent direction changes to determine the spatial distribution morphological characteristics of the pixel group. For example, scratches correspond to linear shapes, pits to circular shapes, and pockmarks to dotted cluster shapes. The input data is the list of smoothed edge contour coordinates, and the output data is a description of the spatial distribution morphological characteristics of each pixel group.
[0111] Step 1652: Count the number of pixels in each pixel group, and combine it with the pixel resolution of the surface image of the metal product to be detected to convert the number of pixels into the corresponding actual physical area to obtain the area parameter of each pixel group.
[0112] The metal product defect detection system counts the number of pixels in each pixel group. The input data is the final set of pixel groups, and the output data is the number of pixels in each pixel group. In this embodiment, the industrial line scan camera has a pixel resolution of 10 pixels per millimeter. The metal product defect detection system divides the number of pixels by 100 to obtain the actual physical area. The input data is the number of pixels and the pixel resolution parameter, and the output data is the area parameter of each pixel group, in square millimeters.
[0113] Step 1653: Perform statistical analysis on the feature parameters within each pixel group, calculate the mean, variance, and extreme values of the feature parameters, and obtain the feature parameter distribution. The feature parameters include standardized gray values, texture gradient directions, and neighborhood correlation coefficients.
[0114] The metal product defect detection system calculates the mean, variance, maximum and minimum values of grayscale values, texture gradient direction, and neighborhood correlation coefficient for all standardized feature vectors within each pixel group. The system integrates these statistical results into a feature parameter distribution. The input data is a set of standardized feature vectors for each pixel group, and the output data is a feature parameter distribution table for each pixel group.
[0115] Step 1654: Integrate the spatial distribution morphological features, regional area parameters, and feature parameter distribution of each pixel group to obtain the clustering result.
[0116] The metal product defect detection system structurally integrates the spatial distribution morphological features, regional area parameters, and feature parameter distribution tables of each pixel group to form the clustering results of each pixel group. The input data is the spatial distribution morphological features, regional area parameters, and feature parameter distribution of each pixel group, and the output data is a structured clustering result document of each pixel group.
[0117] Step 1655: Establish a defect type feature library, which stores the spatial distribution morphology standards, regional area range standards, and feature parameter distribution standards corresponding to different defect types.
[0118] The metal product defect detection system establishes a defect type feature library, storing standard features for three types of defects: scratches, dents, and pits. Scratches are characterized by a linear spatial distribution, a region area ranging from 0.1 to 5 square millimeters, and feature parameters with a large variance in grayscale values, concentrated texture gradient directions, and low neighborhood correlation coefficients. Dents are characterized by a circular or elliptical spatial distribution, a region area ranging from 0.5 to 10 square millimeters, and feature parameters with a low mean grayscale value, divergent texture gradient directions, and moderate neighborhood correlation coefficients. Pitts are characterized by a dot-like cluster spatial distribution, a region area ranging from 0.05 to 2 square millimeters, and feature parameters with a high mean grayscale value, random texture gradient directions, and high neighborhood correlation coefficients. Input data consists of manually labeled defect feature standards, and output data is a structured storage file of the defect type feature library.
[0119] Step 1656: Compare the clustering results of each pixel group with each standard in the defect type feature library dimension by dimension, determine the defect type corresponding to each pixel group based on the comparison results, and determine the defect location and defect range based on the spatial coordinate set of each pixel group.
[0120] The metal product defect detection system compares the spatial distribution morphological features of each pixel group with the morphological standards in the defect type feature library. If the morphological matching degree is greater than 90%, it proceeds to the next step. It then compares the region area parameters with the corresponding area range standards; if the parameters are within the range, it proceeds to the next step. Finally, it compares the feature parameter distribution with the corresponding feature parameter distribution standards. If the matching degree of the statistical results in each dimension is greater than 85%, the defect type corresponding to that pixel group is determined. Based on the spatial coordinate set of each pixel group, the system determines the coordinates of the upper left and lower right corners of its minimum bounding rectangle as the boundary of the defect location. Simultaneously, it calculates the area of the minimum bounding rectangle as the defect range. The input data is the clustering results of each pixel group and the defect type feature library. The output data is the defect type, defect location coordinates, and defect range parameters corresponding to each pixel group.
[0121] Step 1657: Associate the defect type, defect location, and defect range corresponding to each pixel group with the spatial coordinate system of the surface image of the metal product to be inspected to obtain the associated defect information.
[0122] The metal product defect detection system converts the defect location coordinates into physical coordinates of the surface of the metal product to be inspected. Taking the upper left corner of the stainless steel stamping part as the origin, the x-axis is along the width direction, and the y-axis is along the length direction. The conversion ratio between pixel coordinates and physical coordinates is 0.1 mm per pixel. The input data is the defect location coordinates and the pixel-to-physical coordinate conversion ratio; the output data is the physical coordinate range of the defect. The system also correlates the defect type, physical coordinate range, and defect range parameters to obtain correlated defect information. The input data is the defect type, defect location coordinates, and defect range parameters; the output data is a structured document of correlated defect information.
[0123] Step 1658: The associated defect information is structured and organized to generate surface defect detection results containing product defect overview, detailed defect features and defect spatial distribution. The surface defect detection results are then transmitted to the designated storage module and display module through a preset output interface.
[0124] The metal product defect detection system organizes the associated defect information and generates surface defect detection results. The product defect overview includes the model, production batch, total number of defects, and main defect types of the metal product to be inspected. Detailed defect features include the type, area, grayscale characteristics, and texture characteristics of each defect. The defect spatial distribution includes the physical coordinate range of the defects on the surface of the metal product and a visual image. The system transmits the surface defect detection results to the storage and display modules of the factory production management system via a pre-set TCP / IP output interface. The storage module stores the detection results in a relational database, creating records indexed by production batch and product number. The display module shows the operator the visual image of the defect spatial distribution and the defect feature information. The input data is the associated defect information, and the output data is the surface defect detection result data transmitted to the storage and display modules.
[0125] Optionally, the method further includes:
[0126] Step 210: Perform texture detail enhancement processing on the target defect texture region, extract the high-frequency texture components of the target defect texture region, and fuse the high-frequency texture components with the original texture of the target defect texture region to obtain the texture detail enhancement region; extract the defect edge feature points of the texture detail enhancement region to establish the coordinate sequence of the defect edge feature points, and smooth the coordinate sequence to obtain the smoothed defect edge coordinate sequence.
[0127] In this embodiment, the metal product defect detection system uses the Difference of Gaussian Pyramid (DGPP) algorithm to extract high-frequency texture components from the target defect texture region. The target defect texture region is decomposed into five Gaussian pyramid levels. The high-frequency texture components are obtained by subtracting the Gaussian images of adjacent levels. The input data is the grayscale array of the target defect texture region, and the output data is the grayscale array of the high-frequency texture components. The system then weights and concatenates the high-frequency texture components with the original texture grayscale array of the target defect texture region using weights of 0.3 and 0.7 to obtain a texture detail enhancement region. The input data is the grayscale array of the high-frequency texture components and the grayscale array of the target defect texture region, and the output data is the grayscale array of the texture detail enhancement region. Finally, the system uses the Harris corner detection algorithm to extract defect edge feature points from the texture detail enhancement region. It calculates the structure tensor of each pixel, determines the corner response function, and marks pixels with response function values greater than a preset corner threshold as defect edge feature points. The input data is the grayscale array of the texture detail enhancement region, and the output data is a list of coordinates of the defect edge feature points. The metal product defect detection system arranges the feature points of the defect edge in edge order to obtain a coordinate sequence. The coordinate sequence is smoothed by a cubic spline interpolation algorithm to obtain a smoothed defect edge coordinate sequence. The input data is a list of coordinates of the feature points of the defect edge, and the output data is the smoothed defect edge coordinate sequence.
[0128] Step 220: Calculate the geometric parameters of the defect based on the smoothed defect edge coordinate sequence, associate the geometric parameters with the preset defect level classification standard to determine the defect level; and associate and bind the defect level with the product information of the metal product to be inspected to obtain defect association data.
[0129] In this embodiment, the metal product defect detection system calculates the length, width, area, and aspect ratio of a smoothed defect edge coordinate sequence as geometric parameters. The input data is the smoothed defect edge coordinate sequence, and the output data is the set of geometric parameters of the defect. The system pre-defines a defect level classification standard, classifying defects into three levels: minor, moderate, and severe based on their area, length, and aspect ratio. The input data is the set of defect geometric parameters and the pre-define level classification standard, and the output data is a level label for each defect. The system also associates and binds defect levels with product information such as the model, production batch, and product number of the metal product to be inspected, obtaining defect-related data. The input data is the defect level label and product information, and the output data is a structured defect-related data document.
[0130] Step 230: Store the defect-related data in a preset defect data repository and establish a defect data index. The defect data index includes product model, production batch, defect type, and defect level.
[0131] In this embodiment, the metal product defect detection system stores defect-related data in a pre-defined distributed defect data repository. The repository uses an HBase database architecture, with product number as the row key and defect information as the column family. The metal product defect detection system establishes a defect data index, with index fields including product model, production batch, defect type, and defect level. Each index field corresponds to a secondary index. The input data is the defect-related data, and the output data is the defect data record in the repository and its corresponding secondary index.
[0132] Step 240: Based on the historical defect data in the defect data repository, analyze the defect distribution patterns corresponding to different production batches and different production processes, generate defect distribution statistics, and output the defect distribution statistics in association with the defect association data.
[0133] In this embodiment, the metal product defect detection system retrieves historical defect data from the past six months from a defect data repository, groups and statistically analyzes it by production batch and production process, and calculates the total number of defects, defect type distribution, and defect level distribution for each group. The input data is the historical defect data from the defect data repository, and the output data is the defect distribution statistics. The metal product defect detection system associates the current defect-related data with the corresponding defect distribution statistics of the production batch and production process, and outputs this data simultaneously through the output interface of the factory production management system. The input data is the defect association data and the defect distribution statistics, and the output data is the combined data of the associated defect information and statistics.
[0134] Optionally, the method further includes:
[0135] Step 310: Obtain the surface defect detection results of multiple batches of the same type of metal product to be tested and the production parameter data of each batch. Align the surface defect detection results of the multiple batches with the surface defect detection results output this time in terms of defect feature dimensions to obtain a cross-batch defect feature set with a unified dimension.
[0136] In this embodiment, the metal product defect detection system retrieves surface defect detection results and corresponding production parameter data from the past 10 production batches of the same model of stainless steel stamping parts from the factory production management system. The production parameter data includes stamping pressure, stamping speed, die temperature, and raw material hardness. The input data consists of surface defect detection results and production parameter data from multiple batches, and the output data is a set of defect data and production parameters from multiple batches. The metal product defect detection system aligns the defect features in the surface defect detection results from multiple batches with the defect feature dimensions of the current detection results, unifying the defect type classification, feature parameter statistical standards, and coordinate system to obtain a unified set of cross-batch defect features. The input data consists of defect data from multiple batches and the current defect data, and the output data is the cross-batch defect feature set.
[0137] Step 320: Based on the cross-batch defect feature set, associate the production parameter data corresponding to each batch, filter out the key production parameter dimensions that are associated with the defect features, and obtain the defect-parameter associated feature group; perform feature correlation mapping on the defect-parameter associated feature group to establish a correspondence model between defect features and key production parameters.
[0138] In this embodiment, the metal product defect detection system uses a mutual information algorithm to calculate the mutual information value between each defect feature dimension and the production parameter dimension in the cross-batch defect feature set. Dimension pairs with mutual information values greater than a preset association threshold are identified as associated dimensions. Two key production parameter dimensions, stamping pressure and mold temperature, are selected to obtain a defect-parameter associated feature group. The input data consists of the cross-batch defect feature set and production parameter data, and the output data is the defect-parameter associated feature group. The metal product defect detection system uses a gradient boosting decision tree algorithm to establish a correspondence model between defect features and key production parameters. The input layer receives key production parameter data, and the output layer receives defect feature parameters. Model training uses the cross-batch defect-parameter associated feature group as training data. The optimizer uses a gradient descent optimizer with an initial learning rate of 0.01, 100 training epochs, and mean squared error as the loss function. Training continues until the loss function converges. The input data is the defect-parameter associated feature group, and the output data is the trained correspondence model.
[0139] Step 330: Input the production parameter data of the metal product to be inspected into the corresponding relationship model to obtain the production parameter influence weight corresponding to the defect feature; combine the production parameter influence weight with the surface defect detection results to generate extended detection results including defect cause correlation analysis; aggregate the extended detection results with multiple batches of historical extended detection results to obtain a defect-parameter correlation dataset for the same model of product.
[0140] In this embodiment, the metal product defect detection system inputs the stamping pressure and mold temperature parameters of the metal product to be inspected into a corresponding relational model. The model outputs the production parameter influence weights corresponding to each defect feature. The input data is the current production parameter data, and the output data is the set of production parameter influence weights. The metal product defect detection system integrates the production parameter influence weights with the current surface defect detection results to generate extended detection results, which include defect cause correlation analysis, such as the correlation between scratch defects and excessive stamping pressure, and the correlation between pit defects and excessively low mold temperature. The input data is the set of production parameter influence weights and the current surface defect detection results, and the output data is the extended detection results. The metal product defect detection system aggregates the current extended detection results with the historical extended detection results of the past 10 batches, and groups and statistically analyzes them according to the production parameter dimension and the defect type dimension to obtain a defect-parameter correlation dataset for products of the same model. The input data is the current extended detection results and the historical extended detection results, and the output data is the defect-parameter correlation dataset.
[0141] Optionally, the method further includes:
[0142] Step 410: Extract the core texture features and spatial distribution features of defects from the surface defect detection results, obtain the material property data and processing technology texture reference data of the metal product to be detected, and perform feature dimension matching between the core texture features, spatial distribution features and material property data and processing technology texture reference data to obtain a multi-source fusion feature set.
[0143] In this embodiment, the metal product defect detection system extracts the core texture features of the defects from the surface defect detection results, including gray-level co-occurrence matrix parameters and texture gradient direction distribution. The spatial distribution features of the defects include their physical coordinate range, area, and shape. The input data is the surface defect detection results, and the output data is a set of core texture features and spatial distribution features. The system retrieves material property data of stainless steel stampings from a material database, including hardness, toughness, and surface roughness. It also retrieves processing texture reference data from a process database, including the surface texture direction and texture depth distribution after stamping. The input data is the stored data from the material and process databases, and the output data is the material property data and processing texture reference data. The system matches the dimensions of the above four types of features, unifies the statistical standards and coordinate system of the features, and weights and concatenates the feature vectors to obtain a multi-source fusion feature set. The input data is the four types of feature sets, and the output data is the multi-source fusion feature set.
[0144] Step 420: Based on the multi-source fusion feature set, construct a verification dimension space for defect features, and perform multi-dimensional mapping between the defect type and defect range information in the current surface defect detection results and the verification dimension space; determine the consistency of the current defect identification results based on the mapping results; if there are inconsistent dimensions, correct the defect type and defect range based on the core fusion features; associate and bind the corrected surface defect detection results with the multi-source fusion features to generate optimized detection results with verification labels; feed the optimized detection results back to the feature extraction task module of the defect detection model to update the dimension weights of the feature extraction task module.
[0145] In this embodiment, the metal product defect detection system, based on a multi-source fusion feature set, constructs a verification dimension space for defect features using principal component analysis (PCA). The first three principal components are extracted as verification dimensions. The input data is the multi-source fusion feature set, and the output data is the feature vector of the verification dimension space. The system maps the defect type and defect range information from the current surface defect detection result to the verification dimension space. It calculates the Euclidean distance between the mapped vector and the standard defect vector of the same type. If the distance is greater than a preset consistency threshold, an inconsistent dimension is determined. The input data is the current defect information and the verification dimension space, and the output data is the consistency judgment result. If an inconsistent dimension exists, the system re-matches the defect type and recalculates the defect range based on the core fusion features in the multi-source fusion feature set, correcting the current defect identification result. The input data is the multi-source fusion feature set and the inconsistent dimension information, and the output data is the corrected surface defect detection result. The metal product defect detection system associates and binds the corrected surface defect detection results with multi-source fusion features to generate optimized detection results with verification labels. The input data consists of the corrected defect detection results and the multi-source fusion feature set; the output data is the optimized detection results with verification labels. The system then feeds the optimized detection results back to the feature extraction module of the defect detection model. An incremental learning method is used to update the dimensionality weights of the feature extraction module, improving the accuracy of feature extraction. The input data is the optimized detection results with verification labels; the output data is the updated feature extraction module of the defect detection model.
[0146] Optionally, the method further includes:
[0147] Step 510: Obtain surface images of the metal product to be inspected under different inspection time sequences and the corresponding surface defect detection results for each time sequence. Align the surface defect detection results of each time sequence according to the inspection time order to obtain the time sequence defect feature sequence.
[0148] In this embodiment, the metal product defect detection system retrieves surface images and corresponding surface defect detection results of the same metal product under inspection at three different inspection times: after stamping, after grinding, and after cleaning, from the factory production management system. The input data consists of multiple time-series surface images and defect detection results, and the output data is a set of multiple time-series defect data. The metal product defect detection system performs time-series alignment on the surface defect detection results of each time sequence according to the inspection time order, unifies the defect feature dimensions and coordinate system, and arranges the defect feature vectors of each time sequence in time order to obtain a time-series defect feature sequence. The input data is a set of multiple time-series defect data, and the output data is the time-series defect feature sequence.
[0149] Step 520: Extract the defect evolution features from the temporal defect feature sequence, wherein the defect evolution features include the expansion trend features of the defect region and the change trend features of the defect texture.
[0150] In this embodiment, the metal product defect detection system uses a linear fitting algorithm to fit the trajectory of the center coordinates of the defect region in a time-series defect feature sequence, obtaining the expansion trend characteristics of the defect region, including the expansion direction, expansion speed, and expansion range. The input data is the time-series defect feature sequence, and the output data is the defect region expansion trend characteristics. The metal product defect detection system also calculates the rate of change of the texture gradient direction distribution for each time sequence of the defect texture features in the time-series defect feature sequence, obtaining the defect texture change trend characteristics, including the change amplitude, change frequency, and stability of the texture direction. The input data is the time-series defect feature sequence, and the output data is the defect texture change trend characteristics.
[0151] Step 530: Perform time-series correlation between the temporal defect feature sequence and the defect features corresponding to the current surface defect detection results to construct a defect evolution path; based on the defect evolution path and defect evolution features, deduce the potential defect development state under subsequent detection time sequences.
[0152] In this embodiment, the metal product defect detection system associates the temporal defect feature sequence with the defect features corresponding to the current surface defect detection result, establishes the feature correspondence of defects in each temporal sequence, and constructs the defect evolution path. The input data consists of the temporal defect feature sequence and the current defect features, and the output data is a structured description of the defect evolution path. Based on the defect evolution path and defect evolution features, the metal product defect detection system uses a long short-term memory neural network to deduce the potential defect development state in subsequent detection time sequences. This network uses 3 layers of LSTM units and 1 fully connected layer. The input layer receives the temporal defect feature sequence, and the output layer outputs the predicted defect feature values for subsequent time sequences. The training data uses multi-temporal defect data of the same model of product. The optimizer uses the Adam optimizer with an initial learning rate of 0.001, 80 training epochs, and mean squared error as the loss function. The input data consists of the defect evolution path and evolution features, and the output data is the predicted result of the defect development state in subsequent detection time sequences.
[0153] Step 540: Combine the defect evolution path, defect development state prediction results, and current surface defect detection results to generate a detection result with time-series prediction; the detection result with time-series prediction is used to compare with historical time-series defect data of the same model of product to optimize the prediction logic of defect development state.
[0154] In this embodiment, the metal product defect detection system integrates the defect evolution path, defect development state prediction results, and the current surface defect detection results to generate a detection result with time-series prediction. This result includes the time-series evolution process of the defect, subsequent development predictions, and detailed information about the current defect. The input data are the defect evolution path, prediction results, and the current defect detection results; the output data is the detection result with time-series prediction. The metal product defect detection system compares the detection result with time-series prediction with historical time-series defect data of the same model of product, calculates the error between the prediction result and the actual defect data, and if the error is greater than a preset error threshold, adjusts the hyperparameters of the long short-term memory neural network to optimize the prediction logic of the defect development state. The input data are the detection result with time-series prediction and historical time-series defect data; the output data is the optimized defect prediction model parameters.
[0155] This application's embodiments achieve a breakthrough in the precision and intelligence of surface defect detection for metal products at a global level: First, by eliminating reflective disturbances and deeply adapting the baseline texture model, the interference of specular reflection on texture feature extraction from the metal surface is eliminated at its source, ensuring that the basic data for defect detection closely matches the actual surface state of the product; Second, the coordinated processing of defect texture gradient separation and boundary pixel reconstruction not only achieves precise positioning of the defect area but also compensates for the recognition errors caused by boundary discreteness and missing parts in traditional defect detection through pixel-level reconstruction, significantly improving the integrity and accuracy of the defect area contour; Furthermore... The combined application of local variance enhancement and neighborhood correlation analysis amplifies the gray-scale abrupt change features of defects while effectively eliminating false defects caused by texture fluctuations and uneven lighting through correlation verification of neighboring pixels, significantly reducing the false detection rate. Finally, the collaborative processing of gray-scale inverse stretching in overexposed areas and clustering of abnormal pixel groups solves the problem of feature loss caused by overexposure in defect areas, and achieves accurate classification and quantification of different types of defects through clustering. The final output detection results have accuracy, completeness and classification refinement, which can meet the real-time and efficient defect detection needs of high-precision metal product production lines.
[0156] Please see Figure 2 The figure is a schematic diagram of the basic structure of a metal product defect detection system 200 provided in an embodiment of this application. The metal product defect detection system 200 includes: a processor 201; a storage device 202 on which a computer program 2020 is stored; and a network interface 203 for providing network communication functions. When the computer program 2020 is executed by the processor 201, the processor 201 implements any of the image recognition-based metal product defect detection methods described above.
[0157] Please see Figure 3 This application provides a functional block diagram of a metal product defect detection device, which includes:
[0158] The reflection disturbance elimination module is used to perform reflection disturbance elimination processing on the surface image of the metal product to be inspected, and obtain the reflection elimination image;
[0159] The texture model generation module is used to obtain the surface reference texture features of the defect-free metal product, and generate a reference texture model based on the texture distribution pattern, grayscale mean and texture continuity of the surface reference texture features.
[0160] The defect region segmentation module is used to locate abnormal regions that differ from the benchmark texture by comparing texture features when performing defect texture gradient separation on the reflective decontamination image based on the benchmark texture model, calculate the texture gradient change of the abnormal region and generate a defect texture gradient map, and segment the suspected defect texture region from the defect texture gradient map.
[0161] The defect texture reconstruction module is used to determine the supplementation rules of the boundary pixels in the suspected defect texture region according to the preset boundary pixel reconstruction strategy, fill the missing boundary pixels and correct the discrete boundary pixels according to the supplementation rules, and obtain the defect texture reconstruction region.
[0162] The defect region optimization module is used to amplify the texture grayscale difference of the defect texture reconstruction region through local variance enhancement processing, generate a defect texture enhancement region including defect grayscale abrupt change features, perform neighborhood correlation analysis on the defect texture enhancement region, and remove pseudo-defect pixels based on the neighborhood correlation analysis results to obtain the target defect texture region.
[0163] The surface defect detection module is used to locate the overexposed area in the target defect texture area and perform grayscale reverse stretching to obtain a pre-processed defect area, perform abnormal pixel group feature clustering on the pre-processed defect area to obtain a clustering result, and output the surface defect detection result of the metal product to be detected based on the clustering result.
[0164] Based on the above, a readable storage medium is provided, on which a program or instructions are stored, and when the program or instructions are executed by a processor, the steps of the above method are implemented.
[0165] Furthermore, it should be noted that this application also provides a computer program product, which may include a computer program that can be stored in a computer-readable storage medium. The processor of the metal product defect detection system reads the computer program from the computer-readable storage medium, and the processor can execute the computer program, causing the metal product defect detection system to perform the aforementioned... Figure 1 The methods described in the corresponding embodiments are already known, and therefore will not be repeated here. Furthermore, the beneficial effects of using the same method will also not be repeated. For technical details not disclosed in the computer program product embodiments related to this application, please refer to the description of the method embodiments of this application.
[0166] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the systems or apparatus disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple, and relevant parts can be referred to the method section.
Claims
1. An image recognition-based metal product defect detection method, characterized by, The method includes: The surface image of the metal product to be inspected is subjected to reflective perturbation removal processing to obtain a reflective removal image; Obtain the surface reference texture features of the defect-free metal product, and generate a reference texture model based on the texture distribution pattern, grayscale mean, and texture continuity of the surface reference texture features. When performing defect texture gradient separation on the reflected light reduction image based on the benchmark texture model, abnormal regions that differ from the benchmark texture are located by comparing texture features. The texture gradient changes of the abnormal regions are calculated and a defect texture gradient map is generated. Suspected defect texture regions are segmented from the defect texture gradient map. The reflected light reduction image is divided into multiple sub-texture regions according to preset texture units. The texture distribution features, grayscale distribution features, and texture continuity features of each sub-texture region are extracted to obtain a sub-texture feature set. The benchmark texture model is called, and benchmark sub-texture features corresponding to each sub-texture region are extracted from the benchmark texture model to establish a one-to-one correspondence between sub-texture regions and benchmark sub-texture features. The sub-texture features of each sub-texture region are compared with the corresponding benchmark sub-texture features step by step. Dimensional comparison is performed to identify sub-texture regions where sub-texture features differ from baseline sub-texture features. Adjacent sub-texture regions with discrepancies are then fused to obtain the abnormal regions. Texture direction analysis is performed on the abnormal regions to determine the dominant direction of the texture within the abnormal regions. The variation amplitude of texture grayscale is calculated along the dominant direction and perpendicular to the dominant direction to obtain texture gradient change data. Using the spatial coordinates of the abnormal regions as a reference, the texture gradient change data is mapped to the corresponding coordinate positions to generate a defect texture gradient map containing gradient change intensity and gradient direction. Based on the distribution characteristics of gradient change intensity in the defect texture gradient map, gradient intensity intervals are divided, and target regions with gradient change intensity within a preset interval are selected. Edge contour extraction is performed on the target regions to obtain the suspected defect texture regions. The supplementation rules for boundary pixels in the suspected defective texture region are determined according to the preset boundary pixel reconstruction strategy. The missing boundary pixels are filled and the discrete boundary pixels are corrected according to the supplementation rules to obtain the defective texture reconstruction region. The texture grayscale difference of the defect texture reconstruction region is amplified by local variance enhancement processing to generate a defect texture enhancement region including defect grayscale abrupt change features. Neighborhood correlation analysis is performed on the defect texture enhancement region, and pseudo-defect pixels are removed based on the neighborhood correlation analysis results to obtain the target defect texture region. The overexposed area in the target defect texture region is located and grayscale inverse stretching is performed to obtain the preprocessed defect region. The abnormal pixel group feature clustering of the preprocessed defect region is performed to obtain the clustering result. The surface defect detection result of the metal product to be detected is output according to the clustering result.
2. The method of claim 1, wherein, The step of determining the supplementation rules for boundary pixels in the suspected defective texture region according to a preset boundary pixel reconstruction strategy, filling in missing boundary pixels and correcting discrete boundary pixels according to the supplementation rules, and obtaining the defective texture reconstruction region includes: Extract the set of edge pixels in the suspected defective texture region, sort the pixels in the edge pixel set by coordinates, and obtain the edge pixel sequence; Calculate the coordinate difference between adjacent pixels in the edge pixel sequence, determine the continuity of boundary pixels based on the coordinate difference, and identify discrete pixels whose coordinate difference exceeds the preset range and missing pixel regions where there is a coordinate discontinuity between adjacent pixels. For the missing pixel region, the continuous edge pixels on both sides of the missing pixel region are used as a reference to identify the texture grayscale change trend of the edge pixels. Combined with the texture distribution pattern of the corresponding position in the reference texture model, the grayscale supplementation rule of the missing pixel is determined. For discrete pixels, the gray-level similarity and spatial distance between the discrete pixel and the surrounding pixels in the edge pixel sequence are calculated. Based on the gray-level similarity and spatial distance, the correction direction and correction magnitude of the discrete pixel are determined, and the discrete pixel correction rule is obtained. The pixel values of the missing pixel region are filled according to the grayscale filling rules of the missing pixels, and the coordinates and grayscale values of the discrete pixels are adjusted according to the discrete pixel correction rules to obtain the initial reconstruction boundary. The texture features of the initial reconstructed boundary are compared with the texture features of the reference texture model. The gray values of the boundary pixels are adjusted according to the comparison results to complete the boundary pixel reconstruction, thereby obtaining the defect texture reconstruction region.
3. The method as described in claim 1, characterized in that, The process of amplifying the texture grayscale difference in the defect texture reconstruction region through local variance enhancement processing to generate a defect texture enhancement region including defect grayscale abrupt change features, performing neighborhood correlation analysis on the defect texture enhancement region, and removing pseudo-defect pixels based on the neighborhood correlation analysis results to obtain the target defect texture region includes: The defect texture reconstruction region is divided into multiple local texture blocks, and the gray-level variance value of each local texture block is calculated to obtain the local variance distribution matrix. Based on the local variance distribution matrix, the gray value of each local texture block is adjusted by variance enhancement to amplify the gray value difference in the first gray value variance region and suppress the gray value fluctuation in the second gray value variance region, thus obtaining the initial enhanced texture region. Extract grayscale abrupt change points in the initial enhanced texture region, identify the grayscale change amplitude and spatial distribution density of the grayscale abrupt change points, mark the regions where the grayscale change amplitude exceeds a preset threshold and the spatial distribution density meets the preset conditions as defective grayscale abrupt change regions, and integrate all defective grayscale abrupt change regions to obtain the defective texture enhancement region. Taking each pixel in the defect texture enhancement region as the center, select neighboring pixels within a preset range to form a neighboring pixel set, and calculate the grayscale correlation coefficient between the center pixel and each pixel in the neighboring pixel set; The distribution of neighborhood correlation coefficients for each center pixel is statistically analyzed and a correlation coefficient threshold is determined. Center pixels with neighborhood correlation coefficients lower than the correlation coefficient threshold are marked as candidate pseudo-defect pixels. The candidate pseudo-defect pixels are subjected to region connectivity analysis. Connected candidate pseudo-defect pixels are divided into pseudo-defect regions. The pixel regions that meet the pseudo-defect features are removed by combining the texture features of the baseline texture model to obtain the target defect texture region.
4. The method as described in claim 3, characterized in that, The process of performing region connectivity analysis on the candidate pseudo-defect pixels, dividing connected candidate pseudo-defect pixels into pseudo-defect regions, and eliminating pixel regions that conform to the pseudo-defect features based on the texture features of the baseline texture model to obtain the target defect texture region includes: A region growing algorithm is used to perform connectivity analysis on the candidate pseudo-defect pixels. Using the candidate pseudo-defect pixels as seed points, candidate pseudo-defect pixels that meet the gray-level similarity condition in their neighborhood are included in the same connected region. By gradually expanding the neighborhood range of the seed point, the connected region is divided, and multiple pseudo-defect regions are generated. Extract the texture feature parameters of each pseudo-defect region, and extract the reference texture feature parameters corresponding to the spatial position of each pseudo-defect region from the reference texture model; The texture feature parameters of each pseudo-defect region are compared with the corresponding baseline texture feature parameters in each dimension, and the texture feature difference is calculated. The degree of matching between each pseudo-defect region and the baseline texture is determined based on the texture feature difference. Based on the overall texture distribution pattern of the defect texture enhancement area, a texture gradient fusion model is constructed. The texture feature parameters of each pseudo-defect area and the degree of matching with the reference texture are input into the texture gradient fusion model. The texture adjustment coefficient of each pseudo-defect area is obtained through the calculation of the texture gradient fusion model. The grayscale value and texture gradient features of each pseudo-defect region are adjusted according to the texture adjustment coefficient to optimize the pixel features corresponding to the pseudo-defect region. Using the texture gradient features of adjacent regions as a transition basis, the optimized pseudo-defect region is fused with the region of the defect texture enhancement region that is not marked as a candidate pseudo-defect pixel to obtain the target defect texture region.
5. The method as described in claim 1, characterized in that, The process involves locating overexposed areas within the target defect texture region and performing grayscale inverse stretching to obtain a preprocessed defect region. Abnormal pixel clustering is then performed on the preprocessed defect region to obtain clustering results. Based on these clustering results, the surface defect detection results of the metal product to be inspected are output, including: Extract the grayscale value distribution of the target defect texture region, filter out overexposed pixels with grayscale values higher than a preset grayscale overexposure threshold, merge adjacent overexposed pixels to obtain the overexposed region; A grayscale range analysis is performed on the overexposed area to determine the maximum grayscale value and grayscale distribution range of the overexposed area. Based on the grayscale distribution range, the parameters of the inverse stretching function are set, and the grayscale values of the overexposed area are mapped and adjusted through the inverse stretching function. The grayscale span of the first grayscale value interval is compressed and the grayscale difference of the second grayscale value interval is expanded to obtain the overexposed area after grayscale adjustment. The preprocessed defect region is obtained by fusing the overexposed area after grayscale adjustment with the unexposed area in the target defect texture region; the feature parameters of each pixel in the preprocessed defect region are extracted and a pixel feature vector is generated, the pixel feature vector including grayscale value, texture gradient direction and neighborhood correlation coefficient. The feature clustering method is used to cluster all pixel feature vectors. Based on the similarity of the pixel feature vectors, the pixels are divided into different pixel groups, and each pixel group corresponds to a type of defect feature. Based on the spatial distribution pattern, area, and feature parameter distribution of each pixel group, the clustering result is obtained. Based on the clustering result, different types of defects are distinguished, and surface defect detection results containing defect type, defect location, and defect range are generated and output.
6. The method as described in claim 5, characterized in that, The feature clustering method is used to cluster all pixel feature vectors, dividing the pixels into different pixel groups based on the similarity of the pixel feature vectors. Each pixel group corresponds to a type of defect feature, including: The feature vectors of all pixels in the preprocessed defect region are subjected to feature standardization to eliminate the dimensional differences between different feature parameters, resulting in standardized feature vectors. Calculate the Euclidean distance between the standardized feature vectors, and use the Euclidean distance as a measure of feature similarity to establish a feature similarity matrix. The elements in the feature similarity matrix correspond to the Euclidean distance between any two standardized feature vectors. Based on the feature similarity matrix, the density peak clustering method is used to determine the initial cluster centers. The initial cluster centers are selected by calculating the local density of each normalized feature vector and the minimum Euclidean distance to other normalized feature vectors, and the two-dimensional scatter plot drawn based on the local density and the minimum Euclidean distance. Each initial cluster center corresponds to an initial pixel group. Iterate through all standardized feature vectors and assign each standardized feature vector to the initial pixel group corresponding to the nearest initial cluster center to complete the first cluster assignment; calculate the mean vector of all standardized feature vectors in each pixel group after the first cluster assignment, use the mean vector as the new cluster center, and calculate the average distance between the standardized feature vector in each pixel group and the corresponding new cluster center; adjust the cluster radius of each pixel group according to the average distance so that the cluster radius is 1.2 times the average distance, and re-execute the standardized feature vector assignment step based on the adjusted cluster radius; Repeat the steps of calculating new cluster centers, adjusting cluster radii, and assigning standardized feature vectors until the change in the number of new cluster centers between two consecutive iterations is less than the preset change, thus completing the clustering iteration; The feature parameter range corresponding to each pixel group after the clustering iteration is matched with the preset defect feature parameter range to determine the defect feature type corresponding to each pixel group, thus completing the classification of the pixel group.
7. The method as described in claim 5, characterized in that, The clustering results are obtained based on the spatial distribution pattern, area, and feature parameter distribution of each pixel group. Based on the clustering results, different types of defects are distinguished, and surface defect detection results containing defect type, defect location, and defect range are generated and output, including: Extract the spatial coordinate set of each pixel group, fit the edge contour of the pixel group using the spatial coordinate set, and use a curve fitting algorithm to smooth the coordinate points of the edge contour to obtain the smoothed edge contour. By analyzing the curvature change and tangent direction change of the smoothed edge contour, determine the spatial distribution morphology characteristics of the pixel group. The number of pixels in each pixel group is counted, and combined with the pixel resolution of the surface image of the metal product to be detected, the number of pixels is converted into the corresponding actual physical area to obtain the area parameter of each pixel group. Statistical analysis is performed on the feature parameters within each pixel group to calculate the mean, variance, and extreme values of the feature parameters, thereby obtaining the feature parameter distribution. The feature parameters include standardized gray values, texture gradient directions, and neighborhood correlation coefficients. The clustering result is obtained by integrating the spatial distribution morphological features, region area parameters, and feature parameter distribution of each pixel group; Establish a defect type feature library, which stores spatial distribution morphology standards, regional area range standards, and feature parameter distribution standards corresponding to different defect types; The clustering results of each pixel group are compared with each standard in the defect type feature library dimension by dimension. Based on the comparison results, the defect type corresponding to each pixel group is determined, and the defect location and defect range are determined based on the spatial coordinate set of each pixel group. The defect type, defect location, and defect range corresponding to each pixel group are associated with the spatial coordinate system of the surface image of the metal product to be inspected to obtain the associated defect information. The associated defect information is structured and organized to generate surface defect detection results that include a product defect overview, detailed defect features, and defect spatial distribution. The surface defect detection results are then transmitted to the designated storage module and display module through a preset output interface.
8. A defect detection system for metal products, characterized in that, include: A processor; a storage device having a computer program stored thereon; a network interface for providing network communication functions; when the computer program is executed by the processor, the processor enables the processor to implement the image recognition-based metal product defect detection method as described in any one of claims 1-7.
9. A readable storage medium, characterized in that, The readable storage medium stores a program or instructions that, when executed by a processor, implement the image recognition-based metal product defect detection method as described in any one of claims 1-7.
Citation Information
Patent Citations
Special equipment defect automatic identification method and system
CN120495756A
Workpiece surface defect image recognition method
CN121236065A