An optimal segmentation method, detection method and system for product appearance defect detection
By calculating parameters such as block-level and pixel-level false detection rates, an evaluation function is constructed to determine the optimal block parameters, thus solving the problems of high false detection rates and difficult evaluation in existing defect detection technologies and optimizing the performance of defect detection algorithms.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SICHUAN CHAOYIHONG TECH CO LTD
- Filing Date
- 2022-01-24
- Publication Date
- 2026-07-31
AI Technical Summary
Existing technologies struggle to determine optimal segmentation parameters in product appearance defect detection, leading to high false detection rates and evaluation difficulties, and hindering algorithm performance optimization.
By calculating the block-level false detection rate, pixel-level false detection rate, false detection rate parameter, false detection balance parameter, and false detection amplification parameter, an evaluation function is constructed to determine the optimal block parameters and optimize the performance of the defect detection algorithm.
This enabled a comprehensive and accurate evaluation of the defect detection algorithm, determined the optimal block parameters, and improved detection accuracy and efficiency.
Smart Images

Figure CN114581372B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the technical field of electronic manufacturing, and more specifically, to an optimal segmentation method, detection method, and system for detecting product appearance defects. Background Technology
[0002] Intelligent manufacturing will become a major development direction in the new era. my country's manufacturing industry will transform from traditional production methods to intelligent production, using the deep integration of informatization and industrialization to lead and drive the development of the entire manufacturing industry. Manually inspecting defects in electronic components is time-consuming and labor-intensive; therefore, automated appearance defect inspection is an inevitable trend in the industry. Currently, some detection algorithms use a block-based and re-integrated detection approach, and the shape and size of the blocks have a certain impact on the algorithm. For some algorithms, changing the number of blocks increases accuracy but introduces false positives. For example, too few blocks result in large detection blocks, leading to overly large detection boxes and excessive redundant information; too many blocks result in small detection blocks, reducing the contrast between the resulting detection blocks and causing a large number of false positives and false negatives. Therefore, for some algorithms, under reasonable conditions, the difference between the false positive rate per block and the false positive rate per pixel is not significant, making evaluation difficult. Therefore, a defect detection evaluation method is needed to comprehensively evaluate how to select the optimal block size, and it is also necessary to consider the overall performance of the detection target and the algorithm, rather than just accuracy.
[0003] Existing technology discloses an image segmentation quality evaluation method based on ROC Graph. This method includes: first, classifying pixels in the image to be evaluated into four categories by comparing them with a reference segmentation image; second, introducing pixel spatial information, performing a distance transformation on the pixels in the reference image, and calculating the distance from each pixel to the target boundary; third, assigning a weight to the corresponding pixel in the segmentation image based on the distance coefficient of each pixel in the reference image; fourth, calculating the weighted true positive rate (wTPR) and weighted false positive rate (wFPR) using the weights, and plotting the point (wFPR, wTPR) in the ROC Graph; fifth, scoring the segmented image based on the distance from the point (wFPR, wTPR) in the ROC Graph to the point (0, 1), with a higher score indicating better segmentation performance. Since this method evaluates every single pixel, it incurs extremely high computational time costs and is unsuitable for high-resolution data samples, failing to optimize algorithm performance. Summary of the Invention
[0004] To overcome the shortcomings of existing technologies in evaluating product appearance defect detection results and determining optimal segmentation parameters, this invention provides an optimal segmentation method, detection method, and system for product appearance defect detection. This system can comprehensively and accurately evaluate the detection results of segmentation-based defect detection algorithms, determine the optimal segmentation parameters, and use these optimal segmentation parameters to perform defect detection on the product to be tested, thereby optimizing the performance of the defect detection algorithm.
[0005] To solve the above-mentioned technical problems, the technical solution of the present invention is as follows:
[0006] This invention provides an optimal segmentation method for detecting product appearance defects, comprising:
[0007] S1: Obtain product appearance images and actual categories of appearance defects;
[0008] S2: Input the appearance image into the existing block-based defect detection algorithm, and set the block parameters and the number of evaluations;
[0009] S3: Based on the block parameters, perform block-level defect detection to obtain block-level and pixel-level detection results;
[0010] S4: Compare the block-level detection results and pixel-level detection results with the true categories of appearance defects, determine the classification attributes of the block-level detection results and pixel-level detection results, and calculate the number of each classification attribute;
[0011] S5: Based on the number of classification attributes in the block-level detection results and pixel-level detection results, calculate the block-level false detection rate, pixel-level false detection rate, false detection rate parameter, false detection balance parameter, and false detection amplification parameter;
[0012] S6: Set the evaluation function based on the block-level false detection rate, pixel-level false detection rate, false detection rate parameter, false detection balance parameter, and false detection amplification parameter, and calculate the final evaluation result;
[0013] S7: Update the block parameters, repeat steps S3-S6, and proceed with the next round of evaluation to obtain the final evaluation result for each block parameter until the number of evaluations is reached.
[0014] S8: Compare the magnitude of the final evaluation result corresponding to each block parameter. When the value of the final evaluation result is the largest, the corresponding block parameter is the optimal block parameter.
[0015] Preferably, the product is an electronic component.
[0016] Preferably, in step S4, the block-level detection results and pixel-level detection results are compared with the true categories of appearance defects to determine the classification attributes of the block-level and pixel-level detection results, and the specific orientation of the quantity of each classification attribute is calculated as follows:
[0017] The actual category of appearance defects is either "defect present" or "defect not present";
[0018] The block-level detection results are compared with the true categories of appearance defects to obtain the classification attributes of the block-level detection results: when the block-level detection result of the appearance image indicates the presence of a defect and the true category of appearance defect also indicates the presence of a defect, the classification attribute of the block-level detection result is a block-level true positive, and the number is denoted as BTP; when the block-level detection result of the appearance image indicates the presence of a defect and the true category of appearance defect also indicates the absence of a defect, the classification attribute of the block-level detection result is a block-level false positive, and the number is denoted as BFP; when the block-level detection result of the appearance image indicates the absence of a defect and the true category of appearance defect also indicates the presence of a defect, the classification attribute of the block-level detection result is a block-level false negative, and the number is denoted as BFN; when the block-level detection result of the appearance image indicates the absence of a defect and the true category of appearance defect also indicates the absence of a defect, the classification attribute of the block-level detection result is a block-level true negative, and the number is denoted as BTN.
[0019] Using the same method, the pixel-level detection results are compared with the true categories of appearance defects to obtain the classification attributes of the pixel-level detection results, including: pixel-level true positives, pixel-level false negatives, pixel-level false positives, and pixel-level true negatives; the number of these are denoted as PTP, PTN, PFP, and PTN, respectively.
[0020] Preferably, the specific method for calculating the block-level false detection rate based on the number of classification attributes of the block-level detection results and pixel-level detection results is as follows:
[0021]
[0022] In the formula, BFDR represents the block-level false positive rate, BFP represents the number of block-level false positives, and BTN represents the number of block-level true negatives.
[0023] Preferably, the specific method for calculating the pixel-level false detection rate based on the classification attributes of block-level and pixel-level detection results is as follows:
[0024]
[0025] In the formula, PFDR represents the pixel-level false positive rate, PFP represents the number of pixel-level false positives, and PTN represents the number of pixel-level true negatives.
[0026] Preferably, the specific method for calculating the false detection rate parameter based on the classification attributes of block-level and pixel-level detection results is as follows:
[0027]
[0028] In the formula, α represents the false detection rate parameter.
[0029] Different block parameters result in variations in pixel-level and block-level false positive rates for block-based defect detection algorithms, with some being higher and others lower, making it difficult to determine the optimal block size for better algorithm performance. To evaluate the overall algorithm performance, a false positive rate (PFDR) parameter is proposed. As shown in the formula, the smaller BFDR and PFDR are, the larger the PFDR parameter becomes. When BFDR and PFDR approach 0, the α value approaches infinity. In actual detection, even if the block-level PFDR is 0, the pixel-level PFDR cannot be 0 because blocks are always designed according to a specific shape, while defect pixels are always irregular. When BFDR is 0, it indicates that the block-based defect detection algorithm has reached its optimal state and no further calculations are needed, but this situation is extremely rare, and achieving 0% false positives is very difficult in practice. Furthermore, the design of the PFDR parameter also considers that it is more difficult to improve the algorithm's performance at higher levels, as shown in the following formula:
[0030]
[0031] In the formula, the false detection rate parameter α0 minus δ is α_0. δ Let x and y represent any false positive rate (FPR). Specifically, when x represents the base false positive rate (BFDR), y represents the power false positive rate (PFDR), and vice versa. It can be seen that when the decrease in rate δ is the same, the smaller y is... The larger the value, the greater the improvement.
[0032] Preferably, the specific method for calculating the false detection balance parameter based on the classification attributes of block-level and pixel-level detection results is as follows:
[0033]
[0034] In the formula, β represents the false detection balance parameter, c represents the first contraction factor, and b represents the second contraction factor.
[0035] The false positive rate parameter evaluates the overall performance of the algorithm, but it cannot evaluate whether the pixel-level false positive rate or the block-level false positive rate contributes more to the algorithm's performance; PFP+PTN is the total negative samples in pixels of the appearance image, and BFP+BTN is the total negative samples in blocks of the appearance image. This represents the ratio of block negative samples to pixel negative samples. Because the numerical difference between (b·PTN+PFP) and (b·BTN+BFP) is too large, the false positive balancing parameter is used to balance the difference in their quantities. The total number of defect samples for pixel-level defect detection is determined the moment the appearance image is finalized, but the total number of defect samples for block-level defect detection is determined by the block segmentation parameter. The more blocks there are, the more total defect samples there are. The second shrinkage factor b∈(0,1) is a distance metric. The better the algorithm performance, the smaller the detection results are in PFP and BFP, and the larger they are in PTN and BTN. Introducing the second shrinkage factor b greatly reduces PTN and BTN. The introduction of the first shrinkage factor c can determine which false positive rate is the focus when evaluating the algorithm. When there is no bias in the focus, c=1. From the first term (BFP+BTN)(b·PTN+PFP) in the above formula, it can be seen that the more blocks there are, the larger BFP+BTN will be, but it will also cause changes in b·PTN+PFP. When the number of blocks is extremely large or extremely small, the value of PFP will be very large. Therefore, it is necessary to find the optimal block parameters.
[0036] Preferably, the specific method for calculating the false detection amplification parameter based on the classification attributes of block-level and pixel-level detection results is as follows:
[0037]
[0038] In the formula, γ represents the false detection amplification parameter.
[0039] The relationship between block-level and pixel-level false detections is not independent; each block false detection contributes to pixel false detections. The false detection balancing parameter cannot describe the correlation between these two false detection rates and the algorithm's detection performance under different block sizes. To investigate how many pixel-level false detections are caused by block-level false detections, a false detection amplification parameter γ is proposed. The number of blocks does not monotonically lead to better or worse detection results; too many or too few blocks will both result in false detections. An appropriate number of blocks is the optimal choice. Blocks that are too small will lead to low contrast between blocks, while blocks that are too large will introduce a large number of redundant and irrelevant pixels, reducing detection precision. The false detection amplification parameter γ directly reflects how many pixel false detections are caused by each block false detection.
[0040] Preferably, in step S6, the specific method for setting the evaluation function based on the block-level false detection rate, pixel-level false detection rate, false detection rate parameter, false detection balance parameter, and false detection amplification parameter, and calculating the final evaluation result, is as follows:
[0041] The evaluation function is:
[0042]
[0043] In the formula, L represents the final evaluation result, t represents the detection time of the block-based defect detection algorithm, λ represents the first reduction factor, and θ represents the second reduction factor.
[0044] The first and second reduction factors are determined based on the appearance image and are adjusted automatically. On high-resolution appearance images, the values of β and γ are very large, not on the same order of magnitude as α. Therefore, the first and second reduction factors are introduced to be appropriately balanced to a reasonable range so that the final evaluation result calculated by the evaluation function is a positive number. The larger the value of L, the better the performance of the algorithm.
[0045] This invention also provides an optimal detection method for product appearance defects, based on the above-mentioned optimal segmentation method for product appearance defect detection, comprising:
[0046] S1: Obtain product appearance images and actual categories of appearance defects;
[0047] S2: Input the appearance image into the existing block-based defect detection algorithm, and set the block parameters and the number of evaluations;
[0048] S3: Based on the block parameters, perform block-level defect detection to obtain block-level and pixel-level detection results;
[0049] S4: Compare the block-level detection results and pixel-level detection results with the true categories of appearance defects, determine the classification attributes of the block-level detection results and pixel-level detection results, and calculate the number of each classification attribute;
[0050] S5: Based on the number of classification attributes in the block-level detection results and pixel-level detection results, calculate the block-level false detection rate, pixel-level false detection rate, false detection rate parameter, false detection balance parameter, and false detection amplification parameter;
[0051] S6: Set the evaluation function based on the block-level false detection rate, pixel-level false detection rate, false detection rate parameter, false detection balance parameter, and false detection amplification parameter, and calculate the final evaluation result;
[0052] S7: Update the block parameters, repeat steps S3-S6, and proceed with the next round of evaluation to obtain the final evaluation result for each block parameter until the number of evaluations is reached.
[0053] S8: Compare the magnitude of the final evaluation result corresponding to each block parameter. When the value of the final evaluation result is the largest, the corresponding block parameter is the optimal block parameter.
[0054] S9: Return the optimal segmentation parameters to the existing segmentation-based defect detection algorithm, and use the optimal segmentation parameters to segment the product appearance image to be detected into blocks to obtain the optimal defect detection result.
[0055] This invention also provides an optimized system for detecting product appearance defects, based on the above-mentioned optimal detection method, comprising:
[0056] The image acquisition module is used to acquire images of the product's appearance and the actual categories of appearance defects.
[0057] The detection algorithm module is used to input the appearance image into the existing block-based defect detection algorithm and set the block parameters and the number of evaluations;
[0058] The detection execution module performs block-level defect detection based on the block parameters, and obtains block-level detection results and pixel-level detection results.
[0059] The results classification module is used to compare the block-level detection results and pixel-level detection results with the true categories of appearance defects, determine the classification attributes of the block-level detection results and pixel-level detection results, and calculate the number of each classification attribute.
[0060] The evaluation parameter calculation module calculates the block-level false detection rate, pixel-level false detection rate, false detection rate parameter, false detection balance parameter, and false detection amplification parameter based on the number of classification attributes in the block-level detection results and pixel-level detection results.
[0061] The evaluation function module sets the evaluation function based on the block-level false detection rate, pixel-level false detection rate, false detection rate parameter, false detection balance parameter, and false detection amplification parameter, and calculates the final evaluation result.
[0062] The block parameter update module is used to update the block parameters and send them to the detection execution module for the next round of evaluation, until the number of evaluations is reached.
[0063] The comparison module is used to compare the size of the final evaluation result corresponding to each block parameter. When the value of the final evaluation result is the largest, the corresponding block parameter is the optimal block parameter.
[0064] The parameter transmission module returns the optimal block parameters to the block-based defect detection algorithm in the detection algorithm module. The detection execution module uses the optimal block parameters to divide the product appearance image to be detected into blocks, performs defect detection, and obtains the optimal defect detection result.
[0065] Compared with the prior art, the beneficial effects of the technical solution of the present invention are:
[0066] This invention utilizes existing block-based defect detection algorithms to perform block-level defect detection on product appearance images according to set block parameters. The obtained block-level and pixel-level detection results are compared with the true categories of appearance defects to determine the classification attributes and their quantity. Based on the number of classification attributes, block-level false detection rate, pixel-level false detection rate, false detection rate parameter, false detection balance parameter, and false detection amplification parameter are calculated. The false detection rate parameter comprehensively considers the algorithm's defect detection level at both the pixel and block levels, initially reflecting the algorithm's overall performance. The false detection balance parameter reflects the degree of influence of block-level and pixel-level false detection rates on algorithm performance. The false detection amplification parameter reflects the impact of block parameters on pixel-level detection during block-level detection. Finally, an evaluation function is constructed by combining the false detection rate parameter, false detection balance parameter, and false detection amplification parameter to calculate the final evaluation result, comprehensively and accurately evaluating the detection results of the block-based defect detection algorithm. The block parameters corresponding to the maximum final evaluation result are taken as the optimal block parameters. Using the optimal block parameters, defect detection is performed on the product to be inspected, thereby optimizing the performance of the defect detection algorithm. Attached Figure Description
[0067] Figure 1 This is a flowchart of an optimal block-based method for detecting product appearance defects as described in Example 1;
[0068] Figure 2 This is a schematic diagram comparing the block-level detection results with the actual categories of appearance defects as described in Example 2;
[0069] Figure 3 This is a schematic diagram showing the comparison of pixel-level detection results with the true categories of appearance defects described in Example 2;
[0070] Figure 4 This is a flowchart of an optimal detection method for detecting product appearance defects as described in Example 3;
[0071] Figure 5 This is a schematic diagram of the structure of an optimized system for detecting product appearance defects as described in Example 4. Detailed Implementation
[0072] The accompanying drawings are for illustrative purposes only and should not be construed as limiting the scope of this patent.
[0073] To better illustrate this embodiment, some parts in the accompanying drawings may be omitted, enlarged, or reduced, and do not represent the actual product dimensions;
[0074] It will be understood by those skilled in the art that certain well-known structures and their descriptions may be omitted in the accompanying drawings.
[0075] The technical solution of the present invention will be further described below with reference to the accompanying drawings and embodiments.
[0076] Example 1
[0077] This embodiment provides an optimal segmentation method for detecting product appearance defects, such as... Figure 1 As shown, it includes:
[0078] S1: Obtain product appearance images and actual categories of appearance defects;
[0079] S2: Input the appearance image into the existing block-based defect detection algorithm, and set the block parameters and the number of evaluations;
[0080] S3: Based on the block parameters, perform block-level defect detection to obtain block-level and pixel-level detection results;
[0081] S4: Compare the block-level detection results and pixel-level detection results with the true categories of appearance defects, determine the classification attributes of the block-level detection results and pixel-level detection results, and calculate the number of each classification attribute;
[0082] S5: Based on the number of classification attributes in the block-level detection results and pixel-level detection results, calculate the block-level false detection rate, pixel-level false detection rate, false detection rate parameter, false detection balance parameter, and false detection amplification parameter;
[0083] S6: Set the evaluation function based on the block-level false detection rate, pixel-level false detection rate, false detection rate parameter, false detection balance parameter, and false detection amplification parameter, and calculate the final evaluation result;
[0084] S7: Update the block parameters, repeat steps S3-S6, and proceed with the next round of evaluation to obtain the final evaluation result for each block parameter until the number of evaluations is reached.
[0085] S8: Compare the magnitude of the final evaluation result corresponding to each block parameter. When the value of the final evaluation result is the largest, the corresponding block parameter is the optimal block parameter.
[0086] In the specific implementation process, this embodiment utilizes existing block-based defect detection algorithms to perform block-level defect detection on product appearance images according to the set block parameters. The obtained block-level and pixel-level detection results are compared with the true categories of appearance defects to determine the classification attributes and their quantity in the detection results. Based on the quantity of classification attributes, the block-level false detection rate, pixel-level false detection rate, false detection rate parameter, false detection balance parameter, and false detection amplification parameter are calculated. The false detection rate parameter comprehensively considers the algorithm's defect detection level at both the pixel and block levels, and initially reflects the overall performance of the algorithm. The false detection balance parameter reflects the degree of influence of the block-level and pixel-level false detection rates on the algorithm's performance. The false detection amplification parameter reflects the influence of the block parameters on pixel-level detection during block-level detection. Finally, an evaluation function is constructed by combining the false detection rate parameter, false detection balance parameter, and false detection amplification parameter to calculate the final evaluation result. This comprehensively and accurately evaluates the detection results of the block-based defect detection algorithm, and the block parameters corresponding to the maximum final evaluation result are taken as the optimal block parameters.
[0087] Example 2
[0088] This embodiment provides an optimal segmentation method for product appearance defect detection, including:
[0089] S1: Obtain product appearance images and actual categories of appearance defects; the product in question is an electronic component.
[0090] S2: Input the appearance image into the existing block-based defect detection algorithm, and set the block parameters and the number of evaluations;
[0091] S3: Based on the block parameters, perform block-level defect detection to obtain block-level and pixel-level detection results;
[0092] S4: Compare the block-level detection results and pixel-level detection results with the true categories of appearance defects, determine the classification attributes of the block-level detection results and pixel-level detection results, and calculate the number of each classification attribute;
[0093] The true category of appearance defects is either present or absent; the presence of defects is recorded as a true value, and the absence of defects is recorded as a false value; the presence of defects in the test results is recorded as a positive example, and the absence of defects is recorded as a negative example.
[0094] like Figure 2As shown, the block-level detection results are compared with the true categories of appearance defects to obtain the classification attributes of the block-level detection results: when the block-level detection result of the appearance image is "defect exists" and the true category of appearance defect is "defect exists", the classification attribute of the block-level detection result is "block-level true positive", and the number is denoted as BTP; when the block-level detection result of the appearance image is "defect exists" and the true category of appearance defect is "defect does not exist", the classification attribute of the block-level detection result is "block-level false positive", and the number is denoted as BFP; when the block-level detection result of the appearance image is "defect does not exist" and the true category of appearance defect is "defect exists", the classification attribute of the block-level detection result is "block-level false negative", and the number is denoted as BFN; when the block-level detection result of the appearance image is "defect does not exist" and the true category of appearance defect is "defect does not exist", the classification attribute of the block-level detection result is "block-level true negative", and the number is denoted as BTN.
[0095] like Figure 3 As shown, the same method is used to compare the pixel-level detection results with the true categories of appearance defects to obtain the classification attributes of the pixel-level detection results, including: pixel-level true positives, pixel-level false negatives, pixel-level false positives and pixel-level true negatives; the number is denoted as PTP, PTN, PFP and PTN respectively.
[0096] S5: Based on the number of classification attributes in the block-level detection results and pixel-level detection results, calculate the block-level false detection rate, pixel-level false detection rate, false detection rate parameter, false detection balance parameter, and false detection amplification parameter;
[0097] The block-level false positive rate is:
[0098]
[0099] In the formula, BFDR represents the block-level false positive rate, BFP represents the number of block-level false positives, and BTN represents the number of block-level true negatives.
[0100] The pixel-level false positive rate is:
[0101]
[0102] In the formula, PFDR represents the pixel-level false positive rate, PFP represents the number of pixel-level false positives, and PTN represents the number of pixel-level true negatives.
[0103] The false positive rate parameter is:
[0104]
[0105] Different block segmentation parameters result in varying false positive rates (FPRs) at the pixel and block levels for block-based defect detection algorithms, making it difficult to determine the optimal block size for best performance. To evaluate the overall algorithm performance, a false positive rate (FPR) parameter is proposed. As shown in the formula, smaller BFDR and PFDR result in larger FPR parameters. When BFDR and PFDR approach zero, the α value approaches infinity. In actual detection, even if the block-level FPR is zero, the pixel-level FPR cannot be zero because blocks are always designed according to a specific shape, while defect pixels are always irregular. When BFDR is zero, it indicates that the block-based defect detection algorithm has reached its optimal state and no further calculations are needed, but this is extremely rare, making it very difficult to achieve 0% false positives in practice. Furthermore, the design of the FPR parameter also considers that improving the algorithm's performance becomes increasingly difficult at higher performance levels.
[0106] The false positive balance parameter is:
[0107]
[0108] In the formula, β represents the false detection balance parameter, c represents the first contraction factor, and b represents the second contraction factor;
[0109] The false positive rate parameter evaluates the overall performance of the algorithm, but it cannot evaluate whether the pixel-level false positive rate or the block-level false positive rate contributes more to the algorithm's performance; PFP+PTN is the total negative samples in pixels of the appearance image, and BFP+BTN is the total negative samples in blocks of the appearance image. This represents the ratio of block negative samples to pixel negative samples. Because the numerical difference between (b·PTN+PFP) and (b·BTN+BFP) is too large, the false positive balancing parameter is used to balance the difference in their quantities. The total number of defect samples for pixel-level defect detection is determined the moment the appearance image is finalized, but the total number of defect samples for block-level defect detection is determined by the block segmentation parameter. The more blocks there are, the more total defect samples there are. The second shrinkage factor b∈(0,1) is a distance metric. The better the algorithm performance, the smaller the detection results are in PFP and BFP, and the larger they are in PTN and BTN. Introducing the second shrinkage factor b greatly reduces PTN and BTN. The introduction of the first shrinkage factor c can determine which false positive rate is the focus when evaluating the algorithm. When there is no bias in the focus, c=1. From the first term (BFP+BTN)(b·PTN+PFP) in the above formula, it can be seen that the more blocks there are, the larger BFP+BTN will be, but it will also cause changes in b·PTN+PFP. When the number of blocks is extremely large or extremely small, the value of PFP will be very large. Therefore, it is necessary to find the optimal block parameters.
[0110] The false detection amplification parameter is:
[0111]
[0112] The relationship between block-level and pixel-level false detections is not independent; each block's false detection contributes to pixel-level false detections. The false detection balancing parameter cannot describe the correlation between these two false detection rates and the algorithm's detection performance under different block sizes. To investigate how many pixel-level false detections are caused by block-level false detections, a false detection amplification parameter γ is proposed. The number of blocks does not monotonically lead to better or worse detection results; too many or too few blocks will both result in false detections. An appropriate number of blocks is the optimal choice. Blocks that are too small will lead to low contrast between blocks, while blocks that are too large will introduce a large number of redundant and irrelevant pixels, reducing detection precision. The false detection amplification parameter γ directly reflects how many pixel-level false detections are caused by each block's false detection.
[0113] S6: Set the evaluation function based on the block-level false detection rate, pixel-level false detection rate, false detection rate parameter, false detection balance parameter, and false detection amplification parameter, and calculate the final evaluation result;
[0114] The evaluation function is:
[0115]
[0116] In the formula, L represents the final evaluation result, t represents the detection time of the block-based defect detection algorithm, λ represents the first reduction factor, and θ represents the second reduction factor.
[0117] The first and second reduction factors are determined based on the appearance image and are adjusted automatically. On high-resolution appearance images, the values of β and γ are very large, not on the same order of magnitude as α. Therefore, the first and second reduction factors are introduced to be appropriately balanced to a reasonable range so that the final evaluation result calculated by the evaluation function is a positive number. The larger the value of L, the better the performance of the algorithm.
[0118] S7: Update the block parameters, repeat steps S3-S6, and proceed with the next round of evaluation to obtain the final evaluation result for each block parameter until the number of evaluations is reached.
[0119] S8: Compare the magnitude of the final evaluation result corresponding to each block parameter. When the value of the final evaluation result is the largest, the corresponding block parameter is the optimal block parameter.
[0120] Example 3
[0121] This embodiment provides an optimal detection method for product appearance defects, based on the optimal block-based method for product appearance defect detection described in embodiment 1 or 2, such as... Figure 4 As shown, the feature is that it includes:
[0122] S1: Obtain product appearance images and actual categories of appearance defects;
[0123] S2: Input the appearance image into the existing block-based defect detection algorithm, and set the block parameters and the number of evaluations;
[0124] S3: Based on the block parameters, perform block-level defect detection to obtain block-level and pixel-level detection results;
[0125] S4: Compare the block-level detection results and pixel-level detection results with the true categories of appearance defects, determine the classification attributes of the block-level detection results and pixel-level detection results, and calculate the number of each classification attribute;
[0126] S5: Based on the number of classification attributes in the block-level detection results and pixel-level detection results, calculate the block-level false detection rate, pixel-level false detection rate, false detection rate parameter, false detection balance parameter, and false detection amplification parameter;
[0127] S6: Set the evaluation function based on the block-level false detection rate, pixel-level false detection rate, false detection rate parameter, false detection balance parameter, and false detection amplification parameter, and calculate the final evaluation result;
[0128] S7: Update the block parameters, repeat steps S3-S6, and proceed with the next round of evaluation to obtain the final evaluation result for each block parameter until the number of evaluations is reached.
[0129] S8: Compare the magnitude of the final evaluation result corresponding to each block parameter. When the value of the final evaluation result is the largest, the corresponding block parameter is the optimal block parameter.
[0130] S9: Return the optimal segmentation parameters to the existing segmentation-based defect detection algorithm, and use the optimal segmentation parameters to segment the product appearance image to be detected into blocks to obtain the optimal defect detection result.
[0131] Example 4
[0132] This embodiment provides an optimized system for detecting product appearance defects, based on the optimal detection method described in Embodiment 3, such as... Figure 5 As shown, it includes:
[0133] The image acquisition module is used to acquire images of the product's appearance and the actual categories of appearance defects.
[0134] The detection algorithm module is used to input the appearance image into the existing block-based defect detection algorithm and set the block parameters and the number of evaluations;
[0135] The detection execution module performs block-level defect detection based on the block parameters, and obtains block-level detection results and pixel-level detection results.
[0136] The results classification module is used to compare the block-level detection results and pixel-level detection results with the true categories of appearance defects, determine the classification attributes of the block-level detection results and pixel-level detection results, and calculate the number of each classification attribute.
[0137] The evaluation parameter calculation module calculates the block-level false detection rate, pixel-level false detection rate, false detection rate parameter, false detection balance parameter, and false detection amplification parameter based on the number of classification attributes in the block-level detection results and pixel-level detection results.
[0138] The evaluation function module sets the evaluation function based on the block-level false detection rate, pixel-level false detection rate, false detection rate parameter, false detection balance parameter, and false detection amplification parameter, and calculates the final evaluation result.
[0139] The block parameter update module is used to update the block parameters and send them to the detection execution module for the next round of evaluation, until the number of evaluations is reached.
[0140] The comparison module is used to compare the size of the final evaluation result corresponding to each block parameter. When the value of the final evaluation result is the largest, the corresponding block parameter is the optimal block parameter.
[0141] The parameter transmission module returns the optimal block parameters to the block-based defect detection algorithm in the detection algorithm module. The detection execution module uses the optimal block parameters to divide the product appearance image to be detected into blocks, performs defect detection, and obtains the optimal defect detection result.
[0142] The same or similar labels correspond to the same or similar parts;
[0143] The terms used to describe positional relationships in the accompanying drawings are for illustrative purposes only and should not be construed as limiting this patent.
[0144] Obviously, the above embodiments of the present invention are merely examples for clearly illustrating the present invention, and are not intended to limit the implementation of the present invention. Those skilled in the art can make other variations or modifications based on the above description. It is neither necessary nor possible to exhaustively describe all embodiments here. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the claims of the present invention.
Claims
1. An optimal segmentation method for detecting product appearance defects, characterized in that, include: S1: Obtain product appearance images and actual categories of appearance defects; S2: Input the appearance image into the existing block-based defect detection algorithm, and set the block parameters and the number of evaluations; S3: Based on the block parameters, perform block-level defect detection to obtain block-level and pixel-level detection results; S4: Compare the block-level detection results and pixel-level detection results with the true categories of appearance defects, determine the classification attributes of the block-level detection results and pixel-level detection results, and calculate the number of each classification attribute; S5: Based on the number of classification attributes in the block-level detection results and pixel-level detection results, calculate the block-level false detection rate, pixel-level false detection rate, false detection rate parameter, false detection balance parameter, and false detection amplification parameter; S6: Set the evaluation function based on the block-level false detection rate, pixel-level false detection rate, false detection rate parameter, false detection balance parameter, and false detection amplification parameter, and calculate the final evaluation result; S7: Update the block parameters, repeat steps S3-S6, and proceed with the next round of evaluation to obtain the final evaluation result for each block parameter until the number of evaluations is reached. S8: Compare the magnitude of the final evaluation result corresponding to each block parameter. When the value of the final evaluation result is the largest, the corresponding block parameter is the optimal block parameter.
2. The optimal segmentation method for product appearance defect detection according to claim 1, characterized in that, In step S4, the block-level detection results and pixel-level detection results are compared with the true categories of appearance defects to determine the classification attributes of the block-level and pixel-level detection results, and the specific orientation of the quantity of each classification attribute is calculated as follows: The actual category of appearance defects is either "defect present" or "defect not present"; The block-level detection results are compared with the true categories of appearance defects to obtain the classification attributes of the block-level detection results: when the block-level detection result of the appearance image is "defect exists" and the true category of appearance defect is "defect exists", the classification attribute of the block-level detection result is "block-level true positive", and the number is denoted as BTP; when the block-level detection result of the appearance image is "defect exists" and the true category of appearance defect is "defect does not exist", the classification attribute of the block-level detection result is "block-level false positive", and the number is denoted as BFP; when the block-level detection result of the appearance image is "defect does not exist" and the true category of appearance defect is "defect exists", the classification attribute of the block-level detection result is "block-level false negative", and the number is denoted as BFN. When the block-level detection result of the appearance image is no defect and the true category of appearance defect is no defect, the classification attribute of the block-level detection result is a block-level true negative example, and the number is denoted as BTN. Using the same method, the pixel-level detection results are compared with the true categories of appearance defects to obtain the classification attributes of the pixel-level detection results, including: pixel-level true positives, pixel-level false negatives, pixel-level false positives, and pixel-level true negatives. The quantities are denoted as PTP, PTN, PFP, and PTN, respectively.
3. The optimal segmentation method for product appearance defect detection according to claim 2, characterized in that, The specific method for calculating the block-level false detection rate based on the number of classification attributes in the block-level and pixel-level detection results is as follows: In the formula, BFDR represents the block-level false positive rate, BFP represents the number of block-level false positives, and BTN represents the number of block-level true negatives.
4. The optimal segmentation method for product appearance defect detection according to claim 3, characterized in that, The specific method for calculating the pixel-level false detection rate based on the classification attributes of block-level and pixel-level detection results is as follows: In the formula, PFDR represents the pixel-level false positive rate, PFP represents the number of pixel-level false positives, and PTN represents the number of pixel-level true negatives.
5. The optimal segmentation method for detecting product appearance defects according to claim 4, characterized in that, The specific method for calculating the false detection rate parameter based on the classification attributes of block-level and pixel-level detection results is as follows: In the formula, α represents the false detection rate parameter.
6. The optimal segmentation method for detecting product appearance defects according to claim 5, characterized in that, The specific method for calculating the false detection balance parameter based on the classification attributes of block-level and pixel-level detection results is as follows: In the formula, β represents the false detection balance parameter, c represents the first contraction factor, and b represents the second contraction factor.
7. The optimal segmentation method for product appearance defect detection according to claim 6, characterized in that, The specific method for calculating the false detection amplification parameter based on the classification attributes of block-level and pixel-level detection results is as follows: In the formula, γ represents the false detection amplification parameter.
8. The optimal segmentation method for product appearance defect detection according to claim 7, characterized in that, In step S6, the evaluation function is set based on the block-level false detection rate, pixel-level false detection rate, false detection rate parameter, false detection balance parameter, and false detection amplification parameter. The specific method for calculating the final evaluation result is as follows: The evaluation function is: In the formula, L represents the final evaluation result, t represents the detection time of the block-based defect detection algorithm, λ represents the first reduction factor, and θ represents the second reduction factor.
9. An optimal detection method for product appearance defects, based on the optimal block-based method for product appearance defect detection according to any one of claims 1-8, characterized in that, include: S1: Obtain product appearance images and actual categories of appearance defects; S2: Input the appearance image into the existing block-based defect detection algorithm, and set the block parameters and the number of evaluations; S3: Based on the block parameters, perform block-level defect detection to obtain block-level and pixel-level detection results; S4: Compare the block-level detection results and pixel-level detection results with the true categories of appearance defects, determine the classification attributes of the block-level detection results and pixel-level detection results, and calculate the number of each classification attribute; S5: Based on the number of classification attributes in the block-level detection results and pixel-level detection results, calculate the block-level false detection rate, pixel-level false detection rate, false detection rate parameter, false detection balance parameter, and false detection amplification parameter; S6: Set the evaluation function based on the block-level false detection rate, pixel-level false detection rate, false detection rate parameter, false detection balance parameter, and false detection amplification parameter, and calculate the final evaluation result; S7: Update the block parameters, repeat steps S3-S6, and proceed with the next round of evaluation to obtain the final evaluation result for each block parameter until the number of evaluations is reached. S8: Compare the magnitude of the final evaluation result corresponding to each block parameter. When the value of the final evaluation result is the largest, the corresponding block parameter is the optimal block parameter. S9: Return the optimal segmentation parameters to the existing segmentation-based defect detection algorithm, and use the optimal segmentation parameters to segment the product appearance image to be detected into blocks to obtain the optimal defect detection result.
10. An optimal detection system for detecting product appearance defects, based on the optimal detection method described in claim 9, characterized in that, include: The image acquisition module is used to acquire images of the product's appearance and the actual categories of appearance defects. The detection algorithm module is used to input the appearance image into the existing block-based defect detection algorithm and set the block parameters and the number of evaluations; The detection execution module performs block-level defect detection based on the block parameters, and obtains block-level detection results and pixel-level detection results. The results classification module is used to compare the block-level detection results and pixel-level detection results with the true categories of appearance defects, determine the classification attributes of the block-level detection results and pixel-level detection results, and calculate the number of each classification attribute. The evaluation parameter calculation module calculates the block-level false detection rate, pixel-level false detection rate, false detection rate parameter, false detection balance parameter, and false detection amplification parameter based on the number of classification attributes in the block-level detection results and pixel-level detection results. The evaluation function module sets the evaluation function based on the block-level false detection rate, pixel-level false detection rate, false detection rate parameter, false detection balance parameter, and false detection amplification parameter, and calculates the final evaluation result. The block parameter update module is used to update the block parameters and send them to the detection execution module for the next round of evaluation, until the number of evaluations is reached. The comparison module is used to compare the size of the final evaluation result corresponding to each block parameter. When the value of the final evaluation result is the largest, the corresponding block parameter is the optimal block parameter. The parameter transmission module returns the optimal block parameters to the block-based defect detection algorithm in the detection algorithm module. The detection execution module uses the optimal block parameters to divide the product appearance image to be detected into blocks, performs defect detection, and obtains the optimal defect detection result.