Electronic component surface defect detection method based on YOLOv5 convolutional neural network
By using a YOLOv5 convolutional neural network-based method for detecting surface defects in electronic components, and by employing image grayscale histogram analysis and dynamic adjustment of normalization parameters based on weight graphs, the problem of low recognition rate for low-contrast defects is solved, achieving a more efficient defect detection effect.
Patent Information
- Application Number
- CN202511054576.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-30
- Publication Date
- 2025-11-18
AI Technical Summary
In the existing technology, the surface defect detection method of electronic components based on YOLOv5 convolutional neural network has a low recognition rate when facing low contrast defects caused by gray-scale differences, and cannot effectively improve the contrast of the defect area, resulting in insufficient recognition ability.
By acquiring raw image data of the surface of electronic components, the region with low local contrast is identified using image grayscale histogram analysis, and a corresponding weight map is generated. Based on the weight map, the normalization parameters of the image enhancement module are dynamically adjusted, including adaptive coefficients, spatial correlation analysis, and noise suppression. Finally, the adjusted parameters are used to enhance the image and input into the YOLOv5 model for defect detection.
It significantly improves the YOLOv5 model's ability to identify small or low-contrast defects, enhances detection accuracy and stability, improves image quality, and increases defect detection efficiency.
Smart Images

Figure CN120976130A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer vision, specifically to an electronic component surface defect detection method based on YOLOv5 convolutional neural network. BACKGROUND
[0002] The present application proposes an electronic component surface defect detection method based on YOLOv5 convolutional neural network, which can quickly identify and locate various defects on the surface of electronic components by utilizing the efficient target detection capability of YOLOv5, thereby improving the detection efficiency and accuracy; however, in view of the problem of low recognition rate of low-contrast defects on the surface of electronic components due to gray difference, it is urgent to dynamically regulate the normalization parameters in the image enhancement module to improve the contrast of the defect area, thereby enhancing the recognition ability of the model to subtle defects. SUMMARY
[0003] Therefore, the present application provides an electronic component surface defect detection method based on YOLOv5 convolutional neural network, which at least partially solves the problems existing in the prior art.
[0004] The electronic component surface defect detection method based on YOLOv5 convolutional neural network comprises:
[0005] Obtaining original image data of the surface of an electronic component;
[0006] Determining a region with low local contrast based on image gray histogram analysis and generating a corresponding weight map;
[0007] Dynamically adjusting the normalization parameters of the image enhancement module based on the weight map;
[0008] Enhancing the image using the adjusted normalization parameters and inputting the YOLOv5 model for defect detection.
[0009] Preferably, the step of determining a region with low local contrast based on image gray histogram analysis further comprises:
[0010] Obtaining gray histogram data of the image;
[0011] Counting the number of pixels in each gray interval and calculating the histogram gradient of the current gray interval;
[0012] If ΔI < I_threshold and (I_max - I_min) / I_avg < T_ratio, the low-contrast region is determined, wherein ΔI is the difference amplitude between adjacent gray scale intervals, I_threshold is a set threshold, I_max is the maximum gray scale value, I_min is the minimum gray scale value, and I_avg is the average gray scale value;
[0013] A weight map corresponding to the low-contrast region is generated.
[0014] Preferably, the dynamic adjustment of the normalization parameter of the image enhancement module based on the weight map further comprises:
[0015] The weight coefficient W of each low-contrast region is calculated as W = a*log(1+pixel_count / area_total);
[0016] An adaptive coefficient a is introduced to balance the influence of different regions;
[0017] The normalization factor β is calculated as β = β_base*W by combining the region weight and the overall histogram information;
[0018] The normalization parameter is linearly interpolated or nonlinearly mapped to form a new normalization parameter matrix.
[0019] Preferably, the image enhancement processing using the adjusted normalization parameter further comprises:
[0020] A dual-channel normalization algorithm is used to perform joint enhancement of the global and local images;
[0021] The brightness of each pixel in the image is weighted and compensated, wherein the compensation amount C = K*(W-W_min) / (W_max-W_min); wherein K is a gain coefficient, W is the weight value corresponding to the position, W_min is the minimum value of all region weights, and W_max is the maximum value;
[0022] The compensated image is input into an image preprocessing module to enhance local details;
[0023] The enhanced input image is finally generated and input into a YOLOv5 model.
[0024] Preferably, the normalization parameter in the image enhancement module includes a gamma correction parameter γ and a contrast stretching parameter μ, and the dynamic adjustment of the normalization parameter further comprises:
[0025] The maximum value I_max_local and the minimum value I_min_local of the image in each region are calculated according to the weight map;
[0026] Define local contrast C_local = (I_max_local - I_min_local) / (I_max_global - I_min_global), if C_local < T_contrast, then adjust parameter γ = γ_base * (C_local / T_contrast)^α, wherein T_contrast is a set contrast threshold, and α is an adaptive coefficient;
[0027] Define μ as proportional to the region weight, i.e. μ = μ_base + β * W, wherein β is an adjustment coefficient;
[0028] After parameter integration of all regions, the parameters are uniformly applied to the image.
[0029] Preferably, in the process of dynamically adjusting the normalization parameters of the image enhancement module based on the weight map, a spatial correlation analysis step is further included, which further comprises:
[0030] Calculate the entropy value E = Σ (p_i * log p_i) of each image block, wherein p_i is the proportion of gray scale frequency;
[0031] According to the spatial neighborhood information, evaluate the smoothness of the block, if E < E_threshold, then determine that it is a possible low-contrast region;
[0032] Assign a weighted influence factor θ = θ_base * exp (d / d_scale) to all regions, wherein d is the distance from the center of the region to the center of the image, and d_scale is a diffusion proportion constant;
[0033] According to the weight, entropy value, and spatial influence factor, obtain the final parameter change proportion.
[0034] Preferably, the image enhancement processing further includes a control mechanism for noise suppression, which further comprises:
[0035] Identify a region R_noise with relatively large noise based on a gray scale histogram;
[0036] Calculate the noise intensity N_strength = (σ_rolling_avg^2 - σ_static_avg^2) * K_n; wherein σ_rolling_avg is the variance in the rolling window, σ_static_avg is the variance of the global background, and K_n is an adjustment coefficient;
[0037] If N_strength > N_threshold, then reduce the enhancement multiple, specifically scale_factor = max (scale_base - K_n * N_strength, 5);
[0038] The final enhancement factor is adjusted twice by combining the weight W and the noise factor N_strenth.
[0039] Preferably, the image enhancement module also adds a multi-scale analysis mechanism, further comprising:
[0040] The image is decomposed into multiple scale image layers by Gaussian pyramid decomposition;
[0041] The local histogram and contrast C_level of each layer are calculated respectively;
[0042] The comprehensive weight W_total = W_local + β_log * log(s) is obtained by combining C_level and the corresponding scale s;
[0043] The final normalization factor is obtained by weighting and summarizing the information of all scales.
[0044] Preferably, the dynamic adjustment of the normalization parameter adopts a fuzzy logic controller (FLC) to optimize, further comprising:
[0045] The input variables include the current region weight W and the contrast C;
[0046] The output variable is defined as the change amount Δγ of the normalization parameter;
[0047] The fuzzy inference system rule base is constructed, for example: if W is high and C is low then Δγ is positive;
[0048] The input is fuzzy quantized and de-fuzzied to obtain the actual adjustment parameter γ_adj;
[0049] The historical parameter information is combined to optimize the final normalization adjustment value using the weighted average method.
[0050] Preferably, the dynamic adjustment process introduces a machine learning strategy to predict parameters based on a trained model from past samples, further comprising:
[0051] Collect historical defect image samples and their corresponding enhancement parameters as a training set;
[0052] Establish a feature vector X = [W_region, C_global, E_entropy, d_distance];
[0053] Use a regression model such as random forest or XGBoost to learn the mapping relationship from sample X to enhancement parameters γ and μ;
[0054] The values of γ and μ are predicted and adjusted in real time according to current image features at runtime, so that adaptive enhancement is realized.
[0055] The electronic component surface defect detection method based on the YOLOv5 convolutional neural network provided by the embodiments of the present disclosure includes: acquiring original image data of an electronic component surface; determining a region with low local contrast based on image gray histogram analysis, and generating a corresponding weight map; dynamically adjusting normalization parameters of an image enhancement module based on the weight map; performing image enhancement processing on the image by using the adjusted normalization parameters, and inputting the image into a YOLOv5 model for defect detection. Through the scheme of the embodiments of the present disclosure, how to control the normalization parameters of the image enhancement module according to the gray difference of the electronic component surface to solve the problem of low defect recognition rate of low contrast can be solved. BRIEF DESCRIPTION OF DRAWINGS
[0056] In order to more clearly illustrate the technical solutions of the exemplary embodiments of the embodiments of the present disclosure, the drawings needed in the embodiments will be briefly introduced as follows. It should be understood that the following drawings only show some embodiments of the present disclosure, and therefore should not be considered as a limitation on the scope. For those skilled in the art, other related drawings can also be obtained without creative labor on the basis of these drawings.
[0057] Figure 1 is a flowchart of the electronic component surface defect detection method based on the YOLOv5 convolutional neural network;
[0058] Figure 2 is a further flowchart for determining a region with low local contrast based on image gray histogram analysis;
[0059] Figure 3 is a further flowchart for dynamically adjusting normalization parameters of an image enhancement module based on a weight map;
[0060] Figure 4 is a further flowchart for image enhancement processing by using adjusted normalization parameters;
[0061] Figure 5 is a further flowchart for normalization parameters in the image enhancement module, including gamma correction parameters γ and contrast stretching parameters μ, wherein the dynamic adjustment of the normalization parameters is further illustrated;
[0062] Figure 6 is a further flowchart for dynamically adjusting normalization parameters of an image enhancement module based on a weight map, wherein a spatial correlation analysis step is further added;
[0063] Figure 7 is a further flowchart for image enhancement processing, which further includes a control mechanism for noise suppression;
[0064] Figure 8 is the image enhancement module also adds the multi-scale analysis mechanism, further flow chart;
[0065] Figure 9 is the dynamic adjustment normalization parameter mode adopts the fuzzy logic controller (FLC) to carry out optimization, further flow chart;
[0066] Figure 10 is the dynamic adjustment process introduces the machine learning strategy, based on the past sample training model parameter prediction, further flow chart. DETAILED DESCRIPTION
[0067] It should be noted that, in this article, such as the first and second relationship terms are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between the entities or operations. Moreover, the term "includes", "contains" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, article or equipment including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, method, article or equipment. Without more limitations, the element defined by the statement "includes a" does not exclude the presence of additional identical elements in the process, method, article or equipment including the element.
[0068] Next, with reference to the accompanying drawings, the electronic component surface defect detection method based on YOLOv5 convolutional neural network of the present application includes obtaining the original image data of the electronic component surface. First, the electronic component is photographed by a high-resolution industrial camera or image acquisition device to obtain the original image with defect information. These images usually contain multiple different regions, some of which have small gray value differences due to factors such as lighting conditions and material reflection, affecting subsequent defect recognition. In actual operation, the image will be stored in a common format (such as JPEG, PNG), and may be preprocessed to ensure that its size is consistent with the input requirements of the YOLOv5 model. For example, in one embodiment, a manufacturer uses a 12 million-pixel industrial camera to capture the surface image of a resistor for subsequent defect analysis.
[0069] Next, the low-contrast areas are determined based on image gray histogram analysis, and a corresponding weight map is generated. The core of this step is to evaluate the contrast of each pixel or sub-region by calculating the average gray difference of adjacent regions or the dispersion degree of the histogram, and to identify the parts with low contrast. Then, according to this information, a weight map is constructed for subsequent adjustment of the parameters of the image enhancement module. Specifically, histogram equalization, adaptive contrast enhancement and other algorithms are used to analyze the brightness and color difference of each region, and then different degrees of weight are given to the corresponding regions. For example, in one embodiment, for a capacitor surface with a silver coating, it is found that some areas have too concentrated gray distribution due to mirror reflection, resulting in insufficient contrast. At this time, these areas are located by gray histogram analysis and a corresponding weight map is created.
[0070] Next, the normalization parameters of the image enhancement module are dynamically adjusted based on the weight map. The key here is to associate the previous weight information with the parameters of the enhancement algorithm, so that the normalization function can adjust the parameters for different gray characteristic regions. For example, increase the enhancement coefficient for low-contrast areas, and appropriately reduce the coefficient for high-contrast areas to avoid over-amplifying the existing differences. At the same time, dynamic normalization strategies can be combined to adjust the mean and variance of image standardization in real time according to different image content. This control method can more finely enhance the visibility of local features without damaging the overall image quality. For example, in one embodiment, the system automatically adjusts the clipping threshold in histogram equalization according to the weight map, so that the originally dull micro scratches are highlighted.
[0071] Next, the image is enhanced using the adjusted normalization parameters and input into the YOLOv5 model for defect detection. After completing the dynamic adjustment of parameters, the image enhancement operation is performed to make the low-contrast areas in the original image clearer. Then, the processed image is input into the pre-trained YOLOv5 model, which uses its structural advantages to perform object detection and classification. The YOLOv5 model can recognize various types of defects such as cracks, gaps, and oxidation spots, and provide accurate positioning and classification results. In experiments, this method successfully improves the accuracy of micro-defect recognition, especially for electronic component detection with complex surfaces and susceptible to environmental light. For example, in one embodiment, the micro solder joints on the surface of a certain circuit board were tested, and the optimized image enhancement and YOLOv5 model cooperation made it achieve higher recognition rate in detecting low-contrast cracks, effectively improving product pass rate and quality control efficiency.
[0072] Next, the determination of the low local contrast area based on the image gray histogram analysis of the present application is further described. The acquisition of the gray histogram data of the image is a process of statistical distribution of the gray level of the input image. By dividing the pixel value into several intervals and counting the number of pixels in each interval, the overall brightness distribution of the image can be intuitively reflected. In electronic component detection, for example, in the image processing of the surface of a patch capacitor, this step can help to extract the gray feature difference between the background and the defect area. Counting the number of pixels in each gray interval and calculating the histogram gradient of the current gray interval is to measure the degree of change of the local image by analyzing the change rate between adjacent intervals, which helps to find the low contrast area. For example, in the image near the soldering point of the circuit board, low gray change may cause difficulty in recognizing the soldering point. The low contrast area is determined based on the following formula: if ΔI < I_threshold and (I_max - I_min) / I_avg < T_ratio, it is a low contrast area; where ΔI is the difference amplitude between adjacent gray intervals, I_threshold is a set threshold, usually ranging from 10 to 30, and the optimal value is set according to the actual image noise level, which is used to quantify the degree of gray change; I_max is the maximum gray value, ranging from 0 to 255, representing the brightest pixel value in the image; I_min is the minimum gray value, also ranging from 0 to 255, representing the darkest pixel value in the image; I_avg is the average gray value, representing the overall brightness level of the image. T_ratio is used to judge the proportion of the gray range to the average gray, and the common value range is 0.2 to 0.8, which means to avoid high or low brightness area being misjudged as low contrast area. The purpose of setting this formula is to consider the local pixel change and the overall brightness characteristics comprehensively, and to improve the recognition accuracy of the low contrast area. The generation of the weight map corresponding to the above low contrast area is to give higher weight value to these areas, so as to focus on them in the subsequent defect detection process. For example, in the identification of the slight scratch on the edge of the microchip, this step can enhance the recognition sensitivity of the model to this area and improve the detection accuracy.
[0073] Next, the dynamic adjustment of the normalization parameter of the image enhancement module based on the weight map of the present application is further described. First, the weight coefficient W = a * log(l + pixel_count / area_total) of each low-contrast region is calculated, where W represents the weight coefficient, a is an adaptive coefficient for balancing the influence of different regions, pixel_count represents the number of pixels in the low-contrast region, and area_total represents the area of the entire image. The formula smoothes the pixel count by log(l + pixel_count / area_total) to avoid instability caused by large values. The typical value range of a is 0.5 to 2, and the recommended value is 1 to maintain balance. For example, in electronic component surface detection, if a region has a large number of low-contrast pixels, the W value is large, indicating that the region needs to be enhanced.
[0074] An adaptive coefficient a is introduced to balance the influence of different regions. a is an adjustment parameter that can adjust the importance of the region for different types of defects. The larger a is, the more sensitive the weight coefficient is to small regional changes, which is suitable for situations that require accurate processing of small defects; a is too small and important information may be ignored. In one embodiment, assuming a is 1.2, the attention to small but critical defect regions can be improved.
[0075] Combining regional weight and overall histogram information, the normalization factor β = β_base * W is calculated, where β_base is the baseline normalization factor, W is obtained from the previous step, and β represents the final adjusted normalization factor. β_base is usually selected in the range of 0.8 to 1.2, and 1.0 is recommended to ensure that the basic normalization does not interfere with the original data distribution. Specifically, in an image of a circuit board containing uniform defect distribution, the β value is dynamically adjusted according to W to improve the visibility of low-contrast regions.
[0076] Linear interpolation or nonlinear mapping is performed on the normalization parameter to form a new normalization parameter matrix. This step applies β to each pixel of the image through mathematical methods to enhance the contrast of specific regions. For example, when linear interpolation is used, the weight coefficient is used to proportionally adjust each channel of the image, improving the recognition rate of critical regions and helping YOLOv5 to more accurately locate the defect region.
[0077] Next, the application of the adjusted normalization parameters for image enhancement processing is further described. First, a dual-channel normalization algorithm is used to enhance the image globally and locally. Dual-channel normalization improves image quality by considering both the overall contrast and local detail features of the image. One channel is responsible for global contrast adjustment, and the other channel optimizes local area brightness distribution. For example, in electronic component surface defect detection, if the component image has some areas that are too bright or too dark, the algorithm can enhance the overall recognizability.
[0078] Next, the brightness of each pixel in the image is weighted and compensated, where the compensation amount C = K * (W - W_min) / (W_max - W_min). Where K is a gain coefficient for adjusting the amplitude of brightness change; W is the weight value corresponding to the position, reflecting the importance of the local area; W_min and W_max are the minimum and maximum values of all region weights respectively. The formula normalizes the weight value to the range [0, 1], and then adjusts the final compensation strength through K. The preferred range of K is between 0.5 and 1.5, too large may cause image distortion, too small the effect is not obvious. In one embodiment, if the edge of a certain area is fuzzy, the weight W can be increased and a suitable K value can be selected to clearly highlight the edge.
[0079] Subsequently, the compensated image is input into the image preprocessing module to enhance the local details. The preprocessing process usually includes filtering, edge detection, etc. to further improve the visual quality. Specifically, for the tiny cracks or color differences in electronic component images, the enhanced image enables the detection model to more accurately identify these subtle features.
[0080] Finally, the enhanced input image is generated and input into the YOLOv5 model. Through this process, the image quality is improved, which helps to improve the accuracy and stability of the subsequent defect detection task.
[0081] Next, the normalization parameters in the image enhancement module of the application include gamma correction parameter γ and contrast stretching parameter μ, and the dynamic adjustment of the normalization parameters is further described. According to the weight map, the maximum value I_max_local and the minimum value I_min_local of the image in each region are calculated, which are used to quantify the brightness range in the region. I_max_local represents the gray value of the brightest pixel in the local region, and I_min_local represents the gray value of the darkest pixel, usually the value of I_max_local and I_min_local is between 0 and 255. In this way, the visual features of different parts of the image can be accurately identified. For example, in electronic component images, some areas may have uneven brightness due to reflection or shadows, and this step helps the subsequent adaptive adjustment of parameters.
[0082] The local contrast C_local is defined as (I_max_local - I_min_local) / (I_max_global - I_min_global), where I_max_global and I_min_global represent the maximum and minimum gray value of the whole image, respectively. This ratio measures the intensity of the local contrast relative to the global. If C_local < T_contrast, it means that the current region has too low contrast and needs to be adjusted. T_contrast is a set contrast threshold, typically taking a value between 0.3 and 0.6. α is an adaptive coefficient, usually set between 1.0 and 2.0, to ensure the adjustment amplitude is appropriate. At this time, γ will dynamically change with the increase of local contrast, making the brightness more uniform and the details more obvious. For example, when detecting metal surface oxidation spots, this step helps to highlight subtle differences.
[0083] The value of μ is defined as proportional to the region weight, i.e. μ = μ_base + β * W, where μ_base is the base contrast stretching value, usually taking 1.0; β is an adjustment coefficient, generally taking a value between 0.1 and 0.5, to control the degree of influence of weight on contrast; W represents the region weight, usually calculated based on the complexity or edge information of the image. In this way, different important regions are given differentiated enhancement. For example, there may be high-density details around the chip pins, so higher weight is given to improve visibility.
[0084] After integrating the parameters for all regions, they are uniformly applied to the image. After comprehensive evaluation of the γ and μ parameters of each region, a unified mapping is formed for the final image enhancement processing, ensuring the consistency and natural transition of the enhancement effect of different parts. For example, in the process of circuit board defect detection, this step can effectively reduce the artifacts after image processing and improve the recognition ability of the model for defects such as cracks and solder joints.
[0085] Next, the application also adds a spatial correlation analysis step in the process of dynamically adjusting the normalization parameters of the image enhancement module based on the weight map, further. First, calculate the entropy value E = ∑(p_i * log p_i) of each image block, where p_i is the gray level frequency ratio, which represents the complexity of the distribution of different gray levels in the image block, usually ranging from 0 to 1, and the optimal value is around 0.5, indicating the maximum amount of information. This step is used to identify areas with low contrast or blurred texture in the image. Then, according to the spatial neighborhood information, evaluate the smoothness of the block. If E < E_threshold, it is determined to be a low contrast area, and E_threshold is generally set to 0.3 to 0.5 to distinguish between normal and low contrast blocks to avoid false processing of normal detail areas. Then, assign a weighted influence factor θ = θ_base * exp(d / d_scale) to all areas, where d is the distance from the center of the area to the center of the image, d_scale is the diffusion constant, and θ_base is initially set to 1. d_scale is usually set to half the size of the image to attenuate the influence of the center area, simulating the human visual focusing mechanism. Finally, the final parameter change ratio is obtained by weighting the weight, entropy value, and spatial influence factor, ensuring that the low contrast area is enhanced, while preventing over-enhancement of the center area. For example, in electronic component surface defect detection, if the contrast of a certain area is reduced due to uneven lighting, the system will fine-tune the area according to this process to improve feature recognition, thereby improving the recognition performance of the subsequent YOLOv5 model. Specifically, when low contrast blocks appear near the center of the image, their enhancement amplitude will be significantly greater than that of the edge area, achieving more reasonable local optimization.
[0086] Next, the image enhancement processing of the application also includes a control mechanism for noise suppression, further. First, identify the area R_noise with high noise based on the gray level histogram. This step uses the gray level histogram to count the number of pixels at each gray level, and identifies areas with uneven distribution or low peak values as potential noise areas. For example, in the detection process of electronic components, if the gray level histogram of a certain area shows obvious dispersion or abnormal distribution, it indicates that there is noise interference in that area, which needs to be further processed.
[0087] Second, calculate the noise intensity N_strength = (σ_rolling_avg 2 - σ_static_avg 2) *K_n. Where, sigma_rolling_avg is the variance within the rolling window, used to measure the local noise fluctuation; sigma_static_avg is the variance of the global background, representing the overall environmental noise level; K_n is the adjustment coefficient, usually set to a value between 0.5 and 2 to adapt to the noise characteristics in different scenarios. This formula compares the local and global noise levels to determine whether there is a significant noise change. For example, when sigma_rolling_avg in a certain area is much larger than sigma_static_avg, it indicates that the noise in this area is strong, and N_strength increases, requiring adjustment of the enhancement strategy.
[0088] Then, if N_strength > N_threshold, the enhancement factor is reduced, specifically scale_factor = max(scale_base-K_n*N_strength, 5). N_threshold is usually set to an empirical threshold, such as 10 or 15, to determine whether to trigger the noise reduction mechanism; scale_base is the default enhancement factor, usually 8 or 10; K_n takes the same range as above. For example, if N_strength is close to 15, scale_factor will be appropriately reduced, thus avoiding excessive enhancement leading to noise amplification.
[0089] Finally, the final enhancement factor is adjusted twice in combination with the weight W and the noise coefficient N_strength. W represents the importance weight of each region, determined by the defect position or features, with a value between 0 and 1; N_strength quantifies the noise level of the current region. The final enhancement factor is calculated by weighted calculation to ensure that the effective defect details are enhanced while the noise is suppressed. For example, in circuit board surface detection, some edge regions produce strong noise due to uneven lighting, so applying a lower enhancement factor to this region can effectively avoid false identification.
[0090] Next, the image enhancement module of the present application also adds a multi-scale analysis mechanism, further. The image is decomposed into multiple scale image layers through Gaussian pyramid. This step will downsample the original image at different scales to generate multiple levels of images to capture the detailed features at different spatial resolutions. For example, in electronic component surface defect detection, different size defects may be more obvious at different scales, and Gaussian pyramid processing can enhance the detection effect. The range of each scale layer s is usually set to 1, 2, 4, 8, etc., indicating different multiples of image scaling.
[0091] The local histogram and contrast C_level of each layer are calculated respectively. This step measures the local contrast by counting the pixel distribution and gradient information of each layer image. The larger the C_level, the richer the details in the image, which is beneficial to improve the subsequent image quality. For example, when a slight scratch appears on the surface of an electronic component, the C_level of the corresponding layer is higher, which helps to improve the visibility of the defect area. The value range of C_level is generally [0, 1], where a higher value means higher contrast.
[0092] The comprehensive weight W_total is obtained by combining C_level with the corresponding scale s, which is W_total = W_local + β_log*log(s). Where W_local is the local weight of the current scale, β_log is used to adjust the influence degree of scale on weight, the value is usually 0.1 to 0.5, and log(s) represents the logarithmic transformation of scale. This formula design is to balance the relationship between local features and global scales, and ensure that appropriate enhancement effects can be obtained in images at different levels. For example, when the scale is large, the value of log(s) is high, which can more significantly adjust the weight, avoiding that the image layer with too large scale covers too many details.
[0093] After weighting and summarizing the information of all scales, the final normalization factor is obtained. This step integrates the weight information of all scales to form a unified enhancement parameter, which is used to adjust the image brightness or contrast and improve the visual clarity of the entire image. For example, when detecting small cracks, the comprehensive weight can automatically enhance the corresponding fine areas, making it easier for the detection model to identify defects. The normalization factor ensures the reasonable fusion of different scale information and improves the overall detection accuracy.
[0094] Next, the dynamic adjustment of the normalization parameter of the present application is described. The fuzzy logic controller (FLC) is used to optimize the further. First, the input variables include the current region weight W and the contrast C. Where W represents the possibility of the current detection area being identified as a defect in the image, its value range is 0 to 1, and the larger W indicates that the region needs more attention; C represents the image contrast of the region, its value range is 0 to 255, and the higher C indicates that the color or brightness difference is larger. For example, in the detection of electronic component surface, a scratch area may have a high W value, while the edge part may have a low C value due to lighting reasons.
[0095] Secondly, define the output variable as the change amount of the normalization parameter Δγ. Δγ is the incremental value used to adjust the normalization layer coefficient in the neural network, and its value range is set to -0.5 to +0.5. This variable is used to adjust the standardization effect of the input feature map, ensuring that the model can more accurately identify defect features under different lighting conditions. For example, in a certain area, if W is large and C is small, it indicates that there may be obvious defects in this area, but the light has a greater impact, so Δγ needs to be reduced to enhance the local contrast.
[0096] Next, the fuzzy reasoning system rule base is constructed. The rule base includes several logical rules similar to if Wis high and C is lowthenΔγis positive, which is used to guide the FLC to infer the corresponding output after receiving the input variable. Such a rule set aims to establish an adaptive mechanism through empirical summary, thereby better handling different image environments. For example, when W is higher than 0.8 and C is less than 50, the system determines that Δγ should be increased, so that the network is more sensitive to this part of the detail changes.
[0097] Fuzzy quantization and defuzzification are performed on the input to obtain the actual adjustment parameter γ_adj. Fuzzy quantization is the process of assigning membership functions to input variables, while defuzzification obtains a specific value from the fuzzy set of the output. For example, if the fuzzy output of Δγ is [0.2, 0.4] after reasoning, then γ_adj may be obtained after defuzzification. This processing ensures the stability and interpretability of the system, improving decision-making efficiency.
[0098] Finally, the historical parameter information is combined to optimize the final normalization adjustment value using the weighted average method. Historical parameter information can record γ_adj in the previous steps, and the formula is γ_final = (α × γ_adj) + ((1-α) × γ_prev), where α is the smoothing factor, usually set to 0.7 to 0.9. This helps to reduce fluctuations caused by temporary abnormal inputs and improves the continuity and stability of the adjustment. For example, if γ_adj is 0.3 after a certain detection, and the historical γ_prev of the previous step is 0.25, and α = 0.8, then the final adjustment value is 0.29. This approach makes the system more stable in real-world scenarios.
[0099] Next, the dynamic adjustment process of the present invention introduces a machine learning strategy, which is based on the model trained on past samples for parameter prediction. Further, historical defect image samples and their corresponding enhancement parameters are collected as a training set, the purpose of which is to obtain a data basis that can be used for model training, and to improve the prediction effect by mining the best enhancement parameter combination in different scenarios through historical data. For example, in electronic component detection, multiple batches of defect images can be collected, and the specific enhancement parameters used when each image is processed can be recorded.
[0100] A feature vector X = [W_region, C_global, E_entropy, d_distance] is established to quantify the properties of the current image and serve as input to the model. W_region represents the region weight, ranging from 0 to 1, indicating the proportion of the defect region in the image; C_global represents the global contrast, with a larger value indicating a clearer image; E_entropy represents the information entropy, reflecting the complexity of the image, with a value generally between 0 and 10; d_distance represents the distance between the defect and the boundary, with a larger value indicating a more central defect position. These features help the model identify the characteristics and potential needs of the image.
[0101] A regression model such as random forest or XGBoost is used to learn the mapping relationship between the sample X and the enhancement parameters γ and μ. γ usually represents the contrast enhancement factor, with a value range of 0.5 to 2, used to adjust the image contrast; μ represents the brightness adjustment coefficient, with a range of -1 to 1, used to correct the light changes. This model can predict the optimal enhancement configuration based on the existing feature and parameter relationship, to improve the accuracy of subsequent detection.
[0102] The values of γ and μ are predicted and adjusted in real time according to the current image features during runtime, achieving adaptive enhancement. For example, when processing an electronic component image with high noise and low contrast, the system will automatically adjust the γ value to approximately 1.5, while increasing the μ value to optimize the overall brightness, thereby improving the detection effect.
[0103] The electronic component surface defect detection method based on YOLOv5 convolutional neural network of the present application includes: first, obtaining the original image data of the surface of the electronic component, then identifying the local contrast low area through image gray histogram analysis, and generating the corresponding weight map based on these areas. Next, the weight map is used to dynamically adjust the normalization parameters in the image enhancement module, so that the image intelligently optimizes the brightness, contrast and other parameters according to the contrast characteristics of different areas during the enhancement process. Then, the adjusted normalization parameters are applied to enhance the image, thereby improving the clarity and detail performance of the low contrast area in the image. Finally, the enhanced image is input into the YOLOv5 model for defect detection, realizing efficient recognition and positioning of the surface defects of the electronic component.
[0104] The application proposes a strategy of dynamically adjusting image enhancement parameters by in-depth analysis of image gray difference, effectively solving the problem of low recognition rate of traditional methods when facing low contrast defects. Traditional image enhancement techniques usually use fixed normalization parameters, which cannot adapt to the contrast difference between different regions, resulting in some key defect features being weakened or even lost. However, the application introduces the concept of weight map, and adjusts the parameters of the enhancement module in real time according to the gray distribution of each region of the image, so that the image can obtain better visual performance on global and local scales, significantly improving the recognition ability of the YOLOv5 model for small or low contrast defects. This intelligent adjustment mechanism not only improves the image quality, but also enhances the accuracy and stability of defect detection, and has high practical value and technical advantages.
[0105] The above specific embodiments further illustrate the purpose, technical solutions and beneficial effects of the embodiments of the present disclosure. It should be understood that the above description is only a specific embodiment of the present disclosure and is not intended to limit the protection scope of the present disclosure. Any modification, equivalent replacement, improvement, etc. within the spirit and principles of the embodiments of the present disclosure should be included in the protection scope of the embodiments of the present disclosure.
Claims
1. A method for detecting surface defects in electronic components based on YOLOv5 convolutional neural networks, characterized in that, It includes: Obtain the original image data of the surface of electronic components; Based on the analysis of the image grayscale histogram, determine the regions with low local contrast and generate the corresponding weight map; Dynamically adjust the normalization parameters of the image enhancement module based on the weight map; Use the adjusted normalization parameters to enhance the image and input it into the YOLOv5 model for defect detection.
2. The method for detecting surface defects of electronic components based on YOLOv5 convolutional neural networks according to claim 1, characterized in that, The determination of the regions with low local contrast based on the analysis of the image grayscale histogram further includes: Obtain the grayscale histogram data of the image; Count the number of pixels in each grayscale interval and calculate the histogram gradient of the current grayscale interval; Judge the low-contrast regions based on the following formula: If ΔI < I_threshold and (I_max - I_min) / I_avg < T_ratio, then it is a low-contrast region; where ΔI is the difference amplitude between adjacent grayscale intervals, I_threshold is the set threshold, I_max is the maximum grayscale value, I_min is the minimum grayscale value, and I_avg is the average grayscale value; Generate a weight map corresponding to the above low-contrast regions.
3. The method for detecting surface defects of electronic components based on YOLOv5 convolutional neural networks according to claim 2, characterized in that, The dynamic adjustment of the normalization parameters of the image enhancement module based on the weight map further includes: Calculate the weight coefficient W of each low-contrast region: W = α * log(1 + pixel_count / area_total); Introduce an adaptive coefficient α to balance the influence of different regions; Combine the regional weights with the overall histogram information and calculate the normalization factor β = β_base * W; Perform linear interpolation or non-linear mapping on the normalization parameters to form a new normalization parameter matrix.
4. The method for detecting surface defects of electronic components based on YOLOv5 convolutional neural networks according to claim 3, characterized in that, The enhancement of the image using the adjusted normalization parameters further includes: Adopt a two-channel normalization algorithm to perform joint global and local enhancement on the image; Perform weighted compensation on the brightness of each pixel point in the image, where the compensation amount C = K * (W - W_min) / (W_max - W_min); where K is the gain coefficient, W is the weight value corresponding to this position, W_min is the minimum value of all regional weights, and W_max is the maximum value; Input the compensated image into the image preprocessing module to enhance local details; Finally, generate the enhanced input image and input it into the YOLOv5 model.
5. The method for detecting surface defects of electronic components based on YOLOv5 convolutional neural networks according to claim 4, characterized in that, The normalization parameters in the image enhancement module include the gamma correction parameter γ and the contrast stretching parameter μ. The dynamic adjustment of the normalization parameters further includes: Calculate the maximum value I_max_local and the minimum value I_min_local of the image in each region according to the weight map; Define the local contrast C_local = (I_max_local - I_min_local) / (I_max_global - I_min_global). If C_local < T_contrast, then adjust the parameter γ = γ_base * (C_local / T_contrast)^α, where T_contrast is the set contrast threshold and α is the adaptive coefficient; Define that the value of μ is proportional to the regional weight, i.e., μ = μ_base + β * W, where β is the adjustment coefficient; After integrating the parameters for all regions, they are uniformly applied to the image.
6. The method for detecting surface defects of electronic components based on YOLOv5 convolutional neural networks according to claim 5, characterized in that, During the process of dynamically adjusting the normalization parameters of the image enhancement module based on the weight map, a spatial correlation analysis step is also added, which further includes: Calculate the entropy value E = Σ(p_i * log p_i) of each image block, where p_i is the proportion of gray-level frequency; Evaluate the smoothness of the block according to the spatial neighborhood information. If E < E_threshold, it is determined that it may be a low-contrast region; Assign a weighted influence factor θ = θ_base * exp(d / d_scale) to all regions, where d is the distance from the center of the region to the center of the image, and d_scale is the diffusion proportional constant; Obtain the final parameter change ratio by weighting the weight, entropy value, and spatial influence factor.
7. The method for detecting surface defects of electronic components based on YOLOv5 convolutional neural networks according to claim 6, characterized in that, The image enhancement process also includes a control mechanism for noise suppression, which further includes: Identify the region R_noise with large noise based on the gray-level histogram; Calculate the noise intensity N_strength = (σ_rolling_avg^2 - σ_static_avg^2) * K_n; where σ_rolling_avg is the variance within the rolling window, σ_static_avg is the variance of the global background, and K_n is the adjustment coefficient; If N_strength > N_threshold, reduce the enhancement multiple, specifically scale_factor = max(scale_base - K_n * N_strength, 5); Perform a secondary adjustment on the final enhancement coefficient by combining the weight W and the noise coefficient N_strenth.
8. The method for detecting surface defects of electronic components based on YOLOv5 convolutional neural networks according to claim 7, characterized in that, The image enhancement module also adds a multi-scale analysis mechanism, which further includes: Decompose the image into image layers of multiple scales through Gaussian pyramid; Calculate its local histogram and contrast C_level for each layer respectively; Combine C_level with the corresponding scale s to obtain the comprehensive weight W_total = W_local + β_log * log(s); After weighting and summarizing the information of all scales, obtain the final normalization factor.
9. The method for detecting surface defects of electronic components based on YOLOv5 convolutional neural networks according to claim 8, characterized in that, The method of dynamically adjusting the normalization parameters is optimized by using a fuzzy logic controller (FLC), which further includes: Design the input variables to include the current regional weight W and contrast C; Define the output variable as the change amount Δγ of the normalization parameter; Construct a fuzzy inference system rule base, for example: if W is high and C is low then Δγ is positive; Perform fuzzy quantization and defuzzification processing on the input to obtain the actual adjustment parameter γ_adj; Combine the historical parameter information and use the weighted average method to optimize the final normalization adjustment value.
10. The method for detecting surface defects of electronic components based on YOLOv5 convolutional neural networks according to claim 9, characterized in that, The dynamic adjustment process introduces a machine learning strategy to predict parameters based on training the model with past samples, which further includes: Collect historical defective image samples and their corresponding enhancement parameters as the training set; Establish the feature vector X = [W_region, C_global, E_entropy, d_distance]; Regression models such as random forest or XGBoost are used to learn the mapping relationship between sample X and boosting parameters γ and μ; During runtime, the values of γ and μ are predicted and adjusted in real time based on the current image features to achieve adaptive enhancement.