Machine vision algorithm for determining defects on highly reflective metal surfaces

By combining adaptive contrast enhancement and specular reflection filtering to improve the YOLO detection network, the problems of light sensitivity and multi-scale adaptability in the detection of highly reflective metal surfaces are solved, achieving high-precision and low-cost detection results.

CN122134669APending Publication Date: 2026-06-02SHANGHAI UNIV OF ENG SCI

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SHANGHAI UNIV OF ENG SCI
Filing Date
2026-02-14
Publication Date
2026-06-02

AI Technical Summary

Technical Problem

Existing high-reflectivity metal surface defect detection technologies suffer from high light sensitivity, poor multi-scale adaptability, and strong hardware dependence, resulting in low detection accuracy and high costs.

Method used

An improved YOLO detection network is developed by combining adaptive contrast enhancement and specular reflection filtering. Through attention mechanism and multi-scale feature fusion network, the ability to extract and identify defect features is enhanced, and hardware dependence is reduced.

Benefits of technology

It enables stable detection of highly reflective metal surfaces, reduces detection costs and maintenance difficulty, improves detection accuracy and real-time performance, and adapts to different materials and lighting conditions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122134669A_ABST
    Figure CN122134669A_ABST
Patent Text Reader

Abstract

This invention relates to a machine vision algorithm for determining defects on highly reflective metal surfaces, belonging to the interdisciplinary field of computer vision and industrial quality inspection. The method includes: acquiring an original image of the highly reflective metal surface; performing preprocessing based on adaptive contrast enhancement and suppression of specular reflection components using local brightness characteristics; inputting the preprocessed image into an improved YOLO detection network specifically adapted for highly reflective surfaces. This network enhances defect features through a backbone network embedding an attention mechanism and aggregates information at different scales using a lightweight multi-scale feature fusion network to output preliminary prediction boxes; performing post-processing on the prediction boxes, including adaptive non-maximum suppression, confidence-weighted averaging, morphological closing operations, and connected component merging; and outputting the defect category, location, and confidence score of the merged detection boxes. This method effectively suppresses high reflectivity interference and improves the detection accuracy and robustness for multi-scale defects on metal surfaces.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the interdisciplinary field of computer vision and industrial quality inspection, and specifically relates to a machine vision algorithm for determining defects on highly reflective metal surfaces. Background Technology

[0002] In the industrial manufacturing sector, highly reflective metal materials such as stainless steel sheets, aluminum alloy components, and precision metal stampings are widely used in key industries such as automobiles, aerospace, and electronic equipment due to their excellent mechanical and physicochemical properties. Defects on metal surfaces, such as deformation, scratches, dirt, and indentations, directly affect the assembly accuracy, service life, and appearance quality of products, and may even cause safety hazards. Therefore, surface defect detection is an indispensable core of quality control in the metal processing and production process.

[0003] Traditional metal surface defect detection relies on manual visual inspection, which is not only inefficient and labor-intensive but also susceptible to subjective factors such as the inspector's experience and fatigue, making it difficult to meet the high-speed, high-precision inspection requirements of modern production lines. To address this issue, machine vision inspection technology has gradually replaced manual inspection and become the mainstream solution. Early machine vision inspection methods mainly relied on traditional image processing algorithms, such as multi-class SVM-based detection schemes. These schemes extracted spectral-related features through preprocessing steps such as wavelet smoothing denoising and Otsu thresholding before inputting them into a classification model to complete defect identification. However, these methods are highly dependent on manually designed features, have weak resistance to specular reflection interference from highly reflective metal surfaces, and experience a significant drop in feature extraction accuracy when the contrast between the defect and the background is low. Furthermore, they are difficult to adapt to the multi-scale inspection requirements of defects of different sizes, limiting their detection accuracy and stability.

[0004] In recent years, the development of deep learning technology has driven the technological upgrade of metal surface defect detection. Target detection algorithms, represented by the YOLO series, have been widely used in industrial inspection due to their end-to-end architecture and real-time advantages. Their detection speed is hundreds of times faster than traditional systems, meeting the real-time inspection needs of production lines. However, the strong specular reflection of highly reflective metal surfaces can lead to localized overexposure of images and blurred defect edges, causing defect features to be masked by reflective noise. Simultaneously, the wide range of defect sizes in industrial scenarios (from micro-scratches to large deformations) results in significant shortcomings in existing YOLO algorithms: firstly, high light sensitivity, making them prone to false positives or missed defects due to reflective interference; secondly, poor multi-scale adaptability, with the traditional FPN+PAN feature fusion structure struggling to handle feature extraction from both micro- and large defects; and thirdly, insufficient differentiation between defects and background, lacking optimized feature enhancement mechanisms for highly reflective scenarios, resulting in detection accuracy that fails to meet the stringent requirements of high-end manufacturing.

[0005] Furthermore, existing solutions for detecting defects on highly reflective metal surfaces suffer from significant hardware dependence: to mitigate specular reflection interference, the industry commonly employs customized high-end light sources, high-precision industrial cameras, and dedicated optical lenses. The high cost of a single set of such hardware significantly increases the equipment investment threshold for enterprises. Simultaneously, metal parts of different materials and processing techniques have vastly different requirements for light source angle, brightness, and polarization parameters. On-site debugging requires professional technicians to spend several days or even weeks calibrating parameters, resulting in long debugging cycles and high labor costs. Existing solutions attempt to address the reflection interference problem through hardware upgrades, but this not only remains costly but also limits the stability and versatility of the detection system due to the sensitivity of hardware parameters. Meanwhile, software-level algorithm optimization has not become a core breakthrough, failing to fundamentally reduce enterprises' detection costs and maintenance complexity. In contrast, innovative optimization at the software algorithm level can achieve accurate detection of highly reflective metal surface defects without relying on high-end customized hardware, significantly reducing enterprises' hardware procurement costs and subsequent debugging and maintenance costs. This represents the core development direction for highly reflective metal defect detection technology. Summary of the Invention

[0006] To address the aforementioned problems in the existing technology, this invention provides a machine vision algorithm for determining defects on highly reflective metal surfaces. The objective of this invention can be achieved through the following technical solutions: A machine vision algorithm for determining defects on highly reflective metal surfaces includes: S1: Obtain the original image of the highly reflective metal surface, perform adaptive contrast enhancement processing based on local brightness characteristics on the original image, and then perform filtering processing to suppress specular reflection components to obtain a preprocessed image. S2: The preprocessed image is input into an improved YOLO detection network adapted for detecting defects on highly reflective surfaces. Multi-scale features are extracted and fused through a backbone feature extraction network and a multi-scale feature fusion network, and a preliminary prediction box containing location, category, and confidence is output. The backbone feature extraction network is embedded with an attention mechanism module to enhance defect-related features and suppress background features. The multi-scale feature fusion network adopts a lightweight structure to fuse features of different scales from the backbone network. S3: Post-process the preliminary predicted boxes: perform non-maximum suppression on the predicted boxes output by the detection heads at different scales, and perform a weighted average of the class confidence of the overlapping boxes; perform morphological closing operation on the retained predicted boxes, perform connected component labeling, and merge multiple detection boxes belonging to the same connected component. S4: Output the defect category, location coordinates, and confidence level corresponding to the merged detection box.

[0007] As a preferred technical solution of the present invention, the adaptive contrast enhancement processing based on local brightness characteristics specifically includes: dividing the original image into multiple local regions, calculating the brightness statistical characteristics of each region respectively; determining the adaptive contrast enhancement parameters of each region based on the difference between the brightness statistical characteristics of each region and the global brightness statistical characteristics, and stitching the contrast of each region together to obtain an intermediate image.

[0008] Specifically, the filtering process for suppressing specular reflection components includes: identifying pixel regions with specular reflection characteristics and normal pixel regions in the original image; applying different filtering weights to the specular reflection regions and the normal regions respectively, and preserving the edge details of defects while suppressing specular reflection.

[0009] The improved YOLO detection network is configured to use dynamically generated anchor boxes whose size is determined based on the distribution of defect sizes in the multi-scale fused feature map, and whose aspect ratio is optimized based on the clustering results of historical defect annotation data.

[0010] The attention mechanism module includes a channel attention submodule and a spatial attention submodule.

[0011] The channel attention submodule generates channel weights by aggregating the spatial information of the feature map; the spatial attention submodule generates spatial weights by aggregating the channel information of the feature map.

[0012] The channel attention submodule is a dual-pooling fusion channel attention module, which specifically includes: performing global pooling and local pooling on the input feature map to obtain global features and local features; fusing the two and calculating channel weights through a gating mechanism.

[0013] The backbone feature extraction network is an improved deep convolutional network with embedded lightweight convolutional structures and residual connection structures; wherein, the lightweight convolutional structure can adaptively select the convolution operation type according to the statistical characteristics or gradient characteristics of the pixel values ​​of the input image region.

[0014] The multi-scale feature fusion network adopts a lightweight structure, specifically including: channel optimization of feature maps at each scale through GSConv convolutional layers, and bidirectional fusion of cross-scale features through an FF-Slim-Neck structure; wherein, the FF-Slim-Neck structure has an embedded adaptive feature selection gate, which dynamically determines the fusion path and transmission ratio of features at each scale according to the sparsity and response intensity of the GSConv output features.

[0015] The non-maximum suppression process employs an adaptive threshold adjustment mechanism, the adjustment of which is based on at least one of the following: the size of the prediction box, the distribution density, and the category attribute.

[0016] The morphological closing operation processing uses adaptive structuring elements, whose shape and specifications are selected from a preset multi-scale structuring element library based on the morphological characteristics of the defect region.

[0017] Merging multiple detection boxes belonging to the same connected region specifically includes: first, verifying and removing outlier boxes belonging to the same connected region according to a preset geometric consistency rule; and then performing weighted fusion based on the spatial location, category, and confidence level of the multiple detection boxes.

[0018] The beneficial effects of this invention are as follows: The anti-reflective interference capability is significantly improved, and the detection stability is greatly enhanced. This invention employs a preprocessing scheme of "adaptive contrast enhancement based on local brightness characteristics + differential filtering to suppress specular reflection" to accurately identify and reduce the specular reflection component in highly reflective areas. Simultaneously, by adjusting for regional differences, it preserves the details of defect edges, effectively solving the problems of overexposure in images of highly reflective metal surfaces and the masking of defect features by noise. Even in industrial scenarios with fluctuating lighting and uneven reflective intensity, it can output low-interference preprocessed images, significantly reducing light sensitivity and avoiding false positives and missed defects caused by reflection. The detection stability is significantly improved compared to existing technologies.

[0019] The algorithm achieves outstanding multi-scale detection accuracy and comprehensively optimizes defect identification accuracy. The channel-space hybrid attention mechanism embedded in the backbone network enhances the distinction between defect features and background through dual-pooling fusion and cross-dimensional weighting. The multi-scale feature fusion network employs a lightweight GSConv+FF-Slim-Neck structure, combined with an adaptive feature selection gate, to achieve efficient feature aggregation for defects of different sizes, such as micro-scratches and large deformations. Dynamically generated anchor boxes are optimized through defect size distribution statistics and historical data clustering, further improving bounding box regression accuracy. Through the synergistic effect of multiple technologies, the algorithm significantly improves the comprehensive detection accuracy of four types of defects: deformation, scratches, dirt, and indentations, effectively reducing the false negative and false positive rates and meeting the stringent quality requirements of high-end manufacturing.

[0020] Balancing real-time performance with industrial adaptability, this algorithm meets the high-efficiency inspection needs of production lines. The dynamically switchable lightweight convolutional and residual connection structure of the backbone network significantly reduces computational redundancy while maintaining feature extraction capabilities. The lightweight design and adaptive fusion strategy of the multi-scale feature fusion network further optimize computational efficiency. This algorithm was deployed on an embedded industrial PC (experimental platform: x86 industrial PC + RTX 5080). With an input image resolution of 4K, the inference speed reached 120 FPS, and the end-to-end latency was less than 20 ms.

[0021] With broad scenario adaptability, the algorithm combines intelligence and practicality. By dynamically adjusting preprocessing parameters, fusion weights, and NMS thresholds, it can adapt to defect detection needs of metal materials with different reflectivity, under different lighting conditions, and with different size spans, eliminating the need for frequent manual parameter adjustments. Furthermore, optimizations in post-processing, such as outlier removal and weighted fusion of detection boxes, along with accurate information on defect categories and locations, provide intuitive data support for production quality control. This helps production lines adjust processes in real time, reduce defective product output, and improve overall production efficiency and product quality. Attached Figure Description

[0022] To facilitate understanding by those skilled in the art, the present invention will be further described below with reference to the accompanying drawings.

[0023] Figure 1 This is a flowchart illustrating a machine vision algorithm for determining defects on highly reflective metal surfaces according to the present invention. Figure 2 This is a diagram of the improved YOLO detection network architecture of the present invention; Figure 3 This is a flowchart of the adaptive structuring element matching and selection process in the morphological closing operation of the present invention. Detailed Implementation

[0024] To further illustrate the technical means and effects of the present invention in achieving its intended purpose, the following detailed description of the specific implementation methods, structures, features, and effects of the present invention, in conjunction with the accompanying drawings and preferred embodiments, is provided.

[0025] Please see Figure 1-3 A machine vision algorithm for determining defects on highly reflective metal surfaces, comprising: S1: Obtain the original image of the highly reflective metal surface, perform adaptive contrast enhancement processing based on local brightness characteristics on the original image, and then perform filtering processing to suppress specular reflection components to obtain a preprocessed image. S2: The preprocessed image is input into an improved YOLO detection network adapted for detecting defects on highly reflective surfaces. Multi-scale features are extracted and fused through a backbone feature extraction network and a multi-scale feature fusion network, and a preliminary prediction box containing location, category, and confidence is output. The backbone feature extraction network is embedded with an attention mechanism module to enhance defect-related features and suppress background features. The multi-scale feature fusion network adopts a lightweight structure to fuse features of different scales from the backbone network. S3: Post-process the preliminary predicted boxes: perform non-maximum suppression on the predicted boxes output by the detection heads at different scales, and perform a weighted average of the class confidence of the overlapping boxes; perform morphological closing operation on the retained predicted boxes, perform connected component labeling, and merge multiple detection boxes belonging to the same connected component. S4: Output the defect category, location coordinates, and confidence level corresponding to the merged detection box.

[0026] As a preferred technical solution of the present invention, the adaptive contrast enhancement processing based on local brightness characteristics specifically includes: dividing the original image into multiple local regions, calculating the brightness statistical characteristics of each region respectively; determining the adaptive contrast enhancement parameters of each region based on the difference between the brightness statistical characteristics of each region and the global brightness statistical characteristics, and stitching the contrast of each region together to obtain an intermediate image.

[0027] This embodiment uses the original image of the surface of a highly reflective aluminum alloy component (resolution 1280×720, 8-bit grayscale image, pixel brightness value range 0-255) as an example to explain in detail the specific implementation process of adaptive contrast enhancement: A "non-overlapping uniform partitioning" strategy is employed to divide the original 1280×720 image into local regions of 16×16 pixels. For the remaining portions of the image edges that are less than 16×16 pixels (e.g., 10 columns of pixels remaining on the right edge, 5 rows of pixels remaining on the bottom edge), these are directly merged into complete edge-complementary regions, resulting in a total of 5400 effective local regions. This partitioning method ensures relatively consistent brightness characteristics within each region while reducing computational load, adapting to the needs of real-time industrial inspection. Edge-complementary processing avoids brightness feature distortion caused by region truncation.

[0028] Global brightness statistics: Traverse the entire original image, calculate the global average brightness and the concentration of brightness distribution, and record the brightest and darkest pixel values ​​in the image to determine the overall brightness level and brightness fluctuation range (e.g., the measured global average brightness is too bright, and there are some overly bright areas). Local brightness statistics: For each 16×16 local area, the average brightness, the degree of brightness distribution concentration (i.e. whether the pixel brightness in the area is concentrated in a certain range), and the brightest and darkest pixel values ​​in the area are calculated to determine whether the area is too dark, too bright (reflective), or has moderate brightness.

[0029] By comparing the statistical results of each local region with the global statistical results, three types of regions are identified: Dark areas: The local average brightness is significantly lower than the global average brightness, and the brightness distribution is concentrated in the low brightness range. These areas may have defects that are being masked. Reflective areas: The local average brightness is significantly higher than the global average brightness, or the brightest pixel value in the area is close to 255 (overexposed), which is a high reflective interference area; Normal area: The local brightness statistics are similar to the global results, the brightness distribution is uniform, and there is no obvious underexposure or overexposure.

[0030] Enhancement parameters were set separately for the three types of areas, with the core principle being "brighten dark areas to increase contrast, darken reflective areas to reduce brightness, and fine-tune normal areas to preserve their original colors": Dark areas: Using the "gentle brightening + contrast enhancement" parameters, while increasing the overall brightness of the area, the brightness difference between the defect and the background is widened, allowing the details of the defect in the dark area to be revealed; Reflective areas: The "brightness compression + weak contrast" parameter is used to reduce the brightness intensity of overexposed areas to prevent further diffusion of reflections, while not enhancing contrast to prevent noise amplification; Normal area: The "Slight Contrast Optimization" parameter is used to fine-tune the brightness balance, preserve the original metallic texture and potential defect features, and avoid over-processing.

[0031] Enhancement processing is performed on each local area according to the corresponding parameters: histogram equalization combined with brightness enhancement is used in dark areas, linear brightness compression is used in reflective areas, and mild Gamma correction is used in normal areas. All processed local regions are stitched together in the positional order of the original image, and a smooth transition of 2-3 pixels is performed on the edges of adjacent regions (i.e., the pixel values ​​of adjacent regions gradually transition), completely eliminating stitching marks. The final intermediate image not only solved the problems of overexposure in the reflective areas and blurred details in the dark areas in the original image, but also fully preserved the texture and defect edges of the metal surface, laying a good foundation for subsequent filtering processing to suppress specular reflection.

[0032] Specifically, the filtering process for suppressing specular reflection components includes: identifying pixel regions with specular reflection characteristics and normal pixel regions in the original image; applying different filtering weights to the specular reflection regions and the normal regions respectively, and preserving the edge details of defects while suppressing specular reflection.

[0033] This embodiment uses a pre-processed intermediate image (1280×720 resolution, 8-bit grayscale) of a high-reflectivity stainless steel plate surface as the processing object. After the initial adaptive contrast enhancement, the image still has local specular reflection areas (such as edge chamfers and reflective points on smooth surfaces), and contains defects such as scratches and minor indentations. The specific filtering process is as follows: A combined approach of "threshold determination + neighborhood-assisted verification" is used to accurately distinguish between specular reflection pixel areas and normal pixel areas, avoiding misjudgment of defective bright edges. Threshold T determination: First, calculate the global average brightness of the intermediate image. Considering that the pixel values ​​of highly reflective areas are close to the overexposure range, set the threshold T to "global average brightness + 50" (this value is set based on empirical values ​​in industrial inspection scenarios). This setting is based on the brightness distribution law of reflective pixels on highly reflective metal surfaces, which covers most of the strongly reflective pixels and avoids the defect edges of normal bright areas. Preliminary screening: Traverse all pixels in the image and mark pixels with a brightness value > T as "candidate reflective pixels"; Neighborhood verification: For each candidate reflective pixel, analyze the pixel brightness distribution within its 3×3 neighborhood. If more than 70% of the pixels in the neighborhood also have a brightness value > T, and the brightness difference between neighboring pixels is less than 30 (no obvious edge features), then it is determined to be a "specular reflection pixel". If there is an obvious brightness gradient (such as a defective edge) in the neighborhood, then the candidate pixel is removed to avoid misjudging a bright defective edge as a reflection. Region merging: Connect adjacent specular reflection pixels into blocks to form a complete specular reflection region; the remaining unmarked pixels are normal pixel regions (including defects and background texture).

[0034] Differentiated filtering schemes are adopted to address the characteristics of the two types of regions, maximizing the preservation of defect edge details while suppressing reflections: Specular reflection area: Guided filtering is selected as the suppression filtering method. This method can smooth the image while maintaining the edge structure, which is suitable for the noise reduction requirements of reflective areas. Filter kernel size: Set to about 0.5% of the shortest side length of the image. This can effectively cover scattered reflective points without excessively expanding the filtering range and causing the defect edges to become blurred. Intensity parameter design: The smoothing intensity weight of the guide filter is set to a high value (weight coefficient 0.85). The core logic is to strengthen the smoothing effect of the filter on the reflective area, quickly weaken the bright interference of specular reflection, and at the same time use the original image as the guide map to ensure that the filtering process does not destroy the outline of any weak defects that may exist in the area. Normal pixel area: Standard bilateral filtering is selected as the edge-preserving filtering method. This method achieves a balance between noise removal and edge preservation through the synergy of spatial distance weight and gray-level similarity weight. Spatial standard deviation: set to 1.5 to control the influence range of neighboring pixels during filtering, avoiding excessive smoothing that could lead to the loss of defect details; Color range standard deviation: set to 20. Based on the gray-level difference between defects and the background within the normal area, when the gray-level difference between neighboring pixels is less than 20 (background texture), a high smoothing weight is assigned; when the gray-level difference is greater than 20 (defect edge), a low smoothing weight is assigned, thereby firmly locking the defect edge while removing background noise.

[0035] Regional filtering: For the marked specular reflection area, guided filtering is performed according to the set parameters to quickly suppress the reflective highlights and bring the area brightness back to the normal range; for the normal pixel area, bilateral filtering is performed to remove slight noise but retain the defective grayscale gradient and edge contour. Boundary transition processing: At the boundary between the specular reflection area and the normal area, a gradual filtering weight strategy is adopted - from the reflective area to the normal area, the guiding filter weight gradually decreases and the bilateral filter weight gradually increases, so as to avoid obvious boundary traces after filtering the two types of areas and ensure that the overall image transition is natural.

[0036] After filtering, the overexposure in the specular reflection area completely disappeared, and the brightness became consistent with the surrounding normal area. Meanwhile, the edges of defects such as scratches and indentations were clearly discernible, without blurring or distortion. Actual measurements showed that the standard deviation of brightness in the reflective area decreased from 42 before processing to 18, effectively resolving the contradiction between "reflection suppression and detail preservation," thus laying a high-quality image foundation for subsequent feature extraction and defect detection.

[0037] Specifically, the improved YOLO detection network is configured to use dynamically generated anchor boxes, the size of which is determined based on the distribution pattern of defect sizes in the multi-scale fused feature map, and its aspect ratio is optimized based on the clustering results of historical defect annotation data.

[0038] This embodiment uses four types of target defects (deformation, scratches, dirt, and indentations) on highly reflective metal surfaces as detection objects. Based on the training process of the improved YOLO detection network, it details the generation and optimization of dynamic anchor frames: Constructing a training dataset: Collect 10,000 images of highly reflective metal surfaces under different working conditions (fluctuating illumination, uneven reflectivity), including micro-scratches (minimum size approximately 0.1 mm), medium-sized dirt / indentations (size 0.1-1 mm), and large deformations (maximum size exceeding 5 mm), etc. All images were annotated according to industrial inspection standards, resulting in 86,000 real defect annotation boxes (annotation box format is [x1, y1, x2, y2], corresponding to the defect boundary coordinates). Data preprocessing: Extract the width (w) and height (h) parameters of all real bounding boxes, remove abnormal bounding boxes (such as incorrect bounding boxes with aspect ratios >10 or <0.1), and finally retain the width and height data of 85,200 valid bounding boxes as input samples for cluster analysis.

[0039] The K-means++ algorithm is used for clustering (compared to the traditional K-means, its cluster center initialization is more uniform, avoiding local optima). The specific steps are as follows: Initialize cluster centers: From 85,200 valid width and height samples, randomly select 1 sample as the first cluster center; then calculate the distance between each remaining sample and the selected cluster center, and select the next cluster center according to the distance probability weight. Repeat this process until a preset number of initial cluster centers are selected. Distance measurement method: IoU distance (Intersection over Union distance) is used as the standard for judging the similarity between samples -- the closer the IoU distance between the width and height (w1,h1) and (w2,h2) of two bounding boxes, the more similar their size and shape are, and they are classified into the same class during clustering. This method can accurately match the adaptation logic of anchor boxes and defects in target detection, which is better than Euclidean distance. Iterative clustering: All width and height samples are assigned to the nearest cluster center to form initial clusters; the mean width and height of all samples in each cluster are calculated and updated as new cluster centers; the "sample assignment - center update" steps are repeated until the cluster center positions are stable (the center offset between two adjacent iterations is <0.01), and the clustering converges; Cluster center number K selection: The optimal K value is determined by the "elbow method" -- calculate the clustering error (the sum of the IoU distances of all samples to their respective cluster centers) corresponding to different K values ​​(K=3~12). When K increases from 3 to 9, the clustering error decreases rapidly; when K>9, the rate of error decrease tends to level off ("elbow point" appears). Therefore, the optimal number of cluster centers is determined to be K=9, which generates 9 basic anchor boxes.

[0040] Based on the K-means++ clustering results, the aspect ratio of the anchor frames was screened and optimized, resulting in a set of nine dynamic anchor frames adapted to four types of defects. These are categorized into three levels—large, medium, and small—according to the detection scale. The specific clustering results and adaptation logic are shown in the table below: Training phase: The above 9 optimized dynamic anchor boxes are embedded into the detection head of the improved YOLO detection network. During the network training process, bounding box regression and classification loss are calculated based on the IoU matching results between the anchor boxes and the ground truth bounding boxes. The network parameters are continuously optimized through backpropagation so that the network can adapt to the size and shape features of the set of anchor boxes. Inference phase: After training, the network uses the same set of dynamic anchor boxes for defect detection. For different levels of the multi-scale fused feature map (shallow layers correspond to large-scale defects, and deep layers correspond to small-scale defects), anchor boxes of the corresponding level are assigned (large anchor boxes match shallow feature maps, and small anchor boxes match deep feature maps). There is no need to regenerate anchor boxes, which ensures real-time detection. At the same time, the high adaptability between anchor boxes and defects improves localization accuracy and classification accuracy.

[0041] The dynamic anchor frame generated in this embodiment is based entirely on the actual size distribution and morphological characteristics of highly reflective metal defects. Compared with the fixed anchor frame of traditional YOLO, the matching degree of the four types of target defects is greatly improved, effectively solving the problem of poor anchor frame adaptability in multi-scale defect detection.

[0042] Specifically, the attention mechanism module includes a channel attention submodule and a spatial attention submodule.

[0043] Specifically, the channel attention submodule generates channel weights by aggregating the spatial information of the feature map; the spatial attention submodule generates spatial weights by aggregating the channel information of the feature map.

[0044] Specifically, the channel attention submodule is a dual-pooling fusion channel attention module, which includes: performing global pooling and local pooling on the input feature map respectively to obtain global features and local features; and fusion of the two to calculate channel weights through a gating mechanism.

[0045] Specifically, the backbone feature extraction network is an improved deep convolutional network with embedded lightweight convolutional structures and residual connection structures; wherein, the lightweight convolutional structure can adaptively select the convolution operation type according to the statistical characteristics or gradient characteristics of the pixel values ​​of the input image region.

[0046] This embodiment describes an improved deep convolutional network (based on an improved CSPDarknet backbone network) for detecting defects on highly reflective metal surfaces. It details the adaptive logic implementation process of dynamically switchable convolution. This lightweight convolutional structure works synergistically with the residual connection structure to ensure the integrity of defect feature extraction while also meeting the real-time requirements of industrial inspection.

[0047] The backbone structure of the improved deep convolutional network consists of five feature extraction stages, each composed of a "dynamically switchable convolutional module + residual connection module". The dynamically switchable convolutional module is the core lightweight structure, responsible for adaptively selecting the convolution method based on the reflectivity of the input image region. The residual connection module spans the dynamically switchable convolutional module, enhancing the transfer of shallow defect details to the deep network, avoiding the gradient vanishing problem, and ensuring that weak features such as small scratches and subtle indentations are not lost.

[0048] (a) Selection of specific indicators for pixel value statistical characteristics In this embodiment, "local region pixel value variance" is selected as the core indicator for measuring the uniformity of reflectivity in the input image region. The selection is based on the following criteria: highly reflective metal surfaces exhibit significant brightness fluctuations in reflective areas, with large local pixel value differences and correspondingly high variance values; while normal non-reflective areas (including defective areas) have relatively uniform brightness distribution and lower pixel value variance. This indicator can accurately distinguish between highly reflective interference areas and effective defect feature areas.

[0049] Calculation method: When the dynamically switchable convolution module processes the input feature map, the input feature map is first divided into local receptive fields of 3×3 size (matching the size of the subsequent convolution kernel to ensure feature correlation). For each 3×3 local region, the variance of all pixel values ​​in the region is calculated, which is used as the quantification result of the reflectivity uniformity of the region.

[0050] (II) Basis and range of values ​​for determining the switching threshold The determination of the switching threshold is based on the statistical analysis of the training dataset for high reflectivity metal defect detection. The specific process is as follows: collect 10,000 images of high reflectivity metal surfaces covering different reflectivity intensities (weak reflectivity, medium reflectivity, and strong reflectivity), extract the pixel value variance of the 3×3 local region in the feature map of all images, and statistically obtain the variance distribution range of 0~120.

[0051] By analyzing the correspondence between variance and region type: when variance > 35, more than 90% of the region is a high-reflectivity interference region; when variance ≤ 35, nearly 90% of the region is a normal non-reflective region (including defective regions). Therefore, the switching threshold θ = 35 is determined, and the value range can be fine-tuned according to the reflectivity of the actual metal material (such as stainless steel, aluminum alloy), with a fine-tuning range of 32~38.

[0052] (III) Decision rules for adaptive selection of convolution operations The dynamically switchable convolution module has two built-in convolution operation types: standard 3×3 convolution (emphasizing the completeness of feature extraction) and depthwise separable 3×3 convolution (emphasizing lightweight design and speed improvement). The specific switching logic is as follows: The dynamically switchable convolution module receives the output feature map from the previous stage and calculates the pixel value variance for each 3×3 local region of the feature map. The calculated local variance is compared with a preset threshold θ=35: if the local variance > 35, the region is determined to be a high-reflectivity interference region, and a standard 3×3 convolution is selected for processing -- the standard convolution can fully capture the weak defect features in the region (avoiding feature loss due to reflectivity interference), ensuring the integrity of defect feature extraction; if the local variance ≤ 35, the region is determined to be a normal non-reflective region (including defective regions), and a depthwise separable 3×3 convolution is selected for processing -- the depthwise separable convolution, through the combination of "depth convolution + point convolution", reduces most of the computational load while ensuring the feature extraction effect, and greatly improves the network running speed; After switching convolution operations, the residual connection module fuses the features output by the current convolution with the input features of the previous stage to enhance feature transfer, and finally outputs the feature map of this stage to the next feature extraction stage.

[0053] In practical applications of surface defect detection for high-reflectivity stainless steel plates, the workflow of dynamically switchable convolution is as follows: 1. The preprocessed image is input into the improved backbone network. The dynamically switchable convolutional module in the first feature extraction stage first performs local variance calculation on the initial feature map corresponding to the input image. 2. For the highly reflective edge beveled area in the image, the local variance calculation result is 42 (>35). The module automatically switches to standard 3×3 convolution to accurately extract the possible micro-scratches in this area. 3. For flat areas with weak reflection in the image (including indentation defects), the local variance calculation result is 28 (≤35). The module is switched to depthwise separable 3×3 convolution to quickly complete feature extraction and reduce computational load. 4. The features from each stage are fused through residual connections and then output to the subsequent attention mechanism module and multi-scale feature fusion network.

[0054] Actual test results show that after adopting this dynamic switchable convolutional structure, the network reduces the overall computational load by more than 60% while maintaining the accuracy of defect feature extraction, and improves the processing speed of single-frame images, fully meeting the real-time inspection needs of industrial production lines. At the same time, the defect miss rate in highly reflective areas is reduced by nearly four times compared with the fixed convolutional structure, effectively adapting to the complex inspection scenarios of highly reflective metal surfaces.

[0055] Specifically, the multi-scale feature fusion network adopts a lightweight structure, which includes: channel optimization of feature maps at each scale through GSConv convolutional layers, and bidirectional fusion of cross-scale features through an FF-Slim-Neck structure; wherein, the FF-Slim-Neck structure has an embedded adaptive feature selection gate, which dynamically determines the fusion path and transmission ratio of features at each scale according to the sparsity and response intensity of the output features of GSConv.

[0056] This embodiment describes in detail the working mechanism of the adaptive feature selection gate embedded in the FF-Slim-Neck structure, based on a multi-scale feature fusion network for detecting defects on highly reflective metal surfaces. After channel optimization of feature maps at each scale through GSConv convolutional layers, the adaptive feature selection gate dynamically adjusts the fusion path and propagation ratio, achieving efficient aggregation of multi-scale defect features such as micro-scratches, medium-sized dirt, and large deformations, while balancing detection accuracy and real-time performance.

[0057] The multi-scale feature fusion network in this embodiment adopts a serial architecture of "GSConv convolutional layer + adaptive feature selection gate + FF-Slim-Neck main structure", and the specific process is as follows: 1. Input Features: Receive three feature maps of different scales from the improved backbone network: shallow feature map (corresponding to large-scale defects, such as large deformations), medium-scale feature map (corresponding to medium-sized defects, such as dirt and indentations), and deep feature map (corresponding to micro-defects, such as minor scratches). 2. Channel optimization: The GSConv convolutional layer is used to compress channels and filter key information of the above three scale feature maps. While reducing redundant channels (compression ratio 2:1), the core features related to defects are retained, and three optimized scale feature maps are output. 3. Dynamic gating: The optimized feature maps at three scales are input into an adaptive feature selection gate, which dynamically determines the fusion path and transmission ratio of features at each scale based on the sparsity of features and response intensity. 4. Bidirectional fusion: The feature map after gating and adjustment is input into the main structure of FF-Slim-Neck, and deep fusion is completed through bidirectional transmission paths from top to bottom and from bottom to top, and finally the fused feature map covering defects of the whole scale is output.

[0058] (a) Quantitative definition of sparsity and response intensity The core inputs of the adaptive feature selection gate are the "sparseness" and "response intensity" of the GSConv output feature map. Both are quantized in an intuitive and easy-to-understand way, requiring no complex calculations. The specific definitions are as follows: Sparsity Quantization: The "proportion of non-zero elements in the feature map" is used as a sparsity metric. It is defined as: for each scale feature map output by GSConv, the ratio of the number of non-zero pixels in the map to the total number of pixels, denoted as S (range 0~1). Core logic: Defect features of highly reflective metal surfaces typically appear as local non-zero activations (sparse distribution) in the feature map. If the S value is low (≤0.3), it indicates strong feature sparsity, likely representing effective defect features; if the S value is high (>0.3), it indicates dense feature distribution, potentially containing redundant information caused by reflective interference.

[0059] Response intensity quantization: The "average activation value of the feature map" is used as the metric for response intensity. It is defined as follows: for each scale feature map output by GSConv, the average value of all non-zero pixel values ​​is calculated and denoted as R (ranging from 0 to 1, after normalization). Core logic: Effective defect features have a higher activation level in the network, corresponding to a larger R value; reflective interference or background textures have a lower activation level, corresponding to a smaller R value.

[0060] Quantization calculation range: To ensure feature correlation, the sparsity S and response intensity R are calculated in units of the 3×3 local receptive field of the feature map. That is, the S and R values ​​of each 3×3 region are calculated for each region, and then the global S and R values ​​of the entire feature map are summed to obtain the decision basis of the feature selection gate.

[0061] (II) Structural Implementation of Adaptive Feature Selection Gate The adaptive feature selection gate in this embodiment is implemented using a "lightweight fully connected network + activation function". It is a lightweight module with learnable parameters. The specific structure and input / output definitions are as follows: The gate structure consists of two fully connected layers (16 neurons in the hidden layer and 3 neurons in the output layer) and one sigmoid activation function. The hidden layer is responsible for feature fusion of the input quantized metrics, the output layer generates the transfer weights for features at each scale, and the sigmoid activation function normalizes the output weights to the 0-1 range. Input: Global sparsity S values ​​(S1, S2, S3, corresponding to shallow, medium, and deep feature maps respectively) and global response intensity R values ​​(R1, R2, R3) for each of the three scale feature maps, for a total of six quantization parameters; Output: Three weight values ​​(W1, W2, W3) in the range of 0 to 1, corresponding to the transmission ratio of shallow, medium, and deep feature maps, respectively. The larger the weight value, the higher the proportion of the corresponding scale feature in the fusion process, and the more complete the feature information is transmitted.

[0062] (III) Decision-making process for dynamic fusion path and transmission ratio The adaptive feature selection gate dynamically determines the fusion path and transmission ratio through a four-step decision-making process: "quantitative index input → lightweight network computation → weight output → path adjustment". The specific process is as follows: Step 1: Input the metrics. Input the six quantization parameters (S1, S2, S3 and R1, R2, R3) corresponding to the three scale feature maps output by GSConv into the lightweight fully connected network of the adaptive feature selection gate; Step 2: Weight Calculation. The lightweight fully connected network performs linear transformation and feature fusion on the 6 input parameters. After processing by the Sigmoid activation function, it outputs 3 transit weights W1, W2, and W3 (for example, output W1=0.6, W2=0.3, W3=0.1). Step 3: Path Selection. The fusion path is dynamically selected based on the magnitude of the output weights. If W1 is the largest (corresponding to shallow large-scale features): the direct transmission path of "shallow to middle layer" in FF-Slim-Neck is activated first to strengthen the transmission of large-scale defect features. If W3 is the largest (corresponding to deep micro-features): the direct transmission path from deep to middle layer is activated first to strengthen the transmission of micro-features. If W2 is the largest (corresponding to medium-sized features in the middle layer): activate the bidirectional transmission of the entire path from "shallow to medium to deep" to achieve balanced fusion of features at all scales; Step 4: Proportion Adjustment. The output weights W1, W2, and W3 are multiplied element-wise with the corresponding shallow, medium, and deep feature maps, respectively, to adjust the transfer proportion. For example, W1=0.6 means that 60% of the shallow feature map is transferred to the subsequent fusion structure, and W3=0.1 means that 10% of the deep feature map is transferred, ensuring that the high-weighted effective features dominate the fusion process.

[0063] Taking the detection scenario of a high-reflectivity stainless steel plate surface simultaneously exhibiting large deformations, medium-sized dirt, and micro-scratches as an example, the actual operation process of the adaptive feature selection door is as follows: 1. The three scale feature maps output by GSConv are quantized and calculated to obtain: shallow feature map (large deformation) S1=0.25, R1=0.8 (strong sparsity, high response intensity); middle feature map (medium dirt) S2=0.4, R2=0.5 (moderate sparsity, medium response intensity); deep feature map (micro-scratches) S3=0.2, R3=0.3 (strong sparsity, low response intensity). 2. Six quantization parameters are input to the adaptive feature selection gate, and after computation by a lightweight fully connected network, the output weights are W1=0.55, W2=0.3, and W3=0.15. 3. Since W1 is the largest, the gate structure prioritizes activating the direct transmission path from the shallow layer to the middle layer, while multiplying W1, W2, and W3 by their respective feature maps to complete the proportional control. 4. The adjusted feature map is input into the FF-Slim-Neck main structure to complete bidirectional fusion, and the final output is the fused feature map.

[0064] Real-world testing results show that the adaptive feature selection gate significantly improves the detection accuracy of the multi-scale feature fusion network for large deformations and greatly reduces the false negative rate for micro-scratches. At the same time, by reducing the transmission and calculation of redundant features through weight adjustment, the overall computational load of the network is effectively reduced, and the processing speed of a single frame image is improved, fully meeting the needs of real-time detection in industrial production lines.

[0065] Specifically, the non-maximum suppression process employs an adaptive threshold adjustment mechanism, and the adjustment of the adaptive threshold is based on at least one of the following: the size of the prediction box, the distribution density, and the category attribute.

[0066] Specifically, the morphological closing operation processing uses adaptive structuring elements, and the shape and specifications of the adaptive structuring elements are selected from a preset multi-scale structuring element library based on the morphological features of the defect region.

[0067] This embodiment details the post-processing steps for detecting defects on highly reflective metal surfaces, explaining in detail the configuration logic and matching selection process of adaptive structural elements in morphological closing operations. This processing targets the defect region (including scratches, indentations, dirt, deformation, etc.) corresponding to the initial predicted bounding box output by the improved YOLO network. By pre-setting a multi-scale structural element library and dynamically matching and adapting elements, it achieves the filling of small voids inside defects and the repair of edge fractures. Simultaneously, it avoids contour distortion caused by mismatch between structural elements and defect morphology, providing accurate basic data for subsequent connected component labeling and bounding box merging.

[0068] After preprocessing and network detection, defects on highly reflective metal surfaces are prone to subtle defects in the predicted bounding box area due to reflection interference and image noise. These defects include minute cavities of 1-2 pixels within micro-scratches, localized breaks at the edges of indentations, and irregular contours in dirty areas. Morphological closing operations (dilation followed by erosion) can effectively address these issues, but traditional fixed structural elements struggle to adapt to multi-scale and multi-morphological defects—small elements cannot fill large defect cavities, and large elements can blur the contours of small defects. Therefore, this embodiment employs an adaptive structural element strategy to achieve "defect morphology-adaptive" closing operation processing.

[0069] Based on the size range and morphological characteristics of common defects on highly reflective metal surfaces, a multi-scale, multi-morphological structural element library is pre-designed. Elements in the library are stored in categories according to "morphological type + specification parameters," as shown in the table below: The design of elements in the library is based on the following: by statistically analyzing the defect size and shape of 10,000 images of highly reflective metal defects, the core specification range is determined as follows: more than 90% of micro-defects (≤0.5mm) correspond to a 3×3~5×5 pixel range, medium-sized defects (0.5-5mm) correspond to a 5×5~7×7 pixel range, and large defects (>5mm) correspond to a 7×7~9×9 pixel range. The linear element angles cover the extension direction of common scratches (horizontal, vertical, and diagonal).

[0070] The core logic of the matching selection is as follows: First, analyze the "size features" and "shape complexity" of the defect region corresponding to the preliminary predicted bounding box, and then match the most suitable element from the multi-scale structural element library. The specific rules and execution steps are as follows: (I) Defect Area Feature Analysis Size feature determination: Extract the width (w) and height (h) of the preliminary predicted bounding box, calculate the actual pixel size of the defect area (based on the coverage of the predicted bounding box), and classify it into three categories according to size: Small defects: size ≤ 5×5 pixels (corresponding to actual defects ≤ 0.5mm); Medium-sized defects: 5×5~7×7 pixels (corresponding to actual defects of 0.5-5mm); Large defects: size > 7×7 pixels (corresponding to actual defects > 5mm).

[0071] Shape complexity determination: The shape type is determined by the aspect ratio and edge regularity of the defect area. Near-circular / dot-shaped: aspect ratio w / h∈[0.8,1.2] (close to 1:1), with regular outlines of edge pixels; Slender type: aspect ratio w / h < 0.3 or w / h > 3 (length is much greater than width), and the extension direction of edge pixels is clear; Irregular block shape: Shapes other than the two types mentioned above, with irregular outlines of edge pixels.

[0072] (II) Dynamic Matching Process Step 1: Feature Extraction. For each preliminary predicted bounding box, extract the corresponding defect region image and calculate the region's size (pixel range), aspect ratio, and edge continuity. Step 2: Shape Matching. Match the element type based on the shape complexity determination result. Near-circular / dot-like defects: match circular structural elements; Slender defects: Match linear structural elements, and determine the angle according to the direction of defect extension (e.g., horizontally extending scratches match 0° linear elements, and 45° oblique scratches match 45° linear elements). Irregular block defects: match square structural elements.

[0073] Step 3: Scale Matching. Match element specifications based on the size characteristics determination results. Small defects: Match small-sized elements (circle r=1, linear length 3 pixels, square 3×3 pixels); Medium-sized defects: Match medium-sized elements (circular r=2, linear length 5 pixels, square 5×5~7×7 pixels); Large defects: Match large-sized elements (circular r=3, square 7×7~9×9 pixels).

[0074] (a) Example of the operation process Taking the "horizontal fine scratches" and "medium-sized irregular indentations" on the surface of high-reflective stainless steel sheets as examples, the specific operating procedure is as follows: 1. Preliminary prediction box output: The network detected horizontal thin and long scratches (predicted box size 3×15 pixels, aspect ratio 0.2<0.3, judged as thin and long) and medium irregular indentations (predicted box size 6×6 pixels, aspect ratio 1.0, edge continuity rate more than 60%, judged as irregular block). 2. Element matching: Thin scratches match "5-pixel-long, 0° (horizontal) linear structural elements", medium indentations match "5×5 square structural elements"; 3. Closing operation: Perform a horizontal linear element closing operation on the scratched area to fill the internal 1-pixel hole and repair the local edge break; perform a square element closing operation on the indentation area to fill the 3-pixel hole. 4. Boundary Smoothing: Perform a 1-pixel-width smoothing process on the edges of the defective area after the closing operation to avoid residual sharp corners of structural elements and ensure a natural outline.

[0075] Specifically, merging multiple detection boxes belonging to the same connected domain includes: first, verifying and removing outlier boxes belonging to the same connected domain according to a preset geometric consistency rule; and then performing weighted fusion based on the spatial location, category, and confidence level of the multiple detection boxes.

[0076] This embodiment, based on the post-processing stage of high-reflectivity metal surface defect detection, details the quantification criteria for geometric consistency rules, outlier removal logic, and subsequent weighted fusion process during the merging of detection frames within the same connected domain. After high-reflectivity metal surface defects are detected by the improved YOLO network, the same defect (such as large deformation or long strip scratches) may be marked by multiple overlapping or adjacent detection frames. Some detection frames may have geometric anomalies (such as aspect ratio deviation or angle skew) due to reflective interference. Outliers need to be removed through consistency verification, and then weighted fusion is performed to obtain an accurate single defect detection frame, providing a reliable basis for the final defect determination.

[0077] This embodiment selects "detection frame aspect ratio" and "rotation angle" as core geometric parameters (both can intuitively reflect the morphological characteristics of defects, and are simple to calculate and adaptable to industrial real-time requirements). It clarifies the calculation method for group characteristics and the threshold for judging abnormal deviations, with specific quantitative standards as follows: (a) Calculation of group characteristics For all bounding boxes within the same connected component, the "group feature baseline" is defined as the "median" of the geometric parameters of that group of bounding boxes (compared to the mean, the median is less susceptible to extreme values ​​and is suitable for scenarios with a small number of outliers). The specific calculation steps are as follows: Extract two core parameters for all detection boxes within the same connected component: aspect ratio (the ratio of the width to the height of the detection box, denoted as AR) and rotation angle (the angle between the long side of the detection box and the horizontal direction of the image, denoted as θ). Sort all AR values ​​of the detection boxes in ascending order and take the middle value as the "group aspect ratio reference AR_med"; similarly, sort all θ values ​​and take the middle value as the "group rotation angle reference θ_med". Calculate the "standard deviation σ" of the population parameters (which measures the dispersion of the population parameters): Calculate the deviation of all detection box AR values ​​from AR_med and the deviation of θ values ​​from θ_med, and calculate the standard deviation of the two types of deviations, denoted as σ_AR and σ_θ, as a reference for judging "abnormal deviation".

[0078] (ii) Threshold for judging abnormal deviation Based on the accuracy requirements of industrial testing scenarios and statistical analysis of a large amount of experimental data, a unified threshold for abnormal deviations is set: Aspect Ratio Abnormal Threshold: If the absolute value of the difference between the AR value of a detection box and AR_med, |AR_i - AR_med|, is greater than 2×σ_AR, then the aspect ratio of the detection box is determined to be abnormal. Rotation angle abnormality threshold: If the absolute value of the difference between the θ value of a detection box and θ_med, |θ_i - θ_med|, is greater than 15° (15° is a reasonable threshold determined by experiments, covering the angle fluctuation range of normal detection boxes), then the rotation angle of the detection box is determined to be abnormal. Outlier box determination: Detection boxes that meet any of the above abnormal conditions are considered outliers; only when both parameters meet the consistency requirements will the detection box be retained for subsequent fusion.

[0079] Taking the merging of detection frames for a "large deformation defect" on the surface of a high-reflectivity stainless steel plate as an example, the complete processing flow is explained in detail. After network detection, there are 5 overlapping preliminary prediction frames within the same connected domain for this defect: (a) Step 1: Connected component partitioning Connected domains are divided based on the spatial positional relationship of the detection boxes: the spatial overlap and center distance of all preliminary prediction boxes are calculated. If the overlap area of ​​two detection boxes is ≥30%, or the center distance is ≤1 / 2 of the average side length of the detection boxes, they are determined to be "adjacent detection boxes". Adjacent detection boxes are grouped into the same connected domain, and finally a "large deformation defect connected domain" containing 5 detection boxes is obtained.

[0080] (II) Step 2: Geometric parameter extraction The geometric parameters of the five detection boxes within this connected component were extracted, and the results are shown in the table below (the parameters were obtained from actual detection annotations): (III) Step 3: Geometric consistency verification and outlier box removal Calculate the baseline and standard deviation of the group characteristics: Sort the AR values ​​of the 5 detection boxes (2.2, 2.3, 2.4, 2.5, 5.1), AR_med=2.4; calculate the deviations of the AR values ​​from AR_med, which are 0.2, 0.1, 2.7, 0, 0.2, respectively, σ_AR=0.98; sort the θ values ​​(8, 9, 10, 11, 12), θ_med=10°, σ_θ=1.4°; Anomaly detection: The AR value deviation of detection box 3 is 2.7 > 2 × 0.98 (1.96), which meets the aspect ratio anomaly condition and is determined to be an outlier box; the AR deviation and θ deviation of the other 4 detection boxes all meet the threshold requirements and are retained. Outlier box removal: Remove detection box 3 from the connected component, and the remaining 4 detection boxes participate in the subsequent weighted fusion.

[0081] (iv) Step 4: Weighted fusion based on spatial location, category and confidence level Weighting: The confidence level of the detection box is used as the core weight (the higher the confidence level, the greater the weight). At the same time, the spatial centrality of the detection box is combined (the closer to the center of the connected component, the more weight is added by 0.05). The final weight = confidence level × (1 + centrality gain). Parameter fusion: The position coordinates of the four retained detection boxes (top left x1, y1, bottom right x2, y2) are weighted and averaged to obtain the final coordinates of the merged detection boxes; the category is based on the consistent category of all retained detection boxes (all are "large deformation"); the final confidence is the weighted average of the confidence scores of the four detection boxes. Output: A single, accurate large deformation defect detection box is obtained, whose position can completely cover the actual defect area, and the confidence level is improved to 0.93 (after removing low-confidence outliers).

[0082] Real-world data validation: On a dataset of highly reflective metal defects containing 1000 connected components with multiple detection boxes, the geometric consistency rule and outlier removal strategy of this embodiment achieved an outlier recognition accuracy of over 90%, effectively avoiding interference from outliers on the fusion results. Compared with a fusion scheme that did not perform outlier removal, the localization error of the merged detection boxes was reduced by about 40%, and the defect area coverage was greatly improved. At the same time, because low-confidence outliers were removed, the confidence of the final detection results was improved, significantly reducing the probability of false positive defects and providing a reliable guarantee for high-precision defect detection.

[0083] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention in any way. Although the present invention has been disclosed above with reference to preferred embodiments, it is not intended to limit the present invention. Any person skilled in the art can make some modifications or alterations to the above-disclosed technical content to create equivalent embodiments without departing from the scope of the present invention. Any simple modifications, equivalent changes and alterations made to the above embodiments based on the technical essence of the present invention without departing from the scope of the present invention shall still fall within the scope of the present invention.

Claims

1. A machine vision algorithm for determining defects on highly reflective metal surfaces, characterized in that, include: S1: Obtain the original image of the highly reflective metal surface, perform adaptive contrast enhancement processing based on local brightness characteristics on the original image, and then perform filtering processing to suppress specular reflection components to obtain a preprocessed image. S2: The preprocessed image is input into an improved YOLO detection network adapted for detecting defects on highly reflective surfaces. Multi-scale features are extracted and fused through a backbone feature extraction network and a multi-scale feature fusion network, and a preliminary prediction box containing location, category, and confidence is output. The backbone feature extraction network is embedded with an attention mechanism module to enhance defect-related features and suppress background features. The multi-scale feature fusion network adopts a lightweight structure to fuse features of different scales from the backbone network. S3: Post-process the preliminary predicted boxes: perform non-maximum suppression on the predicted boxes output by the detection heads at different scales, and perform a weighted average of the class confidence of the overlapping boxes; perform morphological closing operation on the retained predicted boxes, perform connected component labeling, and merge multiple detection boxes belonging to the same connected component. S4: Output the defect category, location coordinates, and confidence level corresponding to the merged detection box.

2. The machine vision algorithm according to claim 1, characterized in that, The adaptive contrast enhancement processing based on local brightness characteristics described in S1 specifically includes: dividing the original image into multiple local regions and calculating the brightness statistical characteristics of each region; determining the adaptive contrast enhancement parameters of each region based on the difference between the brightness statistical characteristics of each region and the global brightness statistical characteristics; and stitching the images together after adjusting the contrast of each region to obtain an intermediate image.

3. The machine vision algorithm according to claim 1, characterized in that, The filtering process for suppressing specular reflection components described in S1 specifically includes: identifying pixel regions with specular reflection characteristics and normal pixel regions in the original image; applying different filtering weights to the specular reflection regions and normal regions respectively, and preserving the edge details of defects while suppressing specular reflection.

4. The machine vision algorithm according to claim 1, characterized in that, The improved YOLO detection network described in S2 is configured to use dynamically generated anchor boxes, the size of which is determined based on the distribution of defect sizes in the multi-scale fused feature map, and its aspect ratio is optimized based on the clustering results of historical defect annotation data.

5. The machine vision algorithm according to claim 1, characterized in that, The attention mechanism module described in S2 includes a channel attention submodule and a spatial attention submodule.

6. The machine vision algorithm according to claim 5, characterized in that, The channel attention submodule generates channel weights by aggregating the spatial information of the feature map; the spatial attention submodule generates spatial weights by aggregating the channel information of the feature map.

7. The machine vision algorithm according to claim 5, characterized in that, The channel attention submodule is a dual-pooling fusion channel attention module, which specifically includes: performing global pooling and local pooling on the input feature map to obtain global features and local features; fusing the two and calculating channel weights through a gating mechanism.

8. The machine vision algorithm according to claim 1, characterized in that, The backbone feature extraction network described in S2 is an improved deep convolutional network with embedded lightweight convolutional structures and residual connection structures; wherein, the lightweight convolutional structure can adaptively select the convolution operation type according to the statistical characteristics or gradient characteristics of the pixel values ​​of the input image region.

9. The machine vision algorithm according to claim 1, characterized in that, The multi-scale feature fusion network described in S2 adopts a lightweight structure, specifically including: channel optimization of feature maps at each scale through GSConv convolutional layers, and bidirectional fusion of cross-scale features through an FF-Slim-Neck structure; wherein, the FF-Slim-Neck structure has an embedded adaptive feature selection gate, which dynamically determines the fusion path and transmission ratio of features at each scale according to the sparsity and response intensity of the GSConv output features.

10. The machine vision algorithm according to claim 1, characterized in that, The non-maximum suppression processing described in S3 employs an adaptive threshold adjustment mechanism, the adjustment of which is based on at least one of the following: the size of the prediction box, the distribution density, and the category attribute.

11. The machine vision algorithm according to claim 1, characterized in that, The morphological closing operation processing described in S3 uses adaptive structuring elements. The shape and specifications of the adaptive structuring elements are selected from a preset multi-scale structuring element library based on the morphological features of the defect region.

12. The machine vision algorithm according to claim 1, characterized in that, The merging of multiple detection boxes belonging to the same connected region described in S3 specifically includes: first, verifying and removing outlier boxes belonging to the same connected region according to a preset geometric consistency rule; and then performing weighted fusion based on the spatial location, category, and confidence of multiple detection boxes.