CN115797327A - Defect detection method and device, terminal device and storage medium - Google Patents

Defect detection method and device, terminal device and storage medium Download PDF

Info

Publication number
CN115797327A
CN115797327A CN202211689608.0A CN202211689608A CN115797327A CN 115797327 A CN115797327 A CN 115797327A CN 202211689608 A CN202211689608 A CN 202211689608A CN 115797327 A CN115797327 A CN 115797327A
Authority
CN
China
Prior art keywords
region
image
initial
determining
foreground
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211689608.0A
Other languages
Chinese (zh)
Inventor
康照川
解三霞
周钟海
时广军
杨艺
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Luster LightTech Co Ltd
Original Assignee
Luster LightTech Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Luster LightTech Co Ltd filed Critical Luster LightTech Co Ltd
Priority to CN202211689608.0A priority Critical patent/CN115797327A/en
Publication of CN115797327A publication Critical patent/CN115797327A/en
Pending legal-status Critical Current

Links

Images

Abstract

The application relates to the technical field of defect detection, in particular to a defect detection method, a defect detection device, terminal equipment and a storage medium, and can solve the problem of poor weak defect detection effect in a weak defect detection process to a certain extent. Determining an initial foreground area in an image to be detected, mapping initial gray values of each row of pixel points or each column of pixel points in the initial foreground area to a discrete area of a coordinate space, determining a convex set area of a target closed area based on a preset straight line area and the discrete area in the coordinate space, determining a target gray value corresponding to the initial gray value based on coordinates of outer contour points corresponding to the discrete area in the convex set area, and further determining the target foreground area; finally, based on the difference value image of the initial foreground area and the target foreground area, the weak defect can be determined; the gray difference between the weak defect and other parts of the image is enhanced through the process, and the weak defect detection effect in the weak defect detection process is improved.

Description

Defect detection method and device, terminal device and storage medium
Technical Field
The present application relates to the field of defect detection technologies, and in particular, to a defect detection method, an apparatus, a terminal device, and a storage medium.
Background
In the field of industrial visual inspection, there is the detection of weak defects on the surface of a product, usually by means of an image containing the product. The reason for the weak defect formation mainly includes that the identification degree of the defect itself is low, and/or the imaging of the defect in the image is weak due to limitations of product material, optical imaging conditions when the image is shot, and the like, wherein the limitations of the optical imaging conditions include uneven illumination, background interference, and the like.
In the defect detection process, firstly, preprocessing is performed on an image to enhance the contrast between a defect (namely the foreground of the image) and a background, then a fitted image is obtained by performing surface fitting on the image, and then the interference of uneven illumination on the defect is eliminated by performing difference between the preprocessed image and the fitted image, wherein the surface fitting is mainly realized by a high-order polynomial approximation mode.
However, by detecting weak defects in the above manner, if the order of the high-order polynomial for surface fitting is higher, the detection process is more complicated to calculate, which easily causes errors in the detection result, and if the order of the high-order polynomial for surface fitting is lower, the difference between the preprocessed image and the fitted image is not significantly different, which also causes errors in the detection result, so that the existing weak defect detection scheme has a problem of poor weak defect detection effect.
Disclosure of Invention
In order to solve the technical problem of poor weak defect detection effect in a weak defect detection process, the application provides a defect detection method, a defect detection device, terminal equipment and a storage medium.
The embodiment of the application is realized as follows:
a first aspect of an embodiment of the present application provides a defect detection method, including the following steps:
determining an initial foreground area of an image to be detected, wherein the image to be detected contains weak defects;
mapping the initial gray values of each row of pixel points or each column of pixel points in the initial foreground area to a coordinate space, and determining a discrete area in the coordinate space, wherein the discrete area is formed by the initial gray values of the pixel points;
determining a target closed region in a coordinate space based on a preset straight line region and a discrete region in the coordinate space;
determining a convex set region of the target closed region, and determining a target gray value corresponding to the initial gray value based on coordinates of outer contour points corresponding to the discrete regions in the convex set region;
and determining weak defects based on the difference image of the initial foreground area and the target foreground area, wherein the target foreground area is determined by the target gray value.
A second aspect of the embodiments of the present application provides a defect detection apparatus, including a foreground detection module, a first conversion module, a second conversion module, and a defect detection module, wherein:
the foreground detection module is used for determining an initial foreground area of an image to be detected, and the image to be detected contains weak defects;
the first conversion module is used for mapping the initial gray values of the pixel points in each row or column in the initial foreground area to a coordinate space and determining a discrete area in the coordinate space, wherein the discrete area is formed by the initial gray values of the pixel points;
the second conversion module is used for determining a target closed area in the coordinate space based on a preset straight line area and a discrete area in the coordinate space; the method is also used for determining a convex set region of the closed region, and determining a target gray value corresponding to the initial gray value based on a coordinate space of an outer contour point corresponding to the discrete region in the convex set region;
and the defect detection module is used for determining weak defects based on the difference image of the initial foreground region and the target foreground region, and the target foreground region is determined by the target gray value.
A third aspect of embodiments of the present application provides a terminal device, which includes a memory and a processor, where the memory stores a computer program, and the processor implements the steps of the defect detection method of the first aspect when executing the computer program.
A fourth aspect of embodiments of the present application provides a computer storage medium, on which a computer program is stored, which, when executed by a processor, causes the processor to perform the steps of the defect detection method of the first aspect.
The beneficial effect of this application: when the image to be detected contains weak defects, determining an initial foreground region of the image to be detected, mapping initial gray values of each row of pixel points or each column of pixel points in the initial foreground region to each discrete point (corresponding to the initial gray values of the pixel points) of a coordinate space, and determining the discrete region in the coordinate space; the method comprises the steps of determining a target closed region in a coordinate space and a convex set region of the target closed region based on a preset straight line region and a discrete region in the coordinate space, returning a target gray value corresponding to an initial gray value based on coordinates of an outer contour point corresponding to the discrete region in the convex set region, and further determining a target foreground region; finally, based on the difference image of the initial foreground area and the target foreground area, the weak defect can be determined. By the method, the gray difference between the weak defect and other parts of the image is enhanced, and the weak defect detection effect in the weak defect detection process is improved.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present application, and for those skilled in the art, other drawings can be obtained according to these drawings without inventive exercise.
FIG. 1a shows an exemplary diagram of a weak defect of a product surface;
FIG. 1b shows an example diagram of a weak defect of a product surface;
FIG. l c shows an example diagram of a weak defect of a product surface;
FIG. 2 is a flow chart illustrating a defect detection method provided by an embodiment of the present application;
FIG. 3a shows an exemplary diagram of an image to be detected obtained in defect detection;
FIG. 3b shows an exemplary diagram of the initial foreground region for the image to be detected of FIG. 3 a;
FIG. 3c is a schematic diagram of the Nth row of pixels in the initial foreground region of FIG. 3 b;
FIG. 3d shows a schematic representation of the spatial coordinates of the map of FIG. 3 c;
FIG. 3e is a schematic diagram of the initial closed region defined by the discrete region and the predetermined straight line region of FIG. 3 d;
FIG. 3f shows a schematic diagram of the target occlusion region after removing the disturbance in the discrete edges of the initial occlusion region of FIG. 3 e;
FIG. 3g shows a schematic of the convex set region of the 3f target occlusion region;
FIG. 3h is a schematic diagram of the target foreground region after inverse transformation of the convex set region in FIG. 3 g;
FIG. 3i is a schematic diagram showing a difference image determined between the initial foreground region of FIG. 3b and the target foreground region of FIG. 3 g;
FIG. 4 is a flowchart illustrating an initial foreground region determination of an image to be detected according to an embodiment of the present application;
FIG. 5 is a flow chart illustrating the determination of a target closed region in a coordinate space according to an embodiment of the present application;
FIG. 6 is a flow chart illustrating a weak defect determination based on a difference image according to an embodiment of the present application;
FIG. 7 is a flow chart illustrating a further defect detection method provided by the embodiments of the present application;
FIG. 8 is a schematic structural diagram of a defect detection apparatus provided in an embodiment of the present application;
among them, 100-weak defects; 300-an image to be detected; 310-initial foreground region; 320-discrete regions; 330-initial closed area; 340-target occlusion region; 350-convex set region; 351-region of contour points; 360-target foreground region; 370-difference image.
Detailed Description
To make the objects, embodiments and advantages of the present application clearer, the following is a clear and complete description of exemplary embodiments of the present application with reference to the attached drawings in exemplary embodiments of the present application, and it is apparent that the exemplary embodiments described are only a part of the embodiments of the present application, and not all of the embodiments.
It should be noted that the brief descriptions of the terms in the present application are only for convenience of understanding of the embodiments described below, and are not intended to limit the embodiments of the present application. These terms should be understood in their ordinary and customary meaning unless otherwise indicated.
The terms "first," "second," "third," and the like in the description and claims of this application and in the above-described drawings are used for distinguishing between similar or analogous objects or entities and not necessarily for describing a particular sequential or chronological order, unless otherwise indicated. It is to be understood that the terms so used are interchangeable under appropriate circumstances.
The terms "comprises" and "comprising," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a product or apparatus that comprises a list of elements is not necessarily limited to all elements expressly listed, but may include other elements not expressly listed or inherent to such product or apparatus.
Fig. 1a, 1b, and 1c all show an exemplary illustration of weak defects on a product surface, and as shown in fig. 1a, 1b, and 1c, weak defects 100 on a product surface may occur anywhere on an uneven surface, and some specific disturbances may also exist on the product surface.
In the related defect detection process, firstly, preprocessing is performed on an image to enhance the contrast between the defect (namely the foreground of the image) and the background, then a fitted image is obtained by performing surface fitting on the image, and then the interference of uneven illumination on the defect is eliminated by performing difference between the preprocessed image and the fitted image.
The surface fitting is mainly realized in a high-order polynomial approximation mode, and the fitting precision is related to the order of a polynomial. If the order of the high-order polynomial subjected to surface fitting is high, the detection process is complex in calculation, and a detection result is prone to be wrong.
In order to solve the problem that an existing weak defect detection scheme is poor in weak defect detection effect, embodiments of the present application provide a defect detection method, an apparatus, a terminal device, and a storage medium, where the defect detection method includes: when the image to be detected contains weak defects, determining an initial foreground region of the image to be detected, mapping initial gray values of pixel points of each row or pixel point of each column in the initial foreground region to discrete points (corresponding to the initial gray values of the pixel points) in a coordinate space, and determining the discrete region in the coordinate space; the method comprises the steps of determining a target closed region in a coordinate space and a convex set region of the target closed region based on a preset straight line region and a discrete region in the coordinate space, returning a target gray value corresponding to an initial gray value based on coordinates of an outer contour point corresponding to the discrete region in the convex set region, and further determining a target foreground region; finally, weak defects can be determined based on the difference image of the initial foreground region and the target foreground region. By the method, the gray difference between the weak defect and other parts of the image is enhanced, and the weak defect detection effect in the weak defect detection process is improved.
The following describes a defect detection method, a defect detection apparatus, a terminal device, and a storage medium according to embodiments of the present application in detail with reference to the accompanying drawings.
Fig. 2 shows a schematic flow chart of a defect detection method provided in the embodiment of the present application, and as shown in fig. 2, the embodiment of the present application provides a defect detection method.
The defect detection method comprises the following steps:
s210, determining an initial foreground area of the image to be detected.
The image to be detected contains weak defects, and the image to be detected can be acquired by an area-array camera or acquired by a linear array camera for multiple acquisition and post-processing.
It should be understood that the resolution of the camera, the size of the pixels, that acquire the image to be detected is determined based on the particular product, the accuracy of the product defect detection.
For example, the resolution of the camera may be 2448 × 2048, with the size of a single pixel being 10 μm.
Fig. 3a shows an exemplary illustration of an image to be detected obtained in defect detection, as shown in fig. 3a, of an image 300 to be detected having a weak defect 100 therein.
The initial foreground region of the image to be detected is determined through step 210, which is the positioning of the initial foreground region, so that the background region is prevented from interfering the subsequent processing process and the extraction of defects.
The gray value of the foreground of the image to be detected and the gray value of the background have larger difference, and the initial foreground area of the image to be detected can be determined through a preset foreground extraction strategy.
In some embodiments, the preset foreground extraction policy may be OTSU (that is, the ohs method or the maximum inter-class variance method), the initial foreground region is located by OTSU, the original image is divided into a foreground and a background by the concept of OTSU, and the determination of the optimal threshold T is implemented by the following steps:
in an image to be detected, the average gray level mean value of the image to be detected, a foreground area and a background area have the following relations:
u=w 0 ×u 0 +w 1 ×u 1
wherein u is the average gray level mean value of the image to be detected, w 0 The ratio of the number of pixels in the foreground region to the total number of pixels in the image, u 0 Is the average gray value of the pixel number of the foreground region, w 1 The ratio of the number of pixels in the background area to the total number of pixels in the image, u 1 The average gray value is the number of pixels in the background area.
Further, determining the between-class variance of the foreground area and the background area, and calculating by the following formula:
g=w 0 ×(u 0 -u) 2 +w 1 ×(u 1 -u) 2
wherein g is the between-class variance.
Combining the two formulas, the maximum between-class variance g can be quickly determined through histogram iteration acceleration max To obtain the optimal threshold value T, which will belong to the gray scale interval [0]Determined as the initial foreground region.
Fig. 3b shows an exemplary diagram of the initial foreground region of the image to be detected in fig. 3a, and as shown in fig. 3b, the extracted initial foreground region 310 is located, and a result diagram of the corresponding initial foreground region 310 is obtained.
In some embodiments, the image to be detected is large, and the image to be detected can be processed in blocks through the following steps, so that the defect detection efficiency is improved. Fig. 4 shows a flowchart of determining an initial foreground region of an image to be detected in an embodiment of the present application, and as shown in fig. 4, the determining the initial foreground region of the image to be detected includes the following steps:
s2101, foreground images in the images to be detected are determined.
S2102, determine whether the size of the foreground image is larger than the size of the preset processing area.
S2103, if the size of the foreground image is larger than that of the preset processing area, dividing the foreground image into a plurality of initial foreground areas.
It will be appreciated that the initial foreground regions are the same size to facilitate subsequent processing.
And S2104, if the size of the foreground image is not larger than the size of the preset processing area, taking the foreground image as an initial foreground area.
In the process of determining the initial foreground region of the image to be detected provided in fig. 4, 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 region, the foreground image is divided into a plurality of initial foreground regions; and if the size of the foreground image is not larger than the size of the preset processing area, taking the foreground image as an initial foreground area. The processing of each initial foreground area is independent and parallel; the efficiency of defect detection is improved by the corresponding one or more initial foreground regions.
As shown in fig. 2, the method further includes: s220, mapping the initial gray value of each row of pixel points or each column of pixel points in the initial foreground area to a coordinate space, and determining a discrete area in the coordinate space.
The discrete region is formed by the initial gray value of the pixel point.
It should be understood that, for the gray scale transformation from the pixel points in the initial foreground region to the coordinate space, the transformation may be performed for each row or each column of the initial foreground region, and the initial gray scale values of the pixel points in each row or each column are mapped to discrete points in the coordinate space, where the coordinate space is a space in which all the pixel points corresponding to each row or each column and the coordinate points corresponding to the initial gray scale values (0-255) corresponding to each pixel point are located.
In the process of performing gray scale conversion by using the line initial foreground region, fig. 3c shows a schematic diagram of pixels in the nth line in the line initial foreground region in fig. 3b, and fig. 3d shows a schematic diagram of the space coordinates mapped by fig. 3c, as shown in fig. 3c and fig. 3d, after the initial gray scale value of the pixels in the nth line is converted, the initial gray scale value of the pixels corresponds to a discrete point in the coordinate space, and a discrete region 320 in the coordinate space is determined, that is, the discrete region 320 is formed by the initial gray scale values of the pixels.
For example, the initial gray scale values of the pixels in the nth row are 177, 175, 178, 180, \ 8230;, 177, 163, 142, 165 and 180 in sequence according to the pixels; discrete points mapped into the coordinate space are (1, 177), (2, 175), (3, 178), (4, 180), (8230), (m-4, 177), (m-3, 163), (m-2, 142), (m-1, 165), (m, 180) in sequence, and form discrete areas; wherein m is the number of the pixels in the Nth row.
For the initial foreground region, there is no dependency relationship between each row of pixels or each column of pixels, that is, the conversion from the initial gray value to the coordinate space can be performed independently for each row or each column.
In some embodiments, the parallel processing may be performed on each row or each column by a parallel processing manner, so as to improve the processing efficiency of step 220 by the parallel processing manner.
As shown in fig. 2, further includes: and S230, determining a target closed region in the coordinate space based on the preset straight line region and the discrete region in the coordinate space.
The preset straight line area in the coordinate space is formed by arranging a straight line segment with the width equal to that of the initial foreground area or the length at a preset position in the coordinate space and forming the preset straight line area by a plurality of corresponding straight line segments.
A target closed region in a coordinate space is determined through morphological operations on a preset straight line region and a discrete region in the coordinate space, fig. 5 shows a flowchart of determining the target closed region in the coordinate space in an embodiment of the present application, and as shown in fig. 5, the determining the target closed region in the coordinate space includes the following steps:
s2301, performing area closing processing on a preset straight line area and a discrete area in the coordinate space to obtain an initial closed area.
Fig. 3e shows a schematic diagram of the initial closed region determined by the discrete region and the predetermined linear region in fig. 3d, and as shown in fig. 3e, the region closing process is performed on the predetermined linear region and the discrete region 320, which can be implemented by a morphological closing operation, to connect a narrow gap and a long and thin gap, eliminate a small hole, and fill up a fracture in the contour line, specifically, the initial closed region 330 is determined by performing an expanding operation and then performing erosion on the discrete region.
S2302, removing interference in the discrete edge of the initial closed region to obtain a target closed region.
Fig. 3f shows a schematic diagram of the target occlusion region after removing the interference in the discrete edge of the initial occlusion region of fig. 3e, and as shown in fig. 3f, for the interference in the discrete edge of the initial occlusion region, the influence of the interference can be reduced by removing the interference in the discrete edge, and the target occlusion region 340 can be determined.
In some embodiments, morphological adjustment may be achieved by removing the burr interference of the region by a morphological opening operation. The morphological opening operation smoothes the contour of the object, breaks up the narrow discontinuities and eliminates the fine protrusions, in particular by performing an erosion operation, and then the resulting dilation operation.
It should be understood that, in an image with uneven illumination, there are usually some noises, and these noises may form more discrete interference points after being transformed, so that the boundaries of the corresponding regions are rough, and the rough edges may be eliminated by performing morphological adjustment on the rough edges, thereby reducing the interference of the noises.
As shown in fig. 2, further includes: s240, determining a convex set area of the target closed area, and determining a target gray value corresponding to the initial gray value based on the coordinates of the outer contour points corresponding to the discrete areas in the convex set area.
Wherein the convex set region may be the smallest convex hull that contains the target occlusion region.
By convex set region is meant that in one real vector space V, for a given target occlusion region X, the intersection S of all convex sets containing X is called the convex hull of the target occlusion region X, which can be constructed with a convex combination of all points (X1.. Xp) within X.
Fig. 3g shows a schematic diagram of the convex set region of the 3f target occlusion region, as shown in fig. 3g, the smallest convex hull containing the target occlusion region being the convex set region 350 of the target occlusion region.
It should be appreciated that noise may have a greater impact on the convex set region during the determination of the convex set region of the target occlusion region in step 240, and the interference in the discrete edges of the initial occlusion region is improved by setting step 2302.
Step 240 further comprises determining a target gray value corresponding to the initial gray value based on the coordinates of the outer contour points in the convex set region corresponding to the discrete region. As shown in fig. 3g, the outer contour point corresponding to the discrete region in the convex set region is the contour point region labeled 351 in fig. 3g, and a target gray-scale value is determined by the ordinate (within the range of [0, 255 ]) of the coordinate of each contour point in the contour point region, and the target gray-scale value at this time is the gray-scale value of the pixel point in the nth row after transformation and corresponds to the original gray-scale value (within the range of [0, 255 ]).
For example, the discrete points of the discrete regions in the coordinate space in the above example are (1, 177), (2, 175), (3, 178), (4, 180), \30; \8230; (m-4, 177), (m-3, 163), (m-2, 142), (m-1, 165), (m, 180), and after steps 230 and 240, the contour points in the corresponding contour point regions are (1, 176), (2, 176), (3, 177), (4, 178), \8230;, (m-4, 178), (m-3, 178), (m-2, 177), (m-1, 177), (m, 176); the target gray values determined by the contour point regions are 176, 177, 178, 177, 176 in sequence; the target gray value of the pixel point corresponds to the initial gray value of the pixel point in the Nth row.
Further, a target foreground region is determined by the target gray value, and fig. 3h shows a schematic diagram of the target foreground region after inverse transformation of the convex set region in fig. 3g, as shown in fig. 3h, and the target foreground region 360 after inverse transformation.
The process from the step 220 to the step 240 converts the initial foreground area from the gray scale space to the coordinate space, the gray scale change of the image shows the corresponding curve change in the coordinate space, the gray scale adjustment of the image is converted into the adjustment of the curve value, finally, the changed curve value is inversely converted into the gray scale space, the preset curved surface fitting is completed, and the influence caused by uneven background illumination is weakened through the preset curved surface fitting process.
The higher the fitting precision of the target foreground area is, the better the illumination unevenness eliminating effect is.
As shown in fig. 2, the method further includes: and S250, determining weak defects based on the difference value image of the initial foreground region and the target foreground region.
The illumination unevenness can be eliminated by determining the difference image of the initial foreground area and the target foreground area, and the higher the fitting precision of the target foreground area is, the better the illumination unevenness eliminating effect is.
The difference image between the initial foreground region and the target foreground region can be determined by the following formula:
g=(g 1 -g 2 )×Mult+Add
wherein g is a difference image, g 1 As an initial foreground region, g 2 And taking Mult as a multiplying coefficient and Add as an adding coefficient for the target foreground area.
Fig. 3i shows a schematic diagram of a difference image determined by the initial foreground region in fig. 3b and the target foreground region in fig. 3g, as shown in fig. 3i, which is a difference image 370 after the illumination unevenness is eliminated.
Based on the fact that the gray value of the defect position is lower than that of the non-defect position after illumination unevenness is eliminated, extraction of the outline of the weak defect possibly caused by the weak defect through extraction of the dynamic threshold is small, the embodiment of the application provides that the weak defect is segmented through a high-low threshold method, a suspected defect position is determined through a preset gray high threshold, and then the weak defect is segmented through a preset gray low threshold near the position. Fig. 6 is a flowchart illustrating a weak defect determination method based on a difference image according to an embodiment of the present application, where as shown in fig. 6, the method includes the following steps:
s2501, screening out suspicious regions from the difference image according to a preset gray level high threshold value and a first dynamic threshold value condition corresponding to the preset gray level high threshold value.
The first dynamic threshold condition is determined based on a preset gray level high threshold and a preset first deviation value, and the first dynamic threshold condition is used for segmenting a first image meeting the preset gray level high threshold and determining a suspicious region based on the first image and a difference image.
Firstly, an image after preset gray level high threshold processing can be segmented by the following formula:
Figure BDA0004020751820000081
wherein g is a difference image, g h Offset for an image processed by a preset gray level high threshold 1 In order to set the first deviation value, light is a bright defect and dark is a dark defect.
And then screening out suspicious regions from the difference image through the image processed by the preset gray level high threshold value.
S2502, screening weak defects from the suspicious region according to the preset gray level low threshold value and a second dynamic threshold value condition corresponding to the preset gray level low threshold value.
And the second dynamic threshold condition is determined based on a preset gray level low threshold value and a preset second deviation value, and is used for segmenting a second image meeting the preset gray level low threshold value and determining the weak defect based on the second image and the difference image.
Firstly, an image after preset gray level low threshold processing can be segmented by the following formula:
Figure BDA0004020751820000091
wherein g is a difference image, g1 is an image processed by a preset gray level low threshold, offset 2 To set the second deviation value, light is a bright defect and dark is a dark defect.
And screening weak defects from the suspicious region through the image processed by the preset gray level low threshold value.
In some embodiments, a defect region can be screened from the difference image through the image after the preset gray level low threshold processing; the area where the suspicious region and the defect region intersect is a weak defect.
In some embodiments, if the obtained image to be detected has a row or a column that is both the product surface image, the processes from step 220 to step 250 may be performed in the manner of the row or the column, so as to reduce the extraction process of the initial foreground region.
The defect detection method comprises the steps that when an image to be detected contains weak defects, an initial foreground area of the image to be detected can be determined, initial gray values of pixel points of each row or pixel point of each column in the initial foreground area are mapped to discrete points of a coordinate space, and the discrete area in the coordinate space can be determined; the method comprises the steps of determining a target closed region in a coordinate space and a convex set region of the target closed region based on a preset straight line region and a discrete region in the coordinate space, returning a target gray value corresponding to an initial gray value based on coordinates of an outer contour point corresponding to the discrete region in the convex set region, and further determining a target foreground region; finally, based on the difference image of the initial foreground area and the target foreground area, the weak defect can be determined. By the method, the gray difference between the weak defect and other parts of the image is enhanced, and the weak defect detection effect in the weak defect detection process is improved.
Fig. 7 is a schematic flow chart illustrating a defect detection method provided by an embodiment of the present application, and as shown in fig. 7, the embodiment of the present application provides a defect detection method, which further includes the following steps between step 210 and step 220 in the defect detection method of fig. 2:
and S410, preprocessing the initial foreground area.
The difference of each area can be enhanced through pretreatment, and the pretreatment method comprises the following steps: the method comprises graying, binaryzation, image enhancement, filtering and denoising, image amplification and the like; wherein the image enhancement comprises frequency domain image enhancement and time domain image enhancement; temporal image enhancement includes: gray scale stretching, gamma correction, histogram equalization, histogram specification, and the like.
The image enhancement method comprises the following steps: and (3) performing difference between the original image and the filtered image, and performing gray level stretching on the difference image to achieve the purpose of enhancing the defect, wherein the difference between the original image and the filtered image is used for eliminating the influence of part of background.
In general, when the image to be detected has noise, the preprocessing can be performed by the following formula:
res=round(ori-mean)×factor+ori
in the formula, res is the enhanced alternative foreground region, round is a rounding function, mean is a mean filtered image of the initial foreground region, ori is the initial foreground region, and factor is an enhanced multiple.
In some embodiments, the image to be detected has no noise, and the initial foreground region image may not be preprocessed, and whether the image preprocessing is used or not may be determined according to actual conditions.
Corresponding to step 220, after step 410, the determination of the discrete region may be accomplished by:
and S420, mapping the initial gray value of each row of pixel points or each column of pixel points in the alternative foreground region obtained after preprocessing to a coordinate space, and determining a discrete region.
The implementation principle and technical effect of step 420 and the following steps are similar to those of the above method embodiments, and are not described herein again. According to the embodiment of the application, the difference between the background and the foreground is enhanced and the detection effect is improved by preprocessing the initial foreground area.
Fig. 8 shows a schematic structural diagram of a defect detection apparatus provided in an embodiment of the present application, and as shown in fig. 8, the defect detection apparatus 800 includes a foreground detection module 810, a first conversion module 820, a second conversion module 830, and a defect detection module 840, where:
the foreground detection module is used for determining an initial foreground area of an image to be detected, and the image to be detected contains weak defects;
the first conversion module is used for mapping the initial gray values of the pixel points in each row or column in the initial foreground area to a coordinate space and determining a discrete area in the coordinate space, wherein the discrete area is formed by the initial gray values of the pixel points;
the second conversion module is used for determining a target closed area in the coordinate space based on a preset straight line area and a discrete area in the coordinate space; the method is also used for determining a convex set region of the closed region, and determining a target gray value corresponding to the initial gray value based on a coordinate space of an outer contour point corresponding to the discrete region in the convex set region; wherein the convex set region is the smallest convex hull that contains the target occlusion region.
And the defect detection module is used for determining weak defects based on the difference image of the initial foreground region and the target foreground region, and the target foreground region is determined by the target gray value.
In some embodiments, the second conversion module includes an area determination unit, configured to perform area closure processing on a preset straight line area and a discrete area in a coordinate space to obtain an initial closed area; and also for removing the interference in the discrete edges of the initial occlusion region, resulting in a target occlusion region.
In some embodiments, the defect detection module includes a dynamic determination unit, and the dynamic determination unit is configured to screen out a suspicious region from the difference image according to a preset gray level high threshold and a first dynamic threshold condition corresponding to the preset gray level high threshold; and the method is also used for screening out weak defects from the suspicious region according to the preset gray level low threshold value and a second dynamic threshold value condition corresponding to the preset gray level low threshold value.
The first dynamic threshold condition is determined based on a preset gray level high threshold value and a preset first deviation value, and is used for segmenting a first image meeting the preset gray level high threshold value and determining a suspicious region based on the first image and a difference image; the second dynamic threshold condition is determined based on a preset gray level low threshold and a preset second deviation value, the second dynamic threshold condition is used for segmenting a second image meeting the preset gray level low threshold, and the weak defect is determined based on the second image and the difference image.
In some embodiments, the foreground detection module includes a preprocessing unit configured to divide the foreground image into a plurality of initial foreground regions when a size of the foreground image in the image to be detected is larger than a size of a preset processing region.
In some embodiments, the defect detection apparatus further includes a preprocessing module, configured to perform preprocessing on the initial foreground region and determine a candidate foreground region; at this time, the first conversion module is further configured to map the initial gray values of the pixel points in each row or each column in the candidate foreground region to a coordinate space, and determine the discrete region.
The embodiment of the application provides a defect detection device, which comprises a foreground detection module, a first conversion module, a second conversion module and a defect detection module, wherein the foreground detection module can be used for determining an initial foreground area of an image to be detected when the image to be detected contains weak defects; the first conversion module is used for mapping the initial gray value of each row of pixel points or each column of pixel points in the initial foreground area to a discrete area in a coordinate space; the second conversion module is used for realizing the determination of a target closed region in the coordinate space and a convex set region of the target closed region based on a preset straight line region and a discrete region in the coordinate space, and returning a target gray value corresponding to the initial gray value based on the coordinates of an outer contour point corresponding to the discrete region in the convex set region, so as to determine a target foreground region; the defect detection module may be configured to determine weak defects based on a difference image of the initial foreground region and the target foreground region. The defect detection device enhances the gray difference between the weak defect and other parts of the image, and improves the weak defect detection effect in the weak defect detection process.
The terminal device further provided in this embodiment of the present application includes a memory and a processor, where the memory stores a computer program, and the processor executes the computer program, where the computer program is used to implement the defect detection method, and the implementation principle and the technical effect are similar to those of the method embodiment, and are not described herein again.
The embodiment of the present application further provides a computer storage medium, where a computer program is stored on the computer readable storage medium, and the computer program is executed by a processor to perform the defect detection method.
The following paragraphs will provide a comparative listing of Chinese terms and their corresponding English terms referred to in this application for ease of reading and understanding.
The foregoing description, for purposes of explanation, has been presented in conjunction with specific embodiments. However, the foregoing discussion in some embodiments is not intended to be exhaustive or to limit the implementations to the precise forms disclosed above. Many modifications and variations are possible in light of the above teaching. The embodiments were chosen and described in order to best explain the principles and the practical application, to thereby enable others skilled in the art to best utilize the embodiments and various embodiments with various modifications as are suited to the particular use contemplated.

Claims (10)

1. A method of defect detection, comprising:
determining an initial foreground area of an image to be detected, wherein the image to be detected contains weak defects;
mapping the initial gray values of all rows of pixel points or all columns of pixel points in the initial foreground area to a coordinate space, and determining a discrete area in the coordinate space, wherein the discrete area is formed by the initial gray values of the pixel points;
determining a target closed region in the coordinate space based on a preset straight line region and the discrete region in the coordinate space;
determining a convex set region of a target closed region, and determining a target gray value corresponding to the initial gray value based on coordinates of outer contour points corresponding to the discrete regions in the convex set region;
determining the weak defect based on a difference image of the initial foreground region and a target foreground region, the target foreground region being determined by the target gray value.
2. The defect detection method of claim 1, wherein the determining a target closed region in the coordinate space based on the preset straight-line region and the discrete region in the coordinate space comprises:
performing area closing processing on a preset straight line area and the discrete area in the coordinate space to obtain an initial closed area;
removing interference in discrete edges of the initial occlusion region, and determining the target occlusion region.
3. The defect detection method of claim 1, wherein the convex set region is a smallest convex hull containing the target occlusion region.
4. The defect detection method of claim 1, wherein said determining the weak defect based on the difference image of the initial foreground region and the target foreground region comprises:
screening out a suspicious region from the difference image according to a preset gray level high threshold and a first dynamic threshold condition corresponding to the preset gray level high threshold;
and screening the weak defects from the suspicious region according to a preset gray level low threshold value and a second dynamic threshold value condition corresponding to the preset gray level low threshold value.
5. The defect detection method of claim 4, wherein the first dynamic threshold condition is determined based on the preset gray level high threshold and a preset first deviation value, and the first dynamic threshold condition is used for segmenting a first image satisfying the preset gray level high threshold and determining the suspicious region based on the first image and the difference image;
and the second dynamic threshold condition is determined based on the preset gray level low threshold and a preset second deviation value, and is used for segmenting a second image meeting the preset gray level low threshold and determining the weak defect based on the second image and the difference image.
6. The defect detection method of claim I, wherein the step of determining the initial foreground region of the image to be detected comprises:
and if the size of the foreground image in the image to be detected is larger than the size of a preset processing area, dividing the foreground image into a plurality of initial foreground areas.
7. The defect detection method of claim 1, wherein before mapping the initial gray scale value of each row of pixel points or each column of pixel points in the initial foreground region to a coordinate space and determining a discrete region, the method further comprises:
and performing preprocessing on the initial foreground area.
8. A defect detection apparatus, comprising:
the foreground detection module is used for determining an initial foreground area of an image to be detected, and the image to be detected contains weak defects;
the first conversion module is used for mapping the initial gray values of all rows of pixel points or all columns of pixel points in the initial foreground area to a coordinate space and determining a discrete area in the coordinate space, wherein the discrete area is formed by the initial gray values of the pixel points;
the second conversion module is used for determining a target closed region in the coordinate space based on a preset straight line region and the discrete region in the coordinate space; the method is also used for determining a convex set region of a closed region, and determining a target gray value corresponding to the initial gray value based on a coordinate space of an outer contour point corresponding to the discrete region in the convex set region;
a defect detection module to determine the weak defect based on a difference image of the initial foreground region and a target foreground region, the target foreground region being determined by the target grayscale value.
9. A terminal device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor, when executing the computer program, implements the steps of the defect detection method of any one of claims 1 to 7.
10. A computer storage medium, characterized in that the computer readable storage medium has stored thereon a computer program which, when executed by a processor, causes the processor to carry out the steps of the defect detection method of any one of claims 1 to 7.
CN202211689608.0A 2022-12-27 2022-12-27 Defect detection method and device, terminal device and storage medium Pending CN115797327A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211689608.0A CN115797327A (en) 2022-12-27 2022-12-27 Defect detection method and device, terminal device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211689608.0A CN115797327A (en) 2022-12-27 2022-12-27 Defect detection method and device, terminal device and storage medium

Publications (1)

Publication Number Publication Date
CN115797327A true CN115797327A (en) 2023-03-14

Family

ID=85426954

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211689608.0A Pending CN115797327A (en) 2022-12-27 2022-12-27 Defect detection method and device, terminal device and storage medium

Country Status (1)

Country Link
CN (1) CN115797327A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117274241A (en) * 2023-11-17 2023-12-22 四川赢信汇通实业有限公司 Brake drum surface damage detection method and device based on rapid image analysis

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117274241A (en) * 2023-11-17 2023-12-22 四川赢信汇通实业有限公司 Brake drum surface damage detection method and device based on rapid image analysis
CN117274241B (en) * 2023-11-17 2024-02-09 四川赢信汇通实业有限公司 Brake drum surface damage detection method and device based on rapid image analysis

Similar Documents

Publication Publication Date Title
CN110866924B (en) Line structured light center line extraction method and storage medium
CN110033471B (en) Frame line detection method based on connected domain analysis and morphological operation
CN108416766B (en) Double-side light-entering type light guide plate defect visual detection method
CN112819772B (en) High-precision rapid pattern detection and recognition method
CN110084241B (en) Automatic ammeter reading method based on image recognition
CN109658424B (en) Improved robust two-dimensional OTSU threshold image segmentation method
CN103325118A (en) Method and device for acquiring characteristic parameters of core hole of carbonatite
CN106651792B (en) Method and device for removing stripe noise of satellite image
CN113781406B (en) Scratch detection method and device for electronic component and computer equipment
CN112085651B (en) Automatic shock wave detection and tracking algorithm based on image self-adaptive threshold and feature extraction
CN114782329A (en) Bearing defect damage degree evaluation method and system based on image processing
CN109064479B (en) Sea-sky-line detection method based on gray dynamic features of adjacent video frames
CN114926407A (en) Steel surface defect detection system based on deep learning
CN113192059A (en) On-orbit ship detection method based on infrared remote sensing image
CN113514054A (en) Star sensor star point image spot detection method and system
CN114549441A (en) Sucker defect detection method based on image processing
CN115797327A (en) Defect detection method and device, terminal device and storage medium
CN114298985B (en) Defect detection method, device, equipment and storage medium
CN115294149A (en) Astronomical image background extraction method and system
CN102509265B (en) Digital image denoising method based on gray value difference and local energy
CN116883408B (en) Integrating instrument shell defect detection method based on artificial intelligence
CN108205678B (en) Nameplate character recognition processing method containing bright spot interference
GB2385187A (en) Dynamic thresholding of binary images
US20060126136A1 (en) Image inspecting apparatus, image inspecting method, control program and computer-readable storage medium
CN110633705A (en) Low-illumination imaging license plate recognition method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination