Image detection method and image detection device

By combining gradient algorithm and random Hough algorithm, the problem of low efficiency in detecting line segment defects in arbitrary directions in existing technology is solved, realizing efficient and accurate scratch defect detection, applicable to various image types, and meeting the online inspection needs of production and processing processes.

CN116309287BActive Publication Date: 2026-01-30BEIJING LUSTER LIGHTTECH
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202211708512.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-29
Publication Date
2026-01-30
Estimated Expiration
2042-12-29

AI Technical Summary

Technical Problem

Existing technologies are insufficient for quickly and effectively detecting line segment defects in any direction, especially discontinuous shallow scratches, and their detection efficiency and effectiveness are poor, failing to meet the online inspection requirements of production and processing processes.

Method used

A combined gradient-based algorithm and a randomized Hough algorithm are used to extract defective line segments from the image under test through edge masking and adaptive gradient thresholding. This includes edge extraction, edge masking, and randomized Hough algorithm processing, optimizing the detection process to adapt to different image types.

Benefits of technology

It significantly improves the efficiency and effectiveness of scratch defect detection, can efficiently detect line segment defects in any direction, reduces errors, and is suitable for products with plain backgrounds and patterns, achieving efficient online detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116309287B_ABST
    Figure CN116309287B_ABST
Patent Text Reader

Abstract

This application discloses an image detection method and an image detection device, belonging to the field of image processing technology. The image detection method includes: extracting edges from a test image based on a gradient algorithm to obtain a first gradient map; applying an edge mask to the first gradient map to obtain a binary map; and processing the binary map using a random Hough algorithm and a growth algorithm to obtain defect line segments in the test image. The image detection method of this application, by adding a masking stage, makes the algorithm more adaptable and significantly broadens the application scenarios of scratch detection. By combining adaptive gradient thresholding with random Hough, it achieves high execution efficiency and can extract discontinuous shallow scratch defects, effectively improving the efficiency and effectiveness of scratch defect detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of image processing technology, and in particular relates to an image detection method and an image detection device. Background Technology

[0002] For image detection of scratch-like defects, grayscale camera imaging is generally used, taking advantage of the higher grayscale values ​​at the scratch location for defect detection. This can be achieved by projecting the image in the same direction to find outliers in the projection. However, this method cannot solve the problem of detecting line segment defects in arbitrary directions, limiting its applicability. Identifying all defects within the same image often requires projecting from different directions to obtain the corresponding line segment defects, and then determining the defective line segment based on these defects. This affects detection efficiency and effectiveness, failing to meet the online inspection requirements of rapid manufacturing processes. Summary of the Invention

[0003] This application aims to address at least one of the technical problems existing in the prior art. To this end, this application proposes an image detection method and an image detection device to improve the defect detection effect and efficiency, which can extract discontinuous shallow scratches and has higher execution efficiency than current projection-based and deep learning-based methods.

[0004] In a first aspect, this application provides an image detection method, the method comprising:

[0005] Edge extraction is performed on the image under test based on the gradient algorithm to obtain the first gradient map;

[0006] Apply an edge mask to the first gradient map to obtain a binary map;

[0007] The binary image is processed by a random Hough algorithm and a growth algorithm to obtain the defect line segments in the image to be tested.

[0008] The image detection method of this application incorporates a masking stage, which makes the algorithm more adaptable and significantly expands the application scenarios of scratch detection. By adopting a combination of adaptive gradient thresholding and random Hough, the method has high execution efficiency and can extract discontinuous shallow scratch defects, effectively improving the detection efficiency and detection effect of scratch defects.

[0009] According to one embodiment of this application, the step of performing edge masking on the first gradient map to obtain a binary map includes:

[0010] Based on the type of the image to be tested, obtain the target mask image;

[0011] The binary image is obtained based on the difference between the first gradient image and the target mask image;

[0012] The type of image to be tested includes images with templates or images without templates.

[0013] According to one embodiment of this application, obtaining the target mask image based on the type of the image to be tested includes:

[0014] If the image to be tested has a template image, gradient processing and grayscale dilation are performed on the template image to obtain the target mask image.

[0015] According to the image detection method provided in the embodiments of this application, a target mask image is obtained by performing gradient processing and grayscale dilation on the template image. It only needs to be calculated once before detecting the image to be tested, and similar images to be tested can be reused, thereby realizing a parallel and accelerated detection method, significantly reducing operation steps and improving detection efficiency.

[0016] According to one embodiment of this application, obtaining the target mask image based on the type of the image to be tested includes:

[0017] In the case where there is no template image for the image to be tested, a time-series image sequence is obtained. The time-series image sequence includes multiple images to be tested corresponding to multiple products to be tested, and the multiple products to be tested are of the same type.

[0018] The time-series image sequence is overlaid to obtain a high-value image and a low-value image of the target pattern region in the time-series image sequence.

[0019] The target mask image is determined based on the high-value image and the low-value image.

[0020] According to the image detection method provided in the embodiments of this application, by superimposing time-series image sequences to obtain a target mask image, it is possible to shield the defect features of pattern edges and line segments of image texture changes, thereby highlighting the defect features of the obtained binary image, reducing errors, and helping to improve the detection effect.

[0021] According to one embodiment of this application, the step of edge extraction of the image to be tested based on a gradient algorithm to obtain a first gradient map includes:

[0022] The first operator is used to extract the horizontal edge of the image under test to obtain the second gradient map;

[0023] The second operator is used to extract the vertical edge of the image under test to obtain the third gradient map;

[0024] The first gradient map is obtained by summing the second gradient map and the third gradient map.

[0025] According to the image detection method provided in the embodiments of this application, by using a first operator and a second operator to obtain a first gradient map, the filtering effect can be significantly weakened compared with the gradient map obtained by the Sobel operator, making shallow defects easier to appear, and the execution efficiency can be doubled, thereby helping to improve detection efficiency and detection effect.

[0026] According to one embodiment of this application, the step of processing the binary image using a random Hough algorithm and a growth algorithm to obtain defect line segments in the image to be tested includes:

[0027] Extract multiple white points from the binary image;

[0028] The target white point among the plurality of white points is converted to Hough space to generate a first feature point, and the number of the first feature points generated is recorded. The target white point is a point randomly determined from the plurality of white points.

[0029] If the number of the first feature points is greater than the target threshold, feature line segments are obtained by growing from the first feature points to both ends.

[0030] If the feature line segment meets the target conditions, the feature line segment is identified as the defective line segment;

[0031] The target conditions include at least one of the first target line segment length and the second target line segment length.

[0032] According to the image detection method provided in the embodiments of this application, defective line segments are obtained based on binary images using an optimized Hough line-finding algorithm. The line-finding speed is high, and the accuracy and precision of the finally determined defective line segments are high, which significantly improves the detection efficiency and effect of defective line segments, and realizes the finding of line segment defects with extremely low time cost.

[0033] According to one embodiment of this application, after determining the feature line segment as the defective line segment, the method includes:

[0034] Add the defective line segment to the defect set;

[0035] If the number of line segments in the defect set meets the target number of defects, output the defect location information.

[0036] Secondly, this application provides an image detection apparatus, which includes:

[0037] The first processing module is used to perform edge extraction on the image to be tested based on the gradient algorithm to obtain the first gradient map;

[0038] The second processing module is used to perform edge masking on the first gradient map to obtain a binary map;

[0039] The third processing module is used to process the binary image using the random Hough algorithm and the growth algorithm to obtain the defect line segments in the image to be tested.

[0040] The image detection apparatus of this application, by adding a mask stage, makes the algorithm more adaptable and significantly broadens the application scenarios of scratch detection. By adopting an adaptive gradient threshold and a random Hough algorithm, it has high execution efficiency and can extract discontinuous shallow scratch defects, effectively improving the detection efficiency and detection effect of scratch defects.

[0041] Thirdly, this application provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the image detection method as described in the first aspect above.

[0042] Fourthly, this application provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the image detection method as described in the first aspect above.

[0043] Fifthly, this application provides a chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the image detection method as described in the first aspect.

[0044] In a sixth aspect, this application provides a computer program product, including a computer program that, when executed by a processor, implements the image detection method as described in the first aspect above.

[0045] The above-described one or more technical solutions in the embodiments of this application have at least one of the following technical effects:

[0046] By adding a mask stage, the algorithm becomes more adaptable, significantly expanding the application scenarios of scratch detection. By combining adaptive gradient thresholding with random Hough, the algorithm achieves high execution efficiency and can extract discontinuous shallow scratch defects, effectively improving the efficiency and effectiveness of scratch defect detection.

[0047] Furthermore, by using the first operator and the second operator to obtain the first gradient map, compared with the gradient map obtained by the Sobel operator, the filtering effect can be significantly weakened, making shallow defects easier to appear, and the execution efficiency can be doubled, thereby helping to improve detection efficiency and detection effect.

[0048] Furthermore, by combining adaptive gradient thresholding with random Hough, the algorithm's detection capability can be improved, application scenarios can be broadened, and the interference of pattern edges in the first gradient image on the detection of shallow defects in line segments can be effectively eliminated. This highlights the defect features of the acquired binary image, reduces errors, and thus improves the accuracy and precision of subsequent defect output results, thereby enhancing the quality of the output detection image.

[0049] Furthermore, by using an optimized Hough line-finding algorithm to obtain defect line segments based on binary images, the line-finding speed is high, and the accuracy and precision of the finally determined defect line segments are relatively high, which significantly improves the detection efficiency and effect of defect line segments, and enables the finding of line segment defects at a very low time cost.

[0050] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description

[0051] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which:

[0052] Figure 1 This is one of the flowcharts illustrating the image detection method provided in the embodiments of this application;

[0053] Figure 2 This is a second schematic flowchart of the image detection method provided in the embodiments of this application;

[0054] Figure 3 This is the third schematic flowchart of the image detection method provided in the embodiments of this application;

[0055] Figure 4 This is the fourth flowchart illustrating the image detection method provided in the embodiments of this application;

[0056] Figure 5 This is a schematic diagram of the structure of the image detection device provided in the embodiments of this application;

[0057] Figure 6 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application;

[0058] Figure 7 This is a schematic diagram illustrating the effect of the image detection method provided in the embodiments of this application. Detailed Implementation

[0059] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.

[0060] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.

[0061] In related technologies, the detection of scratch-like defects mainly includes the following methods:

[0062] Firstly, projection-based methods project the image in one direction and find outliers in the projection. However, this method cannot solve the problem of detecting line segment defects in arbitrary directions, which greatly limits its application scenarios and thus affects detection efficiency.

[0063] Secondly, based on various transformation methods, such as wavelet transform, Hough transform, and Radon transform, this method has poor detection accuracy and precision, resulting in poor detection performance.

[0064] Thirdly, classification-based methods, such as SVM, K-means, and decision tree classification, are used to classify suspected defect areas to obtain accurate line segment scratch features. However, this method requires the use of other pre-processing algorithms to obtain the approximate defect location, which is quite complicated and affects the detection efficiency.

[0065] Fourth, the method based on deep convolutional neural networks uses a large number of images with line segment features to train a detection model for detecting line segment defects. This method involves a large number of algorithms, resulting in long computation time and thus affecting detection efficiency.

[0066] Fifth, the algorithm library combination method guides the algorithm to select a certain algorithm and a combination of several algorithms during operation through human teaching, based on different line segment defect characteristics. This method requires a lot of manual assistance, resulting in high labor costs and low detection efficiency.

[0067] None of the above methods can meet the online testing requirements of rapid production and processing technologies.

[0068] The image detection method, image detection device, electronic device, and readable storage medium provided in this application will be described in detail below with reference to the accompanying drawings and through specific embodiments and application scenarios.

[0069] The image detection method provided in this application can be executed by an image detection device, a server, or a user terminal, including but not limited to mobile phones, tablets, and computers.

[0070] It should be noted that this image detection method is applied to shallow scratch detection scenarios.

[0071] like Figure 1 As shown, the image detection method includes steps 110, 120 and 130.

[0072] Step 110: Extract edges from the image under test using a gradient algorithm to obtain the first gradient map;

[0073] In this step, the image to be tested is the image acquired by image acquisition of the product to be tested.

[0074] The product to be tested is one that requires defect detection.

[0075] It should be noted that the image to be tested may or may not include a pattern. A pattern refers to a feature on the surface of the product under test that distinguishes it from the background image, excluding defect features.

[0076] In actual implementation, the first gradient graph can be determined by the corresponding operator. The operator can be a user-defined operator, or it can be the Sobel operator, or it can be any other implementable operator, such as the Lapacian operator, the Roberts operator, and the Prewitt operator, etc. This application does not limit it.

[0077] The implementation of step 110 will be explained below using a user-defined operator as an example.

[0078] In some embodiments, step 110 may include:

[0079] The first operator is used to extract the horizontal edge of the image under test to obtain the second gradient map;

[0080] The second operator is used to extract the vertical edge of the image under test and obtain the third gradient map.

[0081] Summing the second and third gradient maps yields the first gradient map.

[0082] In this embodiment, the first operator and the second operator are user-defined operators.

[0083] Where the first operator is a 2*3 operator, such as... The second operator is a 3*2 operator, such as...

[0084] The second gradient plot is the gradient plot in the horizontal direction, and the third gradient plot is the gradient plot in the vertical direction.

[0085] In actual implementation, two operators, 2*3 and 3*2, are used. and The second gradient map in the horizontal direction and the third gradient map in the vertical direction can be obtained separately; then the absolute values ​​of the two gradient maps are added together to obtain the gradient map in all directions, that is, the first gradient map.

[0086] According to the image detection method provided in the embodiments of this application, by using a first operator and a second operator to obtain a first gradient map, the filtering effect can be significantly weakened compared with the gradient map obtained by the Sobel operator, making shallow defects easier to appear, and the execution efficiency can be doubled, thereby helping to improve detection efficiency and detection effect.

[0087] Step 120: Apply edge masking to the first gradient map to obtain a binary map;

[0088] In this step, an edge mask is applied to the first gradient image to remove other features in the first gradient image that are not related to the defect features, thereby obtaining a binary image.

[0089] In actual execution, an edge mask can be applied to the first gradient map by setting an adaptive threshold (i.e., the target mask map) to obtain a binary map.

[0090] The target mask can be any implementable mask. For example, the target mask can be a mask determined by the template gradient method, or a mask determined by the temporal image fluctuation method, or an adaptive threshold determined by methods such as filtering, pattern partitioning, and deep learning. This application does not limit the specific implementation of the target mask.

[0091] In this step, by adding a mask stage, the interference of pattern edges on the detection of shallow defects in line segments can be effectively eliminated. It is applicable to both pure background products and patterned products, has a wide range of application scenarios, and has good detection results.

[0092] In some embodiments, step 120 may include:

[0093] Based on the type of the image to be tested, obtain the target mask image;

[0094] A binary image is obtained based on the difference between the first gradient image and the target mask image;

[0095] The types of images to be tested include those with templates or those without templates.

[0096] In this embodiment, the type of image to be tested includes an image with a template or an image without a template.

[0097] The template image is an image with the same pattern as the image under test but without defect features, provided that the image under test includes a pattern.

[0098] It is understandable that the method of obtaining the target mask image will differ depending on whether the image under test has a template image or not.

[0099] For example, the target mask map can be a mask map determined by the template gradient method, or it can be a mask map determined by the temporal image fluctuation method.

[0100] After obtaining the target mask image, the difference between the first gradient image and the target mask image is calculated and subtracted from the adaptive threshold. This removes the interference of the pattern edge in the first gradient image on the detection of shallow defects in line segments, highlights the defect features of the obtained binary image, and reduces the error.

[0101] In this application, by providing multiple adaptive thresholds to select the appropriate adaptive threshold based on the type of the image to be tested, and by combining gradient with adaptive threshold, the detection capability of the algorithm can be significantly improved, and shallow defects of line segments with a length of more than 50 pixels, a width of more than 1 pixel, and a contrast of more than 5 can be detected.

[0102] The image detection method provided in the embodiments of this application can improve the detection capability of the algorithm and broaden the application scenarios by adopting a combination of gradient and adaptive threshold. It can effectively eliminate the interference of pattern edges in the first gradient image on the detection of shallow defects in line segments, highlight the defect features of the acquired binary image, reduce errors, thereby improving the accuracy and precision of subsequent defect output results and improving the effect of the output detection image.

[0103] The following sections will explain how to determine the target mask image from two different implementation perspectives.

[0104] Firstly, determination based on template gradient.

[0105] like Figure 2 As shown, in some embodiments, obtaining a target mask image based on the type of the image to be tested may include: if the image to be tested has a template image, performing gradient processing and grayscale dilation on the template image to obtain the target mask image.

[0106] In this embodiment, during the detection preparation stage, a defect-free image can be obtained as a template image, and gradient map calculation can be performed on the template image.

[0107] For example, when the template image is a color image, gradient processing can be used to obtain sub-gradient images corresponding to three channels. The three sub-gradient images are superimposed, and the maximum value at the same position is taken to obtain a fourth gradient image. Then, grayscale dilation is performed on the fourth gradient image to obtain the target mask image.

[0108] According to the image detection method provided in the embodiments of this application, a target mask image is obtained by performing gradient processing and grayscale dilation on the template image. It only needs to be calculated once before detecting the image to be tested, and similar images to be tested can be reused, thereby realizing a parallel and accelerated detection method, significantly reducing operation steps and improving detection efficiency.

[0109] Secondly, determination based on time-series image fluctuations.

[0110] like Figure 3 As shown, in some embodiments, obtaining a target mask image based on the type of the image to be tested may include:

[0111] In the absence of a template image for the image to be tested, a time-series image sequence is obtained. The time-series image sequence includes multiple images to be tested corresponding to multiple products to be tested, and the multiple products to be tested are of the same type.

[0112] The time-series image sequence is overlaid to obtain the high-value map and low-value map of the target pattern region in the time-series image sequence;

[0113] The target mask image is determined based on the high-value map and the low-value map.

[0114] In this embodiment, the time-series image sequence is an image sequence formed by image frames corresponding to multiple products of the same type as the product under test, acquired under the same acquisition environment.

[0115] Among them, products of the same type have the same pattern, the same background image, and the same size and shape.

[0116] Understandably, in practical applications, multiple products of the same type may exist on the same production line. The process involves acquiring and aligning product images for each product, then generating a time-series image sequence based on these images. This time-series image sequence is used to determine the target mask image for the product of the corresponding type.

[0117] The target pattern area is the area corresponding to any pattern.

[0118] In actual execution, a series of product images of the product to be tested can be used as a sequence input, different image frames can be superimposed, and high-value images and low-value images of different pattern areas can be obtained based on the fluctuation of pixel values ​​at the same position. These high-value images and low-value images can then be used as masks.

[0119] In this embodiment, by superimposing the time-series image sequence, the translation error generated by the superposition can be used to make the high and low value threshold ranges larger at the image edges and smaller in the solid color area. This allows the mask to obtain line segment defect features that shield the pattern edges and image texture changes, thereby highlighting the defect features of the acquired binary image and reducing errors.

[0120] According to the image detection method provided in the embodiments of this application, a target mask image is obtained by superimposing a time-series image sequence generated from product images corresponding to multiple products of the same type. This method can shield the defect features of line segments with pattern edges and image texture changes, thereby highlighting the defect features of the obtained binary image, reducing errors, and helping to improve the detection effect.

[0121] Step 130: Process the binary image using the random Hough algorithm and the growth algorithm to obtain the defect line segments in the image to be tested.

[0122] In this step, the Hough algorithm is an optimized version.

[0123] In actual execution, an i7-6700k processor and 16GB of memory can be used, which can process 100 8k*4k color images or 250 8k*4k grayscale images per second, resulting in high computing efficiency.

[0124] It should be noted that the random Hough algorithm in this application has a fast execution speed. For an 8k*4k color image, using an i7-6700k processor and 16GB of memory, the average execution time is only 10ms, and the longest time is no more than 15ms.

[0125] In this application, by adding a mask stage, the interference of pattern edges in the first gradient image on the detection of shallow defects in line segments can be effectively eliminated. It is applicable to both pure background products and patterned products, and is applicable to the detection of line segment defects in any direction. It has a wide range of application scenarios and has good detection capability for shallow defects in line segments that are visible to the human eye. It can detect defective line segments without taking multiple images, and has good detection effect and high detection efficiency.

[0126] By combining adaptive gradient thresholding with random Hough, the algorithm's detection capability can be improved, application scenarios can be broadened, the interference of pattern edges in the first gradient image on the detection of shallow defects in line segments can be effectively eliminated, the defect features of the acquired binary image can be highlighted, and errors can be reduced, thereby improving the accuracy and precision of subsequent defect output results and enhancing the effect of the output detection image.

[0127] The image detection method provided in the embodiments of this application, by adding a mask stage, makes the algorithm more adaptable and significantly broadens the application scenarios of scratch detection. By adopting an adaptive gradient threshold combined with random Hough, the execution efficiency is high and it can extract discontinuous shallow scratch defects, effectively improving the scratch defect detection efficiency and detection effect.

[0128] like Figure 4 As shown, in some embodiments, step 130 may include:

[0129] Extract multiple white points from a binary image;

[0130] The target white point among multiple white points is transformed into Hough space to generate the first feature point, and the number of the first feature points generated is recorded. The target white point is a point randomly determined from multiple white points.

[0131] If the number of first feature points is greater than the target threshold, feature line segments are obtained by growing from the first feature points to both ends.

[0132] If the feature line segment meets the target conditions, the feature line segment is identified as a defective line segment;

[0133] The target conditions include at least one of the first target line segment length and the second target line segment length.

[0134] In this embodiment, the white dots correspond to coordinate values.

[0135] The target white point can be any white point from multiple white points, and can be randomly selected using a random algorithm.

[0136] The target threshold is used to determine whether the number of the first feature points meets the requirements.

[0137] The target threshold can be user-defined, and this application does not impose any restrictions.

[0138] The target conditions include at least one of the first target line segment length and the second target line segment length.

[0139] The first target line segment length is the preset length that the generated feature line segment must meet.

[0140] The second target line segment length is the preset length that the remaining length of the generated feature line segment after removing the breakpoints must satisfy.

[0141] In actual execution, a target white point is randomly selected from multiple white points and converted into Hough space to generate the first feature point. This step is repeated until the number of generated first feature points exceeds the target threshold. Then, the next step is to grow from the first feature point to both ends to obtain feature line segments.

[0142] In some embodiments, determining a feature segment as a defective segment when the feature segment meets the target conditions may include: determining the feature segment as a defective segment when the total length of the feature segment meets the first target segment length and the actual length of the feature segment meets the second target segment length.

[0143] In this embodiment, the target conditions include the first target line segment length and the second target line segment length.

[0144] The total length of a feature line segment is the length between its two endpoints.

[0145] The actual length of a feature line segment is the remaining length after removing the breakpoints in the feature line segment.

[0146] For example, continue to refer to Figure 4 In actual execution, a binary image is input. First, the coordinates of the white points in the binary image are extracted. Then, a point is randomly selected from the extracted white points and transferred to the Hough space to generate the first feature point. As long as there is a first feature point greater than the target threshold, growth begins to extend to both ends to generate feature line segments. After the growth is completed, it is determined whether the total length and actual length of the feature line segment meet the target conditions. If the target conditions are met, a shallow defect (i.e., a defective line segment) is found.

[0147] Continue to refer to Figure 4 In some embodiments, after identifying the feature segment as a defective segment, the method may further include:

[0148] Add the defective line segment to the defect set;

[0149] If the number of line segments in the defect set meets the target number of defects, output the defect location information.

[0150] In this embodiment, the defect set is a collection that stores all feature line segments that satisfy the target conditions.

[0151] Defect location information is used to characterize the location of the defect in the product under test.

[0152] The defect location information is determined based on the coordinates of the target white point.

[0153] The number of target defects can be customized based on requirements such as the actual output image precision, and this application does not impose any limitations.

[0154] According to the image detection method provided in the embodiments of this application, after determining the defect line segment, the defect location information is further generated by extracting the coordinate values ​​of the target white point, and the defect location information is output to realize defect detection, which has high detection accuracy and detection rate.

[0155] In other embodiments, when the number of line segments in the defect set does not meet the target number of defects, the actual number of points is obtained.

[0156] If the actual number of sampling points exceeds the preset number of sampling points, output the defect location information;

[0157] If the actual number of points taken does not exceed the preset number of points, update the target white point.

[0158] In this embodiment, if the actual number of points taken does not exceed the preset number of points taken, the target white point is reselected and the re-extracted target white point is transferred to the Hough space to generate the first feature point; then the first feature point is compared with the target threshold. For the first feature point that is greater than the target threshold, it starts to grow towards both ends to generate feature line segments; after the growth is completed, it is determined whether the length of the feature line segment and the number of points on the line segment meet the target conditions; if the target conditions are met, a shallow defect in the line segment (i.e., the defect line segment) is found, and so on. This application will not elaborate further here.

[0159] In some embodiments, after obtaining feature line segments by growing from the first feature point to both ends, the method may further include:

[0160] If the total length of the feature line segments meets the first target line segment length, but the actual length of the feature line segments does not meet the second target line segment length, obtain the actual number of points taken.

[0161] If the actual number of sampling points exceeds the preset number of sampling points, output the defect location information;

[0162] If the actual number of points taken does not exceed the preset number of points, update the target white point.

[0163] In this embodiment, after obtaining feature line segments by growing from the first feature point to both ends, it can be further determined whether the total length of the feature line segments meets the first target line segment length. If the first target line segment length is met, it can be determined whether the actual length of the feature line segments meets the second target line segment length. If the first target line segment length is not met, the actual number of points is obtained and compared with the preset number of points.

[0164] If the actual number of points taken exceeds the preset number of points, the defect location information will be output and the process will end.

[0165] If the actual number of points taken does not exceed the preset number of points, the target white point is reselected and the above steps are repeated. This application will not elaborate on this.

[0166] In some embodiments, after obtaining feature line segments by growing from the first feature point to both ends, the method may further include:

[0167] If the total length of the feature line segments does not meet the length of the first target line segment, obtain the actual number of points taken;

[0168] If the actual number of sampling points exceeds the preset number of sampling points, output the defect location information;

[0169] If the actual number of points taken does not exceed the preset number of points, update the target white point.

[0170] In this embodiment, if the actual number of points taken does not exceed the preset number of points taken, the target white point is updated and the subsequent steps are repeated.

[0171] In some embodiments, if the first feature point is not greater than the target threshold, the actual number of points taken is obtained;

[0172] If the actual number of sampling points exceeds the preset number of sampling points, output the defect location information;

[0173] If the actual number of points taken does not exceed the preset number of points, update the target white point.

[0174] For example, continue to refer to Figure 4 In actual execution, after the growth is completed, it is determined whether the total length and actual length of the feature line segment meet the target conditions; if the target conditions are not met, the algorithm continues to randomly select white points until a limited number of points are selected or a sufficient number of line segments are found, at which point the algorithm exits.

[0175] It should be noted that in this application, by optimizing the random Hough line finding algorithm, the algorithm execution speed is significantly improved. For an 8k*4k color image, using an i7-6700k processor and 16GB of memory, the average time is only 10ms, and the longest time is no more than 15ms.

[0176] like Figure 7 An example of an effect illustration is provided, in which... Figure 7 (a) is the image to be tested. Figure 7 (b) is the target mask image; Figure 7 (c) is the defect feature map (i.e., the binary map). Figure 7 (d) shows the hough connection results. It can be seen that the method provided in this application has a good detection effect.

[0177] According to the image detection method provided in the embodiments of this application, defective line segments are obtained based on binary images using an optimized Hough line-finding algorithm. The line-finding speed is high, and the accuracy and precision of the finally determined defective line segments are high, which significantly improves the detection efficiency and effect of defective line segments, and realizes the finding of line segment defects with extremely low time cost.

[0178] The image detection method provided in this application can be executed by an image detection device. This application uses an image detection device executing the image detection method as an example to illustrate the image detection device provided in this application.

[0179] This application also provides an image detection device.

[0180] like Figure 5 As shown, the image detection device includes: a first processing module 510, a second processing module 520 and a third processing module 530.

[0181] The first processing module 510 is used to perform edge extraction on the image to be tested based on a gradient algorithm to obtain a first gradient map.

[0182] The second processing module 520 is used to perform edge masking on the first gradient map to obtain a binary map;

[0183] The third processing module 530 is used to process the binary image using the Hough algorithm and the growth algorithm to obtain the defect line segments in the image to be tested.

[0184] The image detection device provided in the embodiments of this application, by adding a mask stage, makes the algorithm more adaptable and significantly broadens the application scenarios of scratch detection. By adopting a combination of adaptive gradient threshold and random Hough, it has high execution efficiency and can extract discontinuous shallow scratch defects, effectively improving the detection efficiency and detection effect of scratch defects.

[0185] In some embodiments, the second processing module 520 may also be used for:

[0186] Based on the type of the image to be tested, obtain the target mask image;

[0187] A binary image is obtained based on the difference between the first gradient image and the target mask image;

[0188] The types of images to be tested include those with templates or those without templates.

[0189] The image detection apparatus provided in the embodiments of this application, by adding a mask stage, makes the algorithm more adaptable and significantly improves the application scenarios of scratch detection. By adopting a combination of gradient and adaptive threshold, the detection rate and detection capability of the algorithm are effectively improved, thereby improving the defect detection effect and defect detection efficiency.

[0190] In some embodiments, the second processing module 520 may also be used for:

[0191] If a template image exists for the image to be tested, gradient processing and grayscale dilation are performed on the template image to obtain the target mask image.

[0192] The image detection apparatus provided in the embodiments of this application obtains the target mask image by performing gradient processing and grayscale dilation on the template image. It only needs to be calculated once before detecting the image to be tested, and similar images to be tested can be reused, thereby realizing a parallel and accelerated detection method, significantly reducing operation steps and improving detection efficiency.

[0193] In some embodiments, the second processing module 520 may also be used for:

[0194] In the absence of a template image for the image to be tested, a time-series image sequence is obtained. The time-series image sequence includes multiple images to be tested corresponding to multiple products to be tested, and the multiple products to be tested are of the same type.

[0195] The time-series image sequence is overlaid to obtain the high-value map and low-value map of the target pattern region in the time-series image sequence;

[0196] The target mask image is determined based on the high-value map and the low-value map.

[0197] The image detection apparatus provided in the embodiments of this application obtains a target mask image by superimposing a time-series image sequence. This can shield the defect features of pattern edges and line segments of image texture changes, thereby highlighting the defect features of the obtained binary image, reducing errors, and helping to improve the detection effect.

[0198] In some embodiments, the first processing module 510 may also be used for:

[0199] The first operator is used to extract the horizontal edge of the image under test to obtain the second gradient map;

[0200] The second operator is used to extract the vertical edge of the image under test and obtain the third gradient map.

[0201] Summing the second and third gradient maps yields the first gradient map.

[0202] According to the image detection apparatus provided in the embodiments of this application, by using a first operator and a second operator to obtain a first gradient map, the filtering effect can be significantly weakened compared to the gradient map obtained by the Sobel operator, making shallow defects easier to appear, and the execution efficiency can be doubled, thereby helping to improve detection efficiency and detection effect.

[0203] In some embodiments, the third processing module 530 may also be used for:

[0204] Extract multiple white points from a binary image;

[0205] The target white point among multiple white points is transformed into Hough space to generate the first feature point, and the number of the first feature points generated is recorded. The target white point is a point randomly determined from multiple white points.

[0206] If the number of first feature points is greater than the target threshold, feature line segments are obtained by growing from the first feature points to both ends.

[0207] If the feature line segment meets the target conditions, the feature line segment is identified as a defective line segment;

[0208] The target conditions include at least one of the first target line segment length and the second target line segment length.

[0209] The image detection device provided in the embodiments of this application obtains defective line segments based on binary images through an optimized Hough line-finding algorithm. It has a high line-finding speed and the accuracy and precision of the finally determined defective line segments are relatively high, which significantly improves the detection efficiency and effect of defective line segments, and realizes the finding of line segment defects at a very low time cost.

[0210] In some embodiments, the device may further include:

[0211] The fourth processing module is used to add the defective line segment to the defect set after the feature line segment is identified as a defective line segment;

[0212] The fifth processing module is used to output defect location information when the number of line segments in the defect set meets the target number of defects.

[0213] The image detection device in this application embodiment can be an electronic device or a component within an electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal or other devices besides a terminal. For example, the electronic device can be a mobile phone, tablet computer, laptop computer, PDA, in-vehicle electronic device, mobile internet device (MID), augmented reality (AR) / virtual reality (VR) device, robot, wearable device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc. It can also be a server, network attached storage (NAS), personal computer (PC), television set (TV), ATM, or self-service machine, etc. This application embodiment does not specifically limit the device.

[0214] The image detection device in this application embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit the specific operating system used.

[0215] The image detection device provided in this application embodiment can achieve... Figures 1 to 4 The various processes implemented in the method implementation examples will not be described again here to avoid repetition.

[0216] In some embodiments, such as Figure 6 As shown, this application embodiment also provides an electronic device 600, including a processor 601, a memory 602, and a computer program stored in the memory 602 and executable on the processor 601. When the program is executed by the processor 601, it implements the various processes of the above-described image detection method embodiment and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0217] It should be noted that the electronic devices in the embodiments of this application include the mobile electronic devices and non-mobile electronic devices described above.

[0218] This application also provides a non-transitory computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it implements the various processes of the above-described image detection method embodiments and achieves the same technical effect. To avoid repetition, it will not be described again here.

[0219] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.

[0220] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described image detection method.

[0221] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.

[0222] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the above-described image detection method embodiments and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0223] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.

[0224] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.

[0225] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.

[0226] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.

[0227] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "illustrative embodiment," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.

[0228] Although embodiments of this application have been shown and described, those skilled in the art will understand that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of this application, the scope of which is defined by the claims and their equivalents.

Claims

1. An image detection method characterized by, The method comprises: performing edge extraction on the to-be-tested image based on a gradient algorithm to obtain a first gradient image; performing edge mask on the first gradient image to obtain a binary image; performing random Hough algorithm and growth algorithm processing on the binary image to obtain a defect line segment in the to-be-tested image; the processing of the binary image by the random Hough algorithm and the growth algorithm to obtain the defect line segment in the to-be-tested image comprises: extracting a plurality of white points in the binary image; converting a target white point in the plurality of white points to a Hough space to generate a first feature point, and recording the number of the generated first feature points, the target white point being a point randomly determined from the plurality of white points; in a case where the number of the first feature points is greater than a target threshold, growing based on the first feature points to both ends to obtain a feature line segment; in a case where the feature line segment meets a target condition, determining the feature line segment as the defect line segment; wherein the target condition comprises at least one of a first target line segment length and a second target line segment length.

2. The image detection method according to claim 1, characterized in that, the processing of the first gradient image by the edge mask to obtain the binary image comprises: obtaining a target mask image based on the type of the to-be-tested image; obtaining the binary image based on the difference between the first gradient image and the target mask image; wherein the type of the to-be-tested image comprises a template image or no template image.

3. The image detection method according to claim 2, characterized in that, the obtaining of the target mask image based on the type of the to-be-tested image comprises: in a case where the to-be-tested image has a template image, performing gradient processing and gray scale dilation on the template image to obtain the target mask image.

4. The image detection method of claim 2, wherein, the obtaining of the target mask image based on the type of the to-be-tested image comprises: in a case where the to-be-tested image has no template image, obtaining a time sequence image sequence, the time sequence image sequence comprising to-be-tested images corresponding to a plurality of to-be-tested products, the plurality of to-be-tested products being the same type of products; performing superposition processing on the time sequence image sequence to obtain a high value image of a target pattern region and a low value image of the target pattern region in the time sequence image sequence; determining the target mask image based on the high value image and the low value image.

5. The image detection method according to any one of claims 1 to 4, characterized in that, the edge extraction on the to-be-tested image based on the gradient algorithm to obtain the first gradient image comprises: performing edge extraction on the to-be-tested image in a horizontal direction by using a first operator to obtain a second gradient image; performing edge extraction on the to-be-tested image in a vertical direction by using a second operator to obtain a third gradient image; summing the second gradient image and the third gradient image to obtain the first gradient image.

6. The image detection method according to any one of claims 1 to 4, characterized in that, after the feature line segment is determined as the defect line segment, the method further comprises: adding the defect line segment to a defect set; in a case where the number of line segments in the defect set meets a target defect number, outputting defect position information.

7. An image detection apparatus characterized by comprising: The method comprises: a first processing module configured to perform edge extraction on a to-be-tested image based on a gradient algorithm to obtain a first gradient image; a second processing module configured to perform edge mask on the first gradient image to obtain a binary image; a third processing module configured to perform random Hough algorithm and growth algorithm processing on the binary image to obtain a defect line segment in the to-be-tested image; The third processing module is configured to extract a plurality of white points in the binary image. The target white point among the plurality of white points is converted to a Hough space to generate a first feature point, and the number of the generated first feature points is recorded, wherein the target white point is a point randomly determined from the plurality of white points. In a case where the number of the first feature points is greater than a target threshold, the first feature points are grown to both ends based on the first feature points to obtain a feature line segment. In a case where the feature line segment satisfies a target condition, the feature line segment is determined as the defect line segment. The target condition includes at least one of a first target line segment length and a second target line segment length.

8. An electronic device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, The processor executes the program to implement the image detection method according to any one of claims 1-6. 9.A non-transitory computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the image detection method according to any one of claims 1-6.

Citation Information

Patent Citations

  • Method and apparatus for testing surface defect

    CN101256157A