A defect detection method, device, terminal device and storage medium

By determining the difference image of the initial and target prospect area in the weak defect detection, the problem of poor weak defect detection effect in the prior art is solved, and more efficient weak defect detection is achieved.

CN115797327BActive Publication Date: 2025-06-27BEIJING LUSTER LIGHTTECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211689608.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-27
Publication Date
2025-06-27
Estimated Expiration
2042-12-27

AI Technical Summary

Technical Problem

The existing weak defect detection methods are complex in the detection process or the detection results are incorrect, resulting in poor weak defect detection results.

Method used

By determining the initial foreground area of ​​the image to be detected, the initial grayscale value is mapped to the coordinate space, the discrete area is determined, and the target closed area and convex set area are determined based on the preset straight line area and the discrete area, thereby determining the target grayscale value and the target foreground area. Finally, a weak defect is determined based on the difference image between the initial foreground area and the target foreground area.

Benefits of technology

The grayscale difference between the weak defect and other parts of the image is enhanced, the effect of weak defect detection is improved, and the error rate of detection results is reduced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115797327B_ABST
    Figure CN115797327B_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of defect detection. Specifically, it relates to a defect detection method, device, terminal device, and storage medium, which can, to a certain extent, solve the problem of poor weak defect detection effect in the process of weak defect detection. Determine an initial foreground region in the image to be detected, map the initial gray values of each row or each column of pixel points in the initial foreground region to a discrete region of the coordinate space, determine the convex set region of the target closed region based on the preset straight line region and the discrete region in the coordinate space, and determine the target gray value corresponding to the initial gray value based on the coordinates of the outer contour points corresponding to the discrete region in the convex set region, and then determine the target foreground region; finally, based on the difference image between the initial foreground region and the target foreground region, weak defects can be determined; by the above process, the gray difference between the weak defects and other parts of the image is enhanced, and the weak defect detection effect in the process of weak defect detection is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of defect detection technology, and in particular to a defect detection method, apparatus, terminal device and storage medium. Background Art

[0002] In the field of industrial visual inspection, there is the detection of weak defects on the surface of products, which is usually achieved by inspecting images containing products. The main reasons for the formation of weak defects include low recognition of the defects themselves, and / or due to limitations such as product materials and optical imaging conditions when taking images, the defects are weakly imaged in the image. Among them, optical imaging condition limitations include uneven lighting, background interference, etc.

[0003] In the defect detection process, the image is usually preprocessed first to enhance the contrast between the defect (i.e., the foreground of the image) and the background. Then, the image is fitted by surface fitting to obtain the fitted image. The preprocessed image and the fitted image are then subtracted to eliminate the interference of uneven lighting on the defect. Among them, surface fitting is mainly achieved through high-order polynomial approximation.

[0004] However, when detecting weak defects in the above manner, if the order of the high-order polynomial used for surface fitting is high, the detection process calculation is more complicated, which may easily lead to erroneous detection results. If the order of the high-order polynomial used for surface fitting is low, there is no obvious difference between the preprocessed image and the fitted image, which may also lead to erroneous detection results. Therefore, the existing weak defect detection scheme has the problem of poor weak defect detection effect. Summary of the invention

[0005] In order to solve the technical problem of poor weak defect detection effect in the weak defect detection process, the present application provides a defect detection method, apparatus, terminal equipment and storage medium.

[0006] The embodiment of the present application is implemented as follows:

[0007] A first aspect of an embodiment of the present application provides a defect detection method, comprising the following steps:

[0008] Determine an initial foreground region of an image to be detected, where the image to be detected contains a weak defect;

[0009] Mapping the initial grayscale values ​​of each row or column of pixels in the initial foreground area to the coordinate space, and determining a discrete area in the coordinate space, wherein the discrete area is composed of the initial grayscale values ​​of the pixels;

[0010] Determine a target closed area in the coordinate space based on a preset straight line area and a discrete area in the coordinate space;

[0011] Determine the convex set region of the target closed region, and determine the target gray value corresponding to the initial gray value based on the coordinates of the outer contour points corresponding to the discrete region in the convex set region;

[0012] Based on the difference image between the initial foreground region and the target foreground region, determine the weak defects, where the target foreground region is determined by the target gray value.

[0013] A second aspect of the embodiments of the present application provides a defect detection device, including a foreground detection module, a first conversion module, a second conversion module, and a defect detection module, where:

[0014] The foreground detection module is configured to determine the initial foreground region of the image to be detected, and the image to be detected contains weak defects;

[0015] The first conversion module is configured to map the initial gray values of the pixel points in each row or each column of the initial foreground region to the coordinate space, and determine the discrete region in the coordinate space, where the discrete region is composed of the initial gray values of the pixel points;

[0016] The second conversion module is configured to determine the target closed region in the coordinate space based on the preset straight line region and the discrete region in the coordinate space; it is also configured to determine the convex set region of the closed region, and determine the target gray value corresponding to the initial gray value based on the coordinate space of the outer contour points corresponding to the discrete region in the convex set region;

[0017] The defect detection module is configured to determine the weak defects based on the difference image between the initial foreground region and the target foreground region, where the target foreground region is determined by the target gray value.

[0018] A third aspect of the embodiments of the present application provides a terminal device, including a memory and a processor, the memory stores a computer program, and when the processor executes the computer program, the steps of the defect detection method in the first aspect are implemented.

[0019] A fourth aspect of the embodiments of the present application provides a computer storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the processor is caused to execute the steps of the defect detection method in the first aspect.

[0020] Advantages of the present application: When the image to be detected contains weak defects, the initial foreground region of the image to be detected can be determined. The initial gray values of each row or column of pixel points in the initial foreground region are mapped to each discrete point in the coordinate space (corresponding to the initial gray value of the pixel point), and the discrete region in the coordinate space can be determined. Based on the preset straight-line region and the discrete region in the coordinate space, the target closed region in the coordinate space and the convex set region of the target closed region are determined, and based on the coordinates of the outer contour points corresponding to the discrete region in the convex set region, the target gray value corresponding to the initial gray value is returned, and then the target foreground region is determined. Finally, based on the difference image between the initial foreground region and the target foreground region, the weak defects can be determined. By the above method, the gray difference between the weak defects and other parts of the image is enhanced, and the detection effect of the weak defects in the weak defect detection process is improved. Description of the Drawings

[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the following drawings are some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.

[0022] Figure 1a Shows an example diagram of weak defects on the product surface;

[0023] Figure 1b Shows an example diagram of weak defects on the product surface;

[0024] Fig. 1c shows an example diagram of weak defects on the product surface;

[0025] Figure 2 Shows a schematic flow chart of a defect detection method provided by an embodiment of the present application;

[0026] Figure 3a Shows an example diagram of the image to be detected obtained in defect detection;

[0027] Figure 3b Shows for Figure 3a an example diagram of the initial foreground region of the image to be detected;

[0028] Figure 3c Shows Figure 3b a schematic diagram of the Nth row of pixel points in the initial foreground region;

[0029] Figure 3d Shows Figure 3c a schematic diagram of the mapped spatial coordinates;

[0030] Figure 3e ShowsFigure 3d Schematic diagram of the initial closed region determined by the discrete region and the preset straight line region;

[0031] Figure 3f Shows the removal of Figure 3e Schematic diagram of the target closed region after removing the interference in the discrete edge of the initial closed region;

[0032] Figure 3g Schematic diagram of the convex set region of the 3f target closed region;

[0033] Figure 3h Shows Figure 3g Schematic diagram of the target foreground region after the inverse transformation of the convex set region;

[0034] Figure 3i Shows Figure 3b The initial foreground region and Figure 3g Schematic diagram of the difference image determined by the target foreground region;

[0035] Figure 4 Schematic flowchart of determining the initial foreground region of a to-be-detected image in an embodiment of the present application;

[0036] Figure 5 Schematic flowchart of determining the target closed region in a coordinate space in an embodiment of the present application;

[0037] Figure 6 Schematic flowchart of determining weak defects based on the difference image in an embodiment of the present application;

[0038] Figure 7 Schematic flowchart of another defect detection method provided in an embodiment of the present application;

[0039] Figure 8 Schematic structural diagram of a defect detection device provided in an embodiment of the present application;

[0040] Among them, 100 - weak defect; 300 - to-be-detected image; 310 - initial foreground region; 320 - discrete region; 330 - initial closed region; 340 - target closed region; 350 - convex set region; 351 - contour point region; 360 - target foreground region; 370 - difference image. Detailed implementation manners

[0041] To make the objectives, implementation manners, and advantages of the present application clearer, the following will clearly and completely describe the exemplary implementation manners of the present application with reference to the accompanying drawings in the exemplary embodiments of the present application. Obviously, the described exemplary embodiments are only a part of the embodiments of the present application, rather than all the embodiments.

[0042] It should be noted that the brief description of terms in this application is only for facilitating the understanding of the following described embodiments, rather than intending to limit the embodiments of this application. Unless otherwise specified, these terms should be understood in their ordinary and common meanings.

[0043] In this application, terms such as "first", "second", "third", etc. in the specification, claims and the above-mentioned drawings are used to distinguish similar or like objects or entities, and do not necessarily mean to limit a specific order or sequence, unless otherwise noted. It should be understood that such terms can be interchanged under appropriate circumstances.

[0044] The terms "comprising" and "having" and any variations thereof are intended to cover but not exclusively include. For example, a product or device comprising a series of components does not necessarily have to be limited to all the components clearly listed, but may include other components not clearly listed or inherent to these products or devices.

[0045] Figure 1a 、 Figure 1b 、 Figure 1c All show example diagrams of weak defects on the product surface, such as Figure 1a 、 Figure 1b 、 Figure 1c shown, the weak defect 100 on the product surface may appear at any position on the surface with uneven illumination, and there may also be some specific interferences on the product surface.

[0046] In the related defect detection process, usually first, the image is preprocessed to enhance the contrast between the defect (i.e., the foreground of the image) and the background, then the fitted image is obtained by the method of surface fitting for the image, and then the preprocessed image and the fitted image are subtracted to eliminate the interference of uneven illumination on the defect.

[0047] Among them, surface fitting is mainly achieved by the way of high-order polynomial approximation, and the fitting accuracy is related to the order of the polynomial. If the order of the high-order polynomial for surface fitting is high, the detection process calculation is more complex and prone to errors in the detection result. If the order of the high-order polynomial for surface fitting is low, there is no obvious difference between the difference of the preprocessed image and the fitted image, which will also lead to errors in the detection result.

[0048] To solve the problem of poor weak defect detection effect in existing weak defect detection solutions, embodiments of the present application provide a defect detection method, apparatus, terminal device, and storage medium. The defect detection method includes: when the image to be detected contains weak defects, the initial foreground region of the image to be detected can be determined, and the initial gray values of the pixel points in each row or each column of the initial foreground region are mapped to each discrete point in the coordinate space (corresponding to the initial gray value of the pixel point), and the discrete region in the coordinate space can be determined; based on the preset straight-line region and the discrete region in the coordinate space, the target closed region in the coordinate space and the convex set region of the target closed region are determined, and based on the coordinates of the outer contour points corresponding to the discrete region in the convex set region, the target gray value corresponding to the initial gray value is returned, and then the target foreground region is determined; finally, based on the difference image between the initial foreground region and the target foreground region, the weak defects can be determined. By the above method, the gray difference between the weak defects and other parts of the image is enhanced, and the weak defect detection effect in the weak defect detection process is improved.

[0049] The following will describe in detail the defect detection method, apparatus, terminal device, and storage medium according to the embodiments of the present application with reference to the accompanying drawings.

[0050] Figure 2 The flowchart showing a defect detection method provided by an embodiment of the present application is as follows Figure 2 As shown, an embodiment of the present application provides a defect detection method.

[0051] The defect detection method includes the following steps:

[0052] S210. Determine the initial foreground region of the image to be detected.

[0053] Among them, the image to be detected contains weak defects. The image to be detected can be collected by a area array camera or obtained by processing multiple collections of a line array camera.

[0054] It should be understood that the resolution of the camera for obtaining the image to be detected and the size of the pixels are determined based on specific products and the accuracy of product defect detection.

[0055] For example, the resolution of the camera can be 2448×2048, and the size of a single pixel is 10μm.

[0056] Figure 3a The example diagram of the image to be detected obtained in defect detection is shown as follows Figure 3a As shown, the image to be detected 300 has weak defects 100.

[0057] Determining the initial foreground region of the image to be detected through step 210 is to locate the initial foreground region, avoiding interference from the background region to subsequent processing processes and defect extraction.

[0058] There are significant differences between the gray values of the foreground and the background of the image to be detected. The initial foreground region of the image to be detected can be determined through a preset foreground extraction strategy.

[0059] In some embodiments, the preset foreground extraction strategy can be OTSU (i.e., Otsu's method or the maximum inter-class variance method). The initial foreground region is located through OTSU. The idea of OTSU is to divide the original image into foreground and background using the optimal threshold T. The determination of the optimal threshold T is achieved through the following steps:

[0060] In the image to be detected, the following relationships exist among the average gray value of the image to be detected, the foreground region, and the background region:

[0061] u = w0 × u0 + w1 × u1

[0062] In the formula, u is the average gray value of the image to be detected, w0 is the proportion of the number of foreground region pixels to the total number of image pixels, u0 is the average gray value of the foreground region pixels, w1 is the proportion of the number of background region pixels to the total number of image pixels, and u1 is the average gray value of the background region pixels.

[0063] Furthermore, the inter-class variance between the foreground region and the background region is determined and obtained through the following formula:

[0064] g = w0 × (u0 - u) 2 + w1 × (u1 - u) 2

[0065] In the formula, g is the inter-class variance.

[0066] Combining the above two formulas, the maximum inter-class variance g can be quickly determined through histogram iteration acceleration max , and the optimal threshold T is obtained. The gray level interval [0, T] is determined as the initial foreground region.

[0067] Figure 3b shows an example diagram of the initial foreground region of the image to be detected for Figure 3a , as shown in Figure 3b , the initial foreground region 310 is located and extracted, and the result schematic diagram of the corresponding initial foreground region 310 is obtained.

[0068] In some embodiments, when the image to be detected is large, the image to be detected can be processed in blocks through the following steps to improve the efficiency of defect detection. Figure 4 shows a flowchart for determining the initial foreground region of an image to be detected in an embodiment of the present application. As shown in Figure 4 , the determination of the initial foreground region of the image to be detected includes the following steps:

[0069] S2101. Determine the foreground image in the image to be detected.

[0070] S2102. Determine whether the size of the foreground image is larger than the size of the preset processing area.

[0071] S2103. If the size of the foreground image is larger than the size of the preset processing area, divide the foreground image into multiple initial foreground regions.

[0072] It should be understood that the sizes of the initial foreground regions are the same, which is convenient for subsequent processing.

[0073] S2104. If the size of the foreground image is not larger than the size of the preset processing area, use the foreground image as the initial foreground region.

[0074] In Figure 4 In the process of determining the initial foreground region of the provided image to be detected, by determining the size of the foreground image in the image to be detected, if the size of the foreground image is larger than the size of the preset processing area, divide the foreground image into multiple initial foreground regions; if the size of the foreground image is not larger than the size of the preset processing area, use the foreground image as the initial foreground region. Since the processing of each initial foreground region is independent and parallel; the efficiency of defect detection is improved through the corresponding one or more initial foreground regions.

[0075] As Figure 2 shown, it further includes: S220. Map the initial gray values of each row or each column of pixel points in the initial foreground region to the coordinate space to determine the discrete region in the coordinate space.

[0076] Among them, the discrete region is composed of the initial gray values of pixel points.

[0077] It should be understood that for the gray-scale transformation of pixel points in the initial foreground region to the coordinate space, it can be performed row by row or column by column in the initial foreground region, and the initial gray values of pixel points in each row or each column are mapped to discrete points in the coordinate space. Among them, the coordinate space is the space where all pixel points corresponding to each row or each column and the coordinate points corresponding to the initial gray values (0 - 255) of each pixel point are located.

[0078] In the gray-scale transformation with the row initial foreground region, Figure 3c shows Figure 3b a schematic diagram of the Nth row of pixel points in the initial foreground region, Figure 3d shows Figure 3c a schematic diagram of the mapped space coordinates, as Figure 3c and Figure 3dAs shown, after the initial gray values of the pixel points in the Nth row are transformed, the initial gray values of the pixel points correspond to discrete points in the coordinate space. The discrete region 320 in the coordinate space is determined, that is to say, this discrete region 320 is composed of the initial gray values of the pixel points.

[0079] For example, the initial gray values of the pixel points in the Nth row are 177, 175, 178, 180, …, 177, 163, 142, 165, 180 in sequence of the pixel points; at this time, the discrete points mapped to the coordinate space are (1, 177), (2, 175), (3, 178), (4, 180), ……, (m - 4, 177), (m - 3, 163), (m - 2, 142), (m - 1, 165), (m, 180) in sequence, and these discrete points form the discrete region; where m is the number of pixel points in the Nth row.

[0080] For the initial foreground region, there is no dependency relationship between the pixel points in each row or between the pixel points in each column. That is to say, the conversion from the initial gray value to the coordinate space can be performed independently for each row or each column.

[0081] In some embodiments, through a parallel processing method, parallel processing can be performed on each row or each column, and the processing efficiency of step 220 can be improved through the parallel processing method.

[0082] Such as Figure 2 As shown, it further includes: S230, determining the target closed region in the coordinate space based on the preset straight-line region and the discrete region in the coordinate space.

[0083] Among them, the preset straight-line region in the coordinate space is a straight-line segment with a width equal to the width or length of the initial foreground region set at a preset position in the coordinate space, and the preset straight-line region is composed of corresponding multiple straight-line segments.

[0084] By performing morphological operations on the preset straight-line region and the discrete region in the coordinate space, the target closed region in the coordinate space is determined. Figure 5 Shows a flowchart for determining the target closed region in the coordinate space in an embodiment of the present application. As Figure 5 As shown, determining the target closed region in the coordinate space includes the following steps:

[0085] S2301, performing region closing processing on the preset straight-line region and the discrete region in the coordinate space to obtain the initial closed region.

[0086] Figure 3e Shows Figure 3d a schematic diagram of the discrete region and the initial closed region determined by the preset straight-line region, as Figure 3eAs shown, the region closing process is performed on the preset straight line region and the discrete region 320, which can be achieved through morphological closing operation. It connects narrow discontinuities and long and thin gaps, eliminates small holes, and fills in the breaks in the contour line. Specifically, the discrete region is dilated and then eroded to determine the initial closed region 330.

[0087] S2302. Remove the interference in the discrete edges of the initial closed region to obtain the target closed region.

[0088] Figure 3f It shows the removal of Figure 3e A schematic diagram of the target closed region after removing the interference in the discrete edges of the initial closed region is shown. As Figure 3f shown, for the interference existing in the discrete edges of the initial closed region, the influence of the interference can be reduced by removing the interference in the discrete edges to determine the target closed region 340.

[0089] In some embodiments, the morphological opening operation can be used to remove the fringing interference of the region to achieve morphological adjustment. The morphological opening operation makes the contour of the object smooth, disconnects narrow discontinuities, and eliminates thin protrusions. Specifically, it is carried out by erosion first and then dilation operation on the result.

[0090] It should be understood that images with uneven illumination usually have some noises, which will form more discrete interference points after transformation, resulting in fringing at the boundaries of the corresponding regions. By performing morphological adjustment on the fringing boundaries, the fringing can be eliminated, thereby reducing the interference of the noises.

[0091] As Figure 2 shown, it further includes: S240. Determine the convex set region of the target closed region, and based on the coordinates of the outer contour points corresponding to the discrete region in the convex set region, determine the target gray value corresponding to the initial gray value.

[0092] Among them, the convex set region can be the smallest convex hull containing the target closed region.

[0093] For the convex set region, it means that in a real vector space V, for a given target closed region x, the intersection S of all convex sets containing X is called the convex hull of the target closed region X. The convex hull of the target closed region X can be constructed by the convex combination of all points (X1,... Xp) in x.

[0094] Figure 3g A schematic diagram of the convex set region of the 3f target closed region is shown. As Figure 3g shown, the smallest convex hull containing the target closed region is the convex set region 350 of the target closed region.

[0095] It should be understood that during the process of step 240 to determine the convex set region of the target closed region, noise has a greater impact on the convex set region. By setting step 2302, the interference in the discrete edge of the initial closed region is improved.

[0096] Step 240 also includes determining the target gray value corresponding to the initial gray value based on the coordinates of the outer contour points corresponding to the discrete region in the convex set region. As Figure 3g shown, the outer contour points corresponding to the discrete region in the convex set region are Figure 3g the contour point region numbered 351 in the figure. Through the ordinates (within the range of [0, 255]) of the coordinates of each contour point in this contour point region, the target gray value is determined. At this time, the target gray value is the gray value of the pixel points in the Nth row after transformation, and corresponds to the initial gray value (within the range of [0, 255]).

[0097] For example, in the above example, the discrete points in the discrete region of the coordinate space are successively (1, 177), (2, 175), (3, 178), (4, 180), ……, (m - 4, 177), (m - 3, 163), (m - 2, 142), (m - 1, 165), (m, 180). After steps 230 and 240, the contour points in the corresponding contour point region are successively (1, 176), (2, 176), (3, 177), (4, 178), ……, (m - 4, 178), (m - 3, 178), (m - 2, 177), (m - 1, 177), (m, 176); the target gray values determined by the contour point region are successively 176, 176, 177, 178,......, 178, 178, 177, 177, 176; the target gray values of these pixel points correspond to the initial gray values of the pixel points in the Nth row.

[0098] Furthermore, the target foreground region is determined from the target gray value. Figure 3h shows Figure 3g a schematic diagram of the target foreground region after the inverse transformation of the convex set region. As Figure 3h shown, the target foreground region 360 after the inverse transformation.

[0099] The process from step 220 to step 240 converts the initial foreground region from the gray space to the coordinate space. The gray change of the image is presented as the corresponding curve change in the coordinate space, converting the gray adjustment of the image into the adjustment of the curve values. Finally, the changed curve values are inversely transformed back into the gray space to complete the preset surface fitting, and the influence brought by the uneven background illumination is weakened through the above process of the preset surface fitting.

[0100] The higher the fitting accuracy of the target foreground region, the better the effect of eliminating the uneven illumination.

[0101] AsFigure 2 As shown, it further includes: S250. Determine weak defects based on the difference image between the initial foreground region and the target foreground region.

[0102] By determining the difference image between the initial foreground region and the target foreground region, uneven illumination can be eliminated. The higher the fitting accuracy of the target foreground region, the better the effect of eliminating uneven illumination.

[0103] Among them, the difference image between the initial foreground region and the target foreground region can be determined by the following formula:

[0104] g = (g1 - g2) × Mult + Add

[0105] In the formula, g is the difference image, g1 is the initial foreground region, g2 is the target foreground region, Mult is the multiplication coefficient, and Add is the addition coefficient.

[0106] Figure 3i shows Figure 3b the initial foreground region and Figure 3g a schematic diagram of the difference image determined by the target foreground region. As Figure 3i shown, it is the difference image 370 after eliminating uneven illumination.

[0107] After eliminating uneven illumination, the gray value of the defect position is lower than that of the non-defect position. Using the dynamic threshold method to extract weak defects may result in a smaller contour extraction of weak defects. Based on this, the embodiments of the present application provide a method for segmenting weak defects by high and low thresholds. The suspicious positions of weak defects are determined by a preset high gray threshold, and then the weak defects are segmented by a preset low gray threshold near this position. Figure 6 shows a flowchart of determining weak defects based on the difference image in an embodiment of the present application. As Figure 6 shown, it includes the following steps:

[0108] S2501. Screen out suspicious regions from the difference image through a preset high gray threshold and a first dynamic threshold condition corresponding to the preset high gray threshold.

[0109] Among them, the first dynamic threshold condition is determined based on the preset high gray threshold and a preset first deviation value. The first dynamic threshold condition is used to segment the first image that meets the preset high gray threshold, and based on the first image and the difference image, the suspicious region is determined.

[0110] First, the image processed by the preset high gray threshold can be segmented by the following formula:

[0111]

[0112] In the formula, g is the difference image, g hThe image is after being processed by a preset high gray - level threshold. Offset1 is a preset first deviation value, light is a bright defect, and dark is a dark defect.

[0113] Then, the suspicious regions are screened out from the difference image by the image after being processed by the preset high gray - level threshold.

[0114] S2502: Weak defects are screened out from the suspicious regions by a preset low gray - level threshold and a second dynamic threshold condition corresponding to the preset low gray - level threshold.

[0115] Among them, the second dynamic threshold condition is determined based on the preset low gray - level threshold and a preset second deviation value. The second dynamic threshold condition is used to segment out a second image that meets the preset low gray - level threshold, and based on the second image and the difference image, weak defects are determined.

[0116] First, the image after being processed by the preset low gray - level threshold can be segmented by the following formula:

[0117]

[0118] In the formula, g is the difference image, g1 is the image after being processed by the preset low gray - level threshold, Offset2 is the preset second deviation value, light is a bright defect, and dark is a dark defect.

[0119] Weak defects are screened out from the suspicious regions by the image after being processed by the preset low gray - level threshold.

[0120] In some embodiments, the defect regions can also be screened out from the difference image by the image after being processed by the preset low gray - level threshold; the region where the suspicious region and the defect region intersect is a weak defect.

[0121] In some embodiments, if the obtained image to be detected has rows or columns that are all product surface images, the processes from step 220 to step 250 can be performed in the form of that row or that column, reducing the extraction process of the initial foreground region.

[0122] The defect detection method according to the embodiment of the present application includes that when the image to be detected contains weak defects, the initial foreground region of the image to be detected can be determined, the initial gray values of each row or each column of pixel points in the initial foreground region are mapped to each discrete point in the coordinate space, and the discrete region in the coordinate space can be determined; based on the preset straight line region and the discrete region in the coordinate space, the target closed region in the coordinate space and the convex set region of the target closed region are determined, and based on the coordinates of the outer contour points corresponding to the discrete region in the convex set region, the target gray value corresponding to the initial gray value is returned, and then the target foreground region is determined; finally, based on the difference image between the initial foreground region and the target foreground region, the weak defects can be determined. By the above method, the gray difference between the weak defects and other parts of the image is enhanced, and the detection effect of the weak defects in the weak defect detection process is improved.

[0123] Figure 7 The flowchart of another defect detection method provided by the embodiment of the present application is shown. As Figure 7 shown, the embodiment of the present application provides a defect detection method. Between step 210 and step 220 in the previous Figure 2 defect detection method, the defect detection method further includes the following steps:

[0124] S410. Perform preprocessing on the initial foreground region.

[0125] Through preprocessing, the differences between regions can be enhanced. The preprocessing methods generally include grayscale conversion, binarization, image enhancement, filtering and denoising, and image augmentation, etc.; among them, image enhancement includes frequency domain image enhancement and time domain image enhancement; time domain image enhancement includes: gray stretching, Gamma correction, histogram equalization, histogram specification, etc.

[0126] Among them, the image enhancement method can include: subtracting the original image and the filtered image, and then performing gray stretching on the difference image to achieve the purpose of enhancing the defects. Subtracting the original image and the filtered image eliminates the influence of part of the background.

[0127] Generally, when there is noise in the image to be detected, the following formula can be used for preprocessing:

[0128] res = round(ori - mean) × factor + ori

[0129] In the formula, res is the enhanced alternative foreground region, round is the rounding function, mean is the mean filtered image of the initial foreground region, ori is the initial foreground region, and factor is the enhancement multiple.

[0130] In some embodiments, when there is no noise in the image to be detected, the initial foreground region image does not need to be preprocessed, and whether to use image preprocessing can be determined according to the actual situation.

[0131] After step 410, corresponding to step 220, the determination of the discrete region can be achieved through the following steps:

[0132] S420. Map the initial gray values of each row or each column of pixel points in the candidate foreground region obtained after preprocessing to the coordinate space to determine the discrete region.

[0133] The implementation principle and technical effects of step 420 and subsequent steps are similar to those of the above method embodiments, and will not be elaborated here. In the embodiments of the present application, by performing preprocessing on the initial foreground region, the difference between the background and the foreground is enhanced, and the detection effect is improved.

[0134] Figure 8 The structure diagram of a defect detection device provided by the embodiments of the present application is shown, as Figure 8 shown, the defect detection device 800 includes a foreground detection module 810, a first conversion module 820, a second conversion module 830, and a defect detection module 840, where:

[0135] The foreground detection module is used to determine the initial foreground region of the image to be detected, and the image to be detected contains weak defects;

[0136] The first conversion module is used to map the initial gray values of each row or each column of pixel points in the initial foreground region to the coordinate space to determine the discrete region in the coordinate space, and the discrete region is composed of the initial gray values of the pixel points;

[0137] The second conversion module is used to determine the target closed region in the coordinate space based on the preset straight line region and the discrete region in the coordinate space; it is also used to determine the convex set region of the closed region, and based on the coordinate space of the outer contour points corresponding to the discrete region in the convex set region, determine the target gray value corresponding to the initial gray value; where the convex set region is the smallest convex hull containing the target closed region.

[0138] The defect detection module is used to determine weak defects based on the difference image between the initial foreground region and the target foreground region, and the target foreground region is determined by the target gray value.

[0139] In some embodiments, the second conversion module includes a region determination unit, and the region determination unit is used to perform region closing processing on the preset straight line region and the discrete region in the coordinate space to obtain the initial closed region; it is also used to remove the interference in the discrete edges of the initial closed region to obtain the target closed region.

[0140] In some embodiments, the defect detection module includes a dynamic determination unit, which is configured to screen out suspicious regions from the difference image through a preset high gray - level threshold and a first dynamic threshold condition corresponding to the preset high gray - level threshold; and is further configured to screen out weak defects from the suspicious regions through a preset low gray - level threshold and a second dynamic threshold condition corresponding to the preset low gray - level threshold.

[0141] Among them, the first dynamic threshold condition is determined based on the preset high gray - level threshold and a preset first deviation value. The first dynamic threshold condition is used to segment a first image that meets the preset high gray - level threshold, and based on the first image and the difference image, determine the suspicious regions; the second dynamic threshold condition is determined based on the preset low gray - level threshold and a preset second deviation value. The second dynamic threshold condition is used to segment a second image that meets the preset low gray - level threshold, and based on the second image and the difference image, determine the weak defects.

[0142] In some embodiments, the foreground detection module includes a pre - processing unit, which is configured to divide the foreground image into multiple initial foreground regions when the size of the foreground image in the image to be detected is larger than the size of the preset processing region.

[0143] In some embodiments, the defect detection device further includes a pre - processing module, which is configured to perform pre - processing on the initial foreground regions to determine alternative foreground regions; at this time, the first conversion module is further configured to map the initial gray - level values of each row or each column of pixel points in the alternative foreground regions to the coordinate space to determine the discrete regions.

[0144] An embodiment of the present application provides a defect detection device, including a foreground detection module, a first conversion module, a second conversion module, and a defect detection module. When the image to be detected contains weak defects, the foreground detection module can be used to determine the initial foreground region of the image to be detected; the first conversion module is used to map the initial gray - level values of each row or each column of pixel points in the initial foreground region to the discrete regions in the coordinate space; the second conversion module is used to implement the determination of the target closed region in the coordinate space and the convex set region of the target closed region based on the preset straight - line region and the discrete region in the coordinate space, and based on the coordinates of the outer contour points corresponding to the discrete region in the convex set region, return the target gray - level value corresponding to the initial gray - level value, and further determine the target foreground region; the defect detection module can be used to determine weak defects based on the difference image between the initial foreground region and the target foreground region. The defect detection device enhances the gray - level difference between weak defects and other parts of the image, and improves the detection effect of weak defects during the weak defect detection process.

[0145] The embodiment of the present application further provides a computing terminal device, including a memory and a processor. The memory stores a computer program, and the processor executes the computer program, which is used to implement the above-mentioned defect detection method. The implementation principle and technical effect are similar to those of the above method embodiment, and will not be elaborated here.

[0146] The embodiment of the present application further provides a computer storage medium. A computer program is stored on the computer-readable storage medium, and the computer program is executed by the processor to implement the above-mentioned defect detection method. The implementation principle and technical effect are similar to those of the above method embodiment, and will not be elaborated here.

[0147] The following paragraphs will list and compare the Chinese terms involved in the specification of the present application and their corresponding English terms for easy reading and understanding.

[0148] For the sake of convenience in explanation, the above description has been made in combination with specific embodiments. However, the above discussion in some embodiments is not intended to be exhaustive or to limit the embodiments to the specific forms disclosed above. According to the above teachings, various modifications and variations can be obtained. The selection and description of the above embodiments are for better explaining the principles and actual applications, so that those skilled in the art can better use the embodiments and various different modified embodiments suitable for specific use considerations.

Claims

1. A defect detection method, characterized in that, Including: Determine an initial foreground region of the image to be detected, where the image to be detected contains weak defects; Map the initial gray values of each row of pixel points or each column of pixel points in the initial foreground region to a coordinate space, and determine a discrete region in the coordinate space, where the discrete region is composed of the initial gray values of the pixel points; Based on a preset straight-line region and the discrete region in the coordinate space, determine a target closed region in the coordinate space; Determine a convex set region of the target closed region, and based on the coordinates of the outer contour points corresponding to the discrete region in the convex set region, determine the target gray value corresponding to the initial gray value; Based on the difference image between the initial foreground region and the target foreground region, determine the weak defects, where the target foreground region is determined by the target gray value.

2. The defect detection method according to claim 1, characterized in that The determining the target closed region in the coordinate space based on the preset straight-line region and the discrete region in the coordinate space includes: Perform region closing processing on the preset straight-line region and the discrete region in the coordinate space to obtain an initial closed region; Remove the interference in the discrete edges of the initial closed region to determine the target closed region.

3. The defect detection method according to claim 1, wherein The convex set region is the smallest convex hull containing the target closed region.

4. The defect detection method according to claim 1, wherein The determining the weak defects based on the difference image between the initial foreground region and the target foreground region includes: Screen out suspicious regions from the difference image through a preset high gray threshold and a first dynamic threshold condition corresponding to the preset high gray threshold; Screen out the weak defects from the suspicious regions through a preset low gray threshold and a second dynamic threshold condition corresponding to the preset low gray threshold.

5. The defect detection method according to claim 4, wherein The first dynamic threshold condition is determined based on the preset high gray threshold and a preset first deviation value, and the first dynamic threshold condition is used to segment a first image that meets the preset high gray threshold, and based on the first image and the difference image, determine the suspicious regions; The second dynamic threshold condition is determined based on the preset low gray threshold and a preset second deviation value, and the second dynamic threshold condition is used to segment a second image that meets the preset low gray threshold, and based on the second image and the difference image, determine the weak defects.

6. The defect detection method according to claim 1, characterized in that, In the step of determining the initial foreground region of the image to be detected, it includes: If the size of the foreground image in the image to be detected is larger than the size of the preset processing region, divide the foreground image into multiple initial foreground regions.

7. The defect detection method according to claim 1, wherein Before mapping the initial gray values of each row of pixel points or each column of pixel points in the initial foreground region to the coordinate space to determine the discrete region, it further includes: Perform preprocessing on the initial foreground region.

8. A defect detection device, characterized in that, Including: A foreground detection module for determining an initial foreground region of the image to be detected, where the image to be detected contains weak defects; A first conversion module for mapping the initial gray values of each row of pixel points or each column of pixel points in the initial foreground region to the coordinate space, and determining a discrete region in the coordinate space, where the discrete region is composed of the initial gray values of the pixel points; A second conversion module, configured to determine a target closed region in the coordinate space based on a preset straight-line region and the discrete region in the coordinate space; It is further configured to determine a convex set region of the closed region, and determine a target gray value corresponding to the initial gray value based on the coordinate space of the outer contour points corresponding to the discrete region in the convex set region; A defect detection module, configured to determine the weak defect based on a difference image between the initial foreground region and the target foreground region, where the target foreground region is determined by the target gray value.

9. A terminal device, comprising a memory and a processor, the memory storing a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the defect detection method according to any one of claims 1 to 7.

10. A computer storage medium, characterized in that, A computer program is stored on the computer-readable storage medium. When the computer program is executed by the processor, the processor is caused to execute the steps of the defect detection method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Video segmentation method

    AU2014280957A1

  • Method for detecting weak line defect under arc-shaped surface gradient background

    CN112598647A