An image-based automatic defect detection method and system

The automatic defect detection method integrating light source, camera and image processing system solves the problems of manual setting of defect area threshold and misjudgment caused by changes in ambient light in the existing technology. It realizes automatic calculation of defect area threshold and improves detection efficiency and accuracy.

CN116894813BActive Publication Date: 2026-02-24CHONGQING ZHONGKE SAILBOAT INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310785903.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-29
Publication Date
2026-02-24
Estimated Expiration
2043-06-29

AI Technical Summary

Technical Problem

Existing defect detection methods require manually setting a threshold for the defect area, and changes in ambient light may lead to misjudgments.

Method used

An image-based automatic defect detection system is adopted, which controls the brightness of the light source by switching, uses a camera to capture images, and performs segmentation, correlation and area threshold calculation by the image processing system. The automatic detection method and the image processing system perform defect detection, which includes the integration of the light source, camera and image processing system.

Benefits of technology

It enables automatic calculation of defect area thresholds without relying on manual setting of area thresholds, reducing manual labor, improving detection efficiency and accuracy, ensuring image clarity, and adapting to changes in ambient light.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116894813B_ABST
    Figure CN116894813B_ABST
Patent Text Reader

Abstract

The application provides an image-based defect automatic detection method and system, which is applied to an image-based defect automatic detection system, and comprises a switch, a light source for providing illumination for a to-be-detected object, a camera for shooting the to-be-detected object to obtain a to-be-detected image and sending the to-be-detected image to an image processing system, the image processing system for acquiring the to-be-detected image, segmenting the to-be-detected image to obtain a segmented image block and a histogram of the segmented image block, correcting the image brightness according to the histogram and calculating the correlation of the segmented image block, marking the segmented image block when the correlation of the segmented image block is greater than a correlation threshold value to obtain a marked segmented image, acquiring an area threshold value, calculating the area of the connected marked segmented image, marking the image when the area is greater than the area threshold value to obtain a marked area image, and restoring the marked area image to obtain a defect image with marks. The application can prevent errors caused by environmental light changes, does not need to manually specify an area threshold value, and is more accurate in defect detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image defect technology, and in particular to an automatic defect detection method and system based on images. Background Technology

[0002] As living standards improve, industrial production becomes increasingly specialized. A key characteristic of industrial production is the mechanization and automation of the production process. Due to the large-scale and high-volume nature of automated production, minor deviations and defects sometimes occur. Existing defect detection methods typically require manually setting defect area thresholds for automatic detection, and changes in ambient light during the detection process can lead to misjudgments. Summary of the Invention

[0003] Therefore, it is necessary to provide an image-based automatic defect detection method and system to address the aforementioned technical problems.

[0004] An automatic defect detection method based on images is applied to an image-based automatic defect detection system, which includes a switch, a light source, a camera, and an image processing system; wherein the light source and the camera are located above the object to be tested; and the switch, light source, camera, and image processing system are communicatively connected.

[0005] Includes the following steps:

[0006] The switch controls the switching on and off and the brightness of the light source;

[0007] The light source provides illumination for the object under test;

[0008] The camera captures images of the object to be tested, obtains an image of the object to be tested, and sends the image of the object to be tested to the image processing system.

[0009] The image processing system acquires a test image, segments the test image to obtain multiple segmented image blocks and histograms of the segmented image blocks; corrects the brightness of the segmented image blocks according to the histograms, calculates the correlation of the multiple segmented image blocks, and marks the segmented image blocks to obtain marked segmented images when the correlation of the segmented image blocks is greater than a correlation threshold; obtains an area threshold, calculates the area of ​​connected marked segmented images, and marks connected marked segmented images to obtain marked area images when the area is greater than the area threshold; and restores the marked area images to their original size to obtain a marked defect image.

[0010] In one embodiment, the image to be tested is acquired, and the image to be tested is segmented to obtain multiple segmented image blocks, and the histogram of the segmented image blocks includes:

[0011] The image to be tested is segmented based on a preset size to obtain a group of image blocks to be tested; wherein, the group of image blocks to be tested includes multiple segmented image blocks;

[0012] Calculate the gray-level histogram for each segmented image block to obtain the histogram;

[0013] h I =num(s) a,b =I)

[0014] Among them, h I This represents the value in the i-th column of the histogram, where num() represents the count function, and s a,b This represents the pixel value at row a and column b in the segmented image block, where I represents the column number of the histogram.

[0015] In one embodiment, correcting the brightness of the segmented image blocks based on the histogram and calculating the correlation of multiple segmented image blocks includes:

[0016] Obtain a standard histogram, and calculate the grayscale transformation function of the segmented image block based on the standard histogram and the histogram;

[0017] Based on the grayscale value transformation function, pixel-by-pixel correction is performed using interpolation to obtain a brightness-corrected segmented image;

[0018] The brightness-corrected segmented image is smoothed using a Gaussian filter to obtain the corrected image;

[0019] The correlation of the corrected image is calculated based on the normalized squared difference.

[0020] In one embodiment, obtaining a standard histogram includes:

[0021] Obtain a group of defect-free images, and calculate the mean image based on the group of defect-free images:

[0022]

[0023] Wherein, m r,c Let n represent the mean image, n represent the number of defect-free images in the defect-free image group, and i represent the i-th defect-free image. Represents the pixel value in row r and column c of the i-th defect-free image;

[0024] Based on the defect-free image set and the mean image, calculate the standard deviation image and the standard deviation of the standard deviation image:

[0025]

[0026]

[0027] Wherein, the dev r,c Let represent the standard deviation image, n represent the number of defect-free images in the defect-free image group, and i represent the i-th defect-free image. This represents the pixel value in row r and column c of the i-th defect-free image. σ represents the pixel values ​​in r rows and c columns of the mean image, σ represents the standard deviation of the standard deviation image, M represents the preset segmentation size of M rows, and N represents the preset segmentation size of N columns. The pixel mean of the standard deviation image;

[0028] The mean image is segmented based on a preset size to obtain a group of defect-free image blocks; wherein, the group of defect-free image blocks includes multiple defect-free image segmentation blocks;

[0029] Calculate the grayscale histogram of each defect-free image segment to obtain the standard histogram:

[0030] h J =num(t) r,c =J)

[0031] Among them, h J This represents the value in column J of the standard histogram, where num() represents the count function, and t r,c This represents the pixel value at the r-th row and c-th column in the segmented image block, where J represents the standard histogram column number.

[0032] In one embodiment, calculating the grayscale transformation function of the segmented image patch based on the standard histogram and the histogram includes:

[0033] The grayscale transformation function of the segmented image is calculated using the following formula:

[0034]

[0035]

[0036] z q =G -1 (s k )

[0037] Among them, s k The transform function T(r) represents the grayscale value after transformation, L represents the grayscale level, M represents the preset segmentation size of M rows, N represents the preset segmentation size of N columns, k represents the k-th grayscale level, and n represents the grayscale value after transformation. j G(z) represents the number of pixels with a grayscale value of j, where j represents a certain grayscale value j. q ) represents the standard image transformation function, q represents the q-th gray level, i represents a certain gray level i, and p z z represents the probability of a certain gray value in the standard histogram.i z represents the i-th gray level in the standard histogram. q G represents the corrected pixel value. -1 (s k ) is represented as G(z) q The inverse function of ) satisfies G(z) q ) = s k .

[0038] In one embodiment, obtaining the area threshold includes:

[0039] A defect image is acquired, and a Gaussian filter is used to smooth the defect image to obtain a standard defect image. The standard defect image is then segmented based on a preset size to obtain a defect image block group; wherein, the defect image block group includes multiple defect image segmentation blocks.

[0040] Calculate the correlation between the defective image patch group and the defect-free image patch group:

[0041]

[0042] Where s(x,y) represents the correlation between defective and defect-free image segments, x′ represents the difference in the horizontal coordinate between defective and defect-free image segments, y′ represents the difference in the vertical coordinate between defective and defect-free image segments, T() represents the group of defect-free image blocks, I() represents the group of defective image blocks, and c' T r represents the x-coordinate of a defect-free image segmentation block within a defect-free image block group. T ' represents the ordinate of a defect-free image segment within a group of defect-free image blocks, c' I r represents the x-coordinate of a defective image segmentation block within a defective image block group. I 'Represents the ordinate of a segment of a defective image within a group of defective image blocks;

[0043] The inter-class variance of similarity is calculated using the following formula, and the similarity threshold is set as the value at which the inter-class variance of similarity is maximized:

[0044]

[0045] in, Let represent the inter-class variance of similarity, P1 represent the probability that the similarity threshold is less than or equal to i, P represent the probability that the similarity threshold is greater than i, m1 represent the average similarity when the similarity threshold is less than or equal to i, and m2 represent the average similarity when the similarity threshold is less than or equal to i. G Indicates average similarity;

[0046] The defective image is segmented according to the similarity threshold to obtain multiple threshold-segmented images;

[0047] Calculate the area of ​​the threshold segmented image, and set the area of ​​the threshold segmented image with the largest area as the area threshold.

[0048] In one embodiment, restoring the marked area image to its original size includes:

[0049] The marked area image is restored to its original size using the following formula:

[0050]

[0051] Where, x E The x-coordinate of a pixel after transformation is represented by y. F r represents the ordinate of a pixel after transformation. ** Represents the elements of a two-dimensional rotation matrix, t x t represents the horizontal axis offset. y The x-axis represents the offset of the vertical axis. e The x-coordinate of a pixel before the transformation is represented by y. f This represents the ordinate of a pixel before the transformation.

[0052] An image-based automatic defect detection system is provided to implement the image-based automatic defect detection method and system described above. The system includes a switch, a light source, a camera, and an image processing system. The light source and the camera are located above the object to be tested. The switch, light source, camera, and image processing system are communicatively connected.

[0053] The switch is used to control the switching on and off and the brightness of the light source;

[0054] The light source is used to provide illumination for the object under test;

[0055] The camera is used to photograph the object to be tested, obtain an image of the object to be tested, and send the image of the object to be tested to the image processing system.

[0056] The image processing system is configured to acquire a test image, segment the test image to obtain multiple segmented image blocks and histograms of the segmented image blocks; correct the brightness of the segmented image blocks according to the histograms, calculate the correlation of the multiple segmented image blocks, and mark the segmented image blocks to obtain marked segmented images when the correlation of the segmented image blocks is greater than a correlation threshold; acquire an area threshold, calculate the area of ​​connected marked segmented images, and mark connected marked segmented images to obtain marked area images when the area is greater than the area threshold; and restore the marked area images to their original size to obtain a marked defect image.

[0057] Compared with existing technologies, the advantages and beneficial effects of this invention are as follows: This invention provides an image-based automatic defect detection method, applicable to an integrated image-based automatic defect detection system comprising a switch, light source, camera, and image processing system. It can directly perform multiple functions including light source adjustment, image capture, and detection, ensuring constant ambient light and maintaining the clarity of the image captured of the object under test. This allows the image to clearly display the defect location. An area threshold is calculated based on a preset defect image, eliminating the need for manual determination of the area threshold. This improves the transferability of the invention, reduces manual labor, and increases detection efficiency while ensuring detection accuracy. Attached Figure Description

[0058] Figure 1 This is a schematic diagram illustrating an application scenario of an image-based automatic defect detection method in one embodiment;

[0059] Figure 2 This is a flowchart illustrating an image-based automatic defect detection method in one embodiment.

[0060] Figure 3 This is a schematic diagram of the segmentation dimensions in one embodiment;

[0061] Figure 4 This is an interpolation diagram in one embodiment;

[0062] Figure 5 This is a schematic diagram of a segmented image block before correction in one embodiment;

[0063] Figure 6 This is a schematic diagram of the corrected segmented image in one embodiment;

[0064] Figure 7 This is a schematic diagram of the mean image in one embodiment;

[0065] Figure 8 This is a schematic diagram of the structure of an image-based automatic defect detection system in one embodiment. Detailed Implementation

[0066] Before describing the specific embodiments of the present invention, the overall concept of the present invention will be explained as follows:

[0067] This invention primarily focuses on the development of image defect detection processes. Current defect detection methods involve the following training steps: First, a template is created in a non-detection region with obvious features, and a detection region is specified. The template is used to locate the non-detection region in a defect-free image. Position correction is used to determine the location of the detection region within the image. Then, the image corresponding to the detection region is corrected, and its mean and standard deviation are calculated. A threshold image is calculated based on coefficients and offsets. The detection process involves using the template to locate the non-detection region in a real-time image and obtaining the detection region through position correction. The image corresponding to the detection region is corrected, and its difference from the mean image is calculated. Then, the difference is compared pixel-by-pixel with the threshold image. When the difference is greater than the threshold image, the point is marked as a defect. Connected defect regions are then extracted. When the area of ​​a region exceeds a preset area threshold, a defect image is output. Existing defect detection methods typically require manually setting the defect area threshold for automatic detection, and changes in ambient light during the detection process can lead to misjudgments.

[0068] This invention proposes an image-based automatic defect detection method that can automatically calculate an area threshold and perform automatic image defect detection based on the area threshold.

[0069] After introducing the overall concept of the present invention, in order to make the objectives, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below through specific embodiments and in conjunction with the accompanying drawings.

[0070] It should be noted that, unless otherwise defined, the technical or scientific terms used in one or more embodiments of this specification should have the ordinary meaning understood by one of ordinary skill in the art to which this invention pertains. The terms "first," "second," and similar terms used in one or more embodiments of this specification do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Terms such as "comprising" or "including" mean that the element or object preceding the word covers the element or object listed following the word and its equivalents, without excluding other elements or objects. Terms such as "connected" or "linked" are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. Terms such as "upper," "lower," "left," and "right" are used only to indicate relative positional relationships; when the absolute position of the described object changes, the relative positional relationship may also change accordingly.

[0071] Figure 1 The illustration shows an application scenario of an image-based automatic defect detection method according to an embodiment of the present invention.

[0072] like Figure 1As shown, the application scenarios include a zoomable industrial camera, a ring-shaped light source with independently controllable switches and brightness, and an image processing system. During use, the object to be tested is placed directly below the industrial camera, and the light source is controlled by the switch to provide illumination. The zoomable industrial camera is used to capture the image to be tested, and the image to be tested is sent to the image processing system. After the image processing system obtains the image to be tested, it performs inspection on the image to obtain a defective image or a defect-free image.

[0073] In one embodiment, such as Figure 2 As shown, an image-based automatic defect detection method is provided, which is applied to an image-based automatic defect detection system including a switch, a light source, a camera, and an image processing system; wherein, the light source and the camera are located above the object to be tested; the switch, the light source, the camera, and the image processing system are communicatively connected;

[0074] Includes the following steps:

[0075] Step S101: The switch controls the switching and brightness of the light source.

[0076] Specifically, the switches can be independently controllable switches distributed in a ring, which can adjust the opening and closing of the light source and the brightness of the light source.

[0077] In this embodiment, an independently controllable switch is used to automatically adjust the brightness so that the object under test is under the same ambient light.

[0078] Step S102: The light source provides illumination to the object under test.

[0079] Specifically, the light source can be either a thermal radiation light source (incandescent lamps and halogen lamps) or a gas discharge light source (arc discharge, glow discharge, neon lamps, etc.).

[0080] In this embodiment, a power source is used to provide illumination for the item under test, ensuring the clarity of the image captured by the item under test, so that the image can clearly show the location of the defect.

[0081] Step S103: The camera takes a picture of the object to be tested to obtain an image to be tested, and sends the image to be tested to the image processing system.

[0082] Specifically, the camera can be a zoom industrial camera, a digital camera, etc. Using a zoom industrial camera to photograph the object under test yields a clear image, which can then be used to identify defects in the object.

[0083] Step S104: The image processing system acquires the image to be tested, segments the image to be tested to obtain multiple segmented image blocks and histograms of the segmented image blocks; corrects the brightness of the segmented image blocks according to the histograms, calculates the correlation of the multiple segmented image blocks, and marks the segmented image blocks to obtain marked segmented images in response to the correlation of the segmented image blocks being greater than a correlation threshold; obtains an area threshold, calculates the area of ​​the connected marked segmented images, and marks the connected marked segmented images to obtain marked area images in response to the area being greater than the area threshold; restores the marked area images to their original size to obtain a marked defect image.

[0084] Specifically, the object to be tested is segmented to obtain multiple segmented image blocks and histograms of these blocks. Each segmented image block has the same size. The correlation between the histograms and the correlation threshold is then determined. If the correlation value of a segmented image block is greater than the threshold, it is marked, resulting in a marked segmented image. The correlation of each segmented image block is compared with the correlation threshold, and each block with a correlation value greater than the threshold is marked, resulting in multiple marked segmented images. Connected marked segmented images are treated as a whole, and their areas are calculated. These areas are compared with an acquired area threshold. If the area of ​​a connected marked segmented image is greater than the area threshold, its area is marked, resulting in a marked area image. The marked area image is then restored to its original size according to the segmentation method, resulting in a marked defect image. When a marked defect image exists in the original size of the object to be tested, the object to be tested is determined to be a defective image; otherwise, it is determined to be a defect-free image.

[0085] In this embodiment, the test image captured by the camera is acquired and segmented. It is not necessary to manually specify the area threshold of the defect image region. The area threshold is directly obtained for defect judgment, which can improve the transferability of the method and improve the accuracy of defect judgment.

[0086] Specifically, step S104 includes: acquiring the image to be tested, segmenting the image to be tested to obtain multiple segmented image blocks, and the histogram of the segmented image blocks, including:

[0087] The image to be tested is segmented based on a preset size to obtain a group of image blocks to be tested; wherein, the group of image blocks to be tested includes multiple segmented image blocks;

[0088] Calculate the gray-level histogram for each segmented image block to obtain the histogram;

[0089] h I =num(s) a,b =I)

[0090] Among them, h I This represents the value in the i-th column of the histogram, where num() represents the count function, and s a,b This represents the pixel value at row a and column b in the segmented image block, where I represents the column number of the histogram.

[0091] Specifically, the image to be tested is segmented according to preset dimensions. These preset dimensions are specified by the user based on the actual situation and can be multiple sizes such as 3×4, 6×9, and 30×40. A specific segmentation size diagram is shown below. Figure 3 As shown. Calculate the gray-level histogram for each segmented image block, and arrange the gray-level histograms in order to generate a histogram.

[0092] Step S104 further includes: correcting the brightness of the segmented image blocks according to the histogram, and calculating the correlation of multiple segmented image blocks, including:

[0093] Obtain a standard histogram, and calculate the grayscale transformation function of the segmented image block based on the standard histogram and the histogram;

[0094] Based on the grayscale value transformation function, pixel-by-pixel correction is performed using interpolation to obtain a brightness-corrected segmented image;

[0095] The brightness-corrected segmented image is smoothed using a Gaussian filter to obtain the corrected image;

[0096] The correlation of the corrected image is calculated based on the normalized squared difference.

[0097] Specifically, a standard histogram is obtained. Based on the standard histogram and the histogram formed from multiple segmented image blocks, a grayscale transformation function for the grayscale values ​​of the segmented image blocks is derived. According to the grayscale transformation function of the region where a pixel is located and its neighboring regions, interpolation is used to correct the segmented image blocks pixel by pixel, resulting in a brightness-corrected segmented image. This brightness-corrected segmented image is then smoothed using a Gaussian filter with a mean of 0 and a standard deviation of 6σ. A specific interpolation diagram is shown below. Figure 4 As shown, the segmented image patch before correction is as follows: Figure 5 As shown, the corrected brightness-corrected segmented image is as follows: Figure 6 As shown.

[0098] In this embodiment, pixel interpolation is used to correct the detection image. The nearest neighbor interpolation method has the advantages of low computational cost, simple algorithm, and fast processing speed. A Gaussian filter is used for smoothing correction, which can eliminate noise and preserve image details, making the processed image smoother and more natural. Gaussian filtering is particularly effective for small noise blocks or striped noise.

[0099] Based on this, obtaining the standard histogram includes:

[0100] Obtain a group of defect-free images, and calculate the mean image based on the group of defect-free images:

[0101]

[0102] Wherein, m r,c Let represent the mean image, n represent the number of defect-free images in the defect-free image group, and i represent the defect-free image number. Represents the pixel value in row r and column c of the i-th defect-free image;

[0103] Based on the defect-free image set and the mean image, calculate the standard deviation image and the standard deviation of the standard deviation image:

[0104]

[0105]

[0106] Wherein, the dev r,c This represents the standard deviation image, where n represents the number of defect-free images in the defect-free image group, and i represents the defect-free image number. This represents the pixel value in row r and column c of the i-th defect-free image. Let represent the pixel value in row r and column c of the i-th defect-free image, σ represent the standard deviation of the image, M represent the preset segmentation size of M rows, and N represent the preset segmentation size of N columns. The pixel mean of the standard deviation image;

[0107] The mean image is segmented based on a preset size to obtain a group of defect-free image blocks; wherein, the group of defect-free image blocks includes multiple defect-free image segmentation blocks;

[0108] Calculate the grayscale histogram of each defect-free image segment to obtain the standard histogram:

[0109] h J =num(t) r,c =J)

[0110] Among them, h JThis represents the value in column J of the standard histogram, where num() represents the count function, and t r,c This represents the pixel value at the r-th row and c-th column in the segmented image block, where J represents the standard histogram column number.

[0111] Specifically, the mean image m is calculated based on the corrected set of defect-free images. r,c The specific mean image is as follows: Figure 7 As shown. Then, the standard deviation image and the standard deviation of the image are calculated based on the mean image and the defect-free image group. Then, the mean image is segmented according to the preset size M×N to obtain the defect-free image block group; wherein, the defect-free image block group includes multiple defect-free image segmentation blocks; the gray-level histogram of each defect-free image segmentation block is calculated, and the gray-level histograms are arranged in order to obtain the standard histogram.

[0112] In this embodiment, a standard histogram is calculated based on the defect-free image group. By comparing the standard histogram with the histogram of the image to be tested, the difference between the image to be tested and the defect-free image can be determined, and the defective image can be obtained.

[0113] Based on this, the grayscale transformation function for segmenting image blocks is calculated according to the standard histogram and the histogram, including:

[0114] The grayscale transformation function of the segmented image is calculated using the following formula:

[0115]

[0116]

[0117] z q =G -1 (s k )

[0118] Among them, s k The transform function T(r) represents the grayscale value after transformation, L represents the grayscale level, M represents the preset segmentation size of M rows, N represents the preset segmentation size of N columns, k represents the k-th grayscale level, and n represents the grayscale value after transformation. j G(z) represents the number of pixels with a grayscale value of j, where j represents a certain grayscale value j. q ) represents the standard image transformation function, q represents the q-th gray level, i represents a certain gray level i, and p z z represents the probability of a certain gray value in the standard histogram. i z represents the i-th gray level in the standard histogram. q G represents the corrected pixel value. -1 (s k ) is represented as G(z) q The inverse function of ) satisfies G(z) q) = s k .

[0119] Specifically, the grayscale transformation function of the histogram of the image under test and the standard histogram of the defect-free image group is calculated according to the formula. Image correction can then be performed using the grayscale transformation function.

[0120] Step S104 further includes: obtaining the area threshold, including:

[0121] A defect image is acquired, and a Gaussian filter is used to smooth the defect image to obtain a standard defect image. The standard defect image is then segmented based on a preset size to obtain a defect image block group; wherein, the defect image block group includes multiple defect image segmentation blocks.

[0122] Calculate the correlation between the defective image patch group and the defect-free image patch group:

[0123]

[0124] Where s(x,y) represents the correlation between defective and defect-free image segments, x′ represents the difference in the horizontal coordinate between defective and defect-free image segments, y′ represents the difference in the vertical coordinate between defective and defect-free image segments, T() represents the group of defect-free image blocks, I() represents the group of defective image blocks, and c' T r represents the x-coordinate of a defect-free image segmentation block within a defect-free image block group. T ' represents the ordinate of a defect-free image segment within a group of defect-free image blocks, c' I r represents the x-coordinate of a defective image segmentation block within a defective image block group. I 'Represents the ordinate of a segment of a defective image within a group of defective image blocks;

[0125] The inter-class variance of similarity is calculated using the following formula, and the similarity threshold is set as the value at which the inter-class variance of similarity is maximized:

[0126]

[0127] in, Let represent the inter-class variance of similarity, P1 represent the probability that the similarity threshold is less than or equal to i, P represent the probability that the similarity threshold is greater than i, m1 represent the average similarity when the similarity threshold is less than or equal to i, and m2 represent the average similarity when the similarity threshold is less than or equal to i. G Indicates average similarity;

[0128] The defective image is segmented according to the similarity threshold to obtain multiple threshold-segmented images;

[0129] Calculate the area of ​​the threshold segmented image, and set the area of ​​the threshold segmented image with the largest area as the area threshold.

[0130] Specifically, a defect image is acquired and smoothed using a Gaussian function with a mean of 0 and a standard deviation of 6σ to obtain a standard defect image. This standard defect image is then segmented based on a preset size M×N to obtain defect image block groups. The correlation between defect image segments and non-defect image segments is calculated using normalized squared difference. Since defect images always contain defective regions, they are always separable by similarity. The inter-class variance of similarity is calculated using a formula, and the similarity threshold is set when the inter-class variance is maximized. This similarity threshold is used to segment the defect image, resulting in multiple threshold-segmented images. The area of ​​each threshold-segmented image is calculated, and the image with the largest area is set as the area threshold.

[0131] In this embodiment, the area threshold is calculated based on the defect image, eliminating the need for manual determination of the area threshold. This improves the transferability of the invention and reduces manual labor costs, thereby increasing detection efficiency while ensuring detection accuracy.

[0132] Step S104 further includes: restoring the marked area image to its original size, including:

[0133] The marked area image is restored to its original size using the following formula:

[0134]

[0135] Where, x E The x-coordinate of a pixel after transformation is represented by y. F r represents the ordinate of a pixel after transformation. ** Represents the elements of a two-dimensional rotation matrix, t x t represents the horizontal axis offset. y The x-axis represents the offset of the vertical axis. e The x-coordinate of a pixel before the transformation is represented by y. f This represents the ordinate of a pixel before the transformation.

[0136] Specifically, the detected marked area image is transformed back onto the original image and displayed, while the image under test is marked as a defective image. If no marked area image that meets the conditions exists, the image under test is marked as a defect-free image.

[0137] This invention provides an image-based automatic defect detection method applicable to an integrated image-based automatic defect detection system comprising a switch, light source, camera, and image processing system. It can directly perform multiple functions including light source adjustment, image capture, and detection, ensuring constant ambient light and high clarity of the captured image of the object under test, clearly displaying the defect location. An area threshold is calculated based on a preset defect image, eliminating the need for manual threshold setting. This improves the transferability of the invention, reduces manual labor, and increases detection efficiency while maintaining accuracy.

[0138] It should be noted that the above description describes some embodiments of the present invention. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims may be performed in a different order than that shown in the above embodiments and still achieve the desired results. Furthermore, the processes depicted in the drawings do not necessarily require a specific or sequential order to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0139] Based on the same inventive concept, corresponding to any of the above embodiments, the present invention also provides an image-based automatic defect detection system.

[0140] refer to Figure 8 The image-based automatic defect detection system includes: a switch 801, a light source 802, a camera 803, and an image processing system 804; wherein the light source 802 and the camera 803 are located above the object to be tested; the switch 801, the light source 802, the camera 803, and the image processing system 804 are communicatively connected.

[0141] The switch 801 is used to control the switching on and off and the brightness of the light source;

[0142] The light source 802 is used to provide illumination for the item under test;

[0143] The camera 803 is used to photograph the object to be tested, obtain the image to be tested, and send the image to be tested to the image processing system 804;

[0144] The image processing system 804 is configured to acquire a test image, segment the test image to obtain multiple segmented image blocks and histograms of the segmented image blocks; correct the brightness of the segmented image blocks according to the histograms, calculate the correlation of the multiple segmented image blocks, and mark the segmented image blocks to obtain marked segmented images when the correlation of the segmented image blocks is greater than a correlation threshold; acquire an area threshold, calculate the area of ​​connected marked segmented images, and mark connected marked segmented images to obtain marked area images when the area is greater than the area threshold; and restore the marked area images to their original size to obtain a marked defect image.

[0145] For ease of description, the above system is described by dividing it into various modules based on their functions. Of course, in implementing this invention, the functions of each module can be implemented in one or more software and / or hardware components.

[0146] The system described above is used to implement the corresponding automatic image defect detection method in any of the foregoing embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be repeated here.

[0147] Those skilled in the art should understand that the discussion of any of the above embodiments is merely exemplary and is not intended to imply that the scope of the invention (including the claims) is limited to these examples; within the framework of the invention, the technical features of the above embodiments or different embodiments can also be combined, the steps can be implemented in any order, and there are many other variations of different aspects of the embodiments of the invention as described above, which are not provided in the details for the sake of brevity.

[0148] Any process or method description in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or more executable instructions for implementing a particular logical function or process, and the scope of the preferred embodiments of the invention includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the functions involved, as will be understood by those skilled in the art to which embodiments of the invention pertain.

[0149] Additionally, to simplify the description and discussion, and to avoid obscuring the embodiments of the invention, the well-known power / ground connections to integrated circuit (IC) chips and other components may or may not be shown in the provided drawings. Furthermore, the apparatus may be shown in block diagram form to avoid obscuring the embodiments of the invention, and this also takes into account the fact that the details of implementation of these block diagram apparatuses are highly dependent on the platform on which the embodiments of the invention will be implemented (i.e., these details should be fully understood by those skilled in the art). While specific details (e.g., circuits) have been set forth to describe exemplary embodiments of the invention, it will be apparent to those skilled in the art that the embodiments of the invention may be implemented without these specific details or with variations thereof. Therefore, these descriptions should be considered illustrative rather than restrictive.

[0150] Although the invention has been described in conjunction with specific embodiments thereof, many substitutions, modifications, and variations of these embodiments will be apparent to those skilled in the art from the foregoing description. For example, other memory architectures (e.g., dynamic RAM (DRAM)) may be used with the embodiments discussed.

[0151] The embodiments of this invention are intended to cover all such substitutions, modifications, and variations falling within the broad scope of the appended claims. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the embodiments of this invention should be included within the protection scope of this invention.

Claims

1. An image-based automatic defect detection method, characterized in that, An image-based automatic defect detection system is applied to a device including a switch, a light source, a camera, and an image processing system; wherein the light source and the camera are located above the object to be tested; the switch, the light source, the camera, and the image processing system are communicatively connected; The method includes: The switch controls the switching on and off and the brightness of the light source; The light source provides illumination for the object under test; The camera captures images of the object to be tested, obtains an image of the object to be tested, and sends the image of the object to be tested to the image processing system. The image processing system acquires a test image, segments the test image to obtain multiple segmented image blocks and histograms of the segmented image blocks; corrects the brightness of the segmented image blocks based on the histograms, calculates the correlation of the multiple segmented image blocks, and marks the segmented image blocks when the correlation of the segmented image blocks is greater than a correlation threshold, obtaining marked segmented images; obtains an area threshold, calculates the area of ​​connected marked segmented images, and marks connected marked segmented images when the area is greater than the area threshold, obtaining marked area images; and restores the marked area images to their original size to obtain a marked defect image. The area threshold for acquisition includes: A defect image is acquired, and a Gaussian filter is used to smooth the defect image to obtain a standard defect image. The standard defect image is then segmented based on a preset size to obtain a defect image block group; wherein, the defect image block group includes multiple defect image segmentation blocks. Calculate the correlation between the defective image patch group and the defect-free image patch group: Where s(x,y) represents the correlation between defective and defect-free image segments, x′ represents the difference in the horizontal coordinate between defective and defect-free image segments, y′ represents the difference in the vertical coordinate between defective and defect-free image segments, T() represents the group of defect-free image blocks, I() represents the group of defective image blocks, and c' T r represents the x-coordinate of a defect-free image segmentation block within a group of defect-free image blocks. T ' represents the ordinate of a defect-free image segment within a group of defect-free image blocks, c' I r represents the x-coordinate of a defective image segmentation block within a defective image block group. I 'Represents the ordinate of a segment of a defective image within a group of defective image blocks; The inter-class variance of similarity is calculated using the following formula, and the similarity threshold is set as the similarity value at which the inter-class variance of similarity is maximized: in, Let represent the inter-class variance of similarity, P1 represent the probability that the similarity threshold is less than or equal to i, P2 represent the probability that the similarity threshold is greater than i, m1 represent the average similarity with a similarity threshold less than or equal to i, and m2 represent the average similarity with a similarity threshold less than or equal to i. G Indicates average similarity; The defective image is segmented according to the similarity threshold to obtain multiple threshold-segmented images; Calculate the area of ​​the threshold segmented image, and set the area of ​​the threshold segmented image with the largest area as the area threshold.

2. The image-based automatic defect detection method according to claim 1, characterized in that, The process of acquiring the image to be tested, segmenting the image to be tested to obtain multiple segmented image blocks, and the histogram of the segmented image blocks includes: The image to be tested is segmented based on a preset size to obtain a group of image blocks to be tested; wherein, the group of image blocks to be tested includes multiple segmented image blocks; Calculate the gray-level histogram for each segmented image block to obtain the histogram; h I =num(s a,b =I) Among them, h I This represents the value in the i-th column of the histogram, where num() represents the count function, and s a,b This represents the pixel value at row a and column b in the segmented image block, where I represents the column number of the histogram.

3. The image-based automatic defect detection method according to claim 1, characterized in that, The step of correcting the brightness of segmented image blocks based on the histogram and calculating the correlation of multiple segmented image blocks includes: Obtain a standard histogram, and calculate the grayscale transformation function of the segmented image block based on the standard histogram and the histogram; Based on the grayscale value transformation function, pixel-by-pixel correction is performed using interpolation to obtain a brightness-corrected segmented image; The brightness-corrected segmented image is smoothed using a Gaussian filter to obtain the corrected image; The correlation of the corrected image is calculated based on the normalized squared difference.

4. The image-based automatic defect detection method according to claim 3, characterized in that, The acquisition of the standard histogram includes: Obtain a group of defect-free images, and calculate the mean image based on the group of defect-free images: Wherein, m r,c Let n represent the mean image, n represent the number of defect-free images in the defect-free image group, and i represent the i-th defect-free image. Represents the pixel value in row r and column c of the i-th defect-free image; Based on the defect-free image set and the mean image, calculate the standard deviation image and the standard deviation of the standard deviation image: Wherein, the dev r,c Let represent the standard deviation image, n represent the number of defect-free images in the defect-free image group, and i represent the i-th defect-free image. This represents the pixel value in row r and column c of the i-th defect-free image. σ represents the pixel values ​​in r rows and c columns of the mean image, σ represents the standard deviation of the standard deviation image, M represents the preset segmentation size of M rows, and N represents the preset segmentation size of N columns. The pixel mean of the standard deviation image; The mean image is segmented based on a preset size to obtain a group of defect-free image blocks; wherein, the group of defect-free image blocks includes multiple defect-free image segmentation blocks; Calculate the grayscale histogram of each defect-free image segment to obtain the standard histogram: h J =num(t r,c =J) Among them, h J This represents the value in column J of the standard histogram, where num() represents the count function, and t r,c This represents the pixel value at the r-th row and c-th column in the segmented image block, where J represents the standard histogram column number.

5. The image-based automatic defect detection method according to claim 3, characterized in that, The step of calculating the grayscale transformation function of the segmented image patch based on the standard histogram and the histogram includes: The grayscale transformation function of the segmented image is calculated using the following formula: z q =G -1 (s k ) Among them, s k The transform function T(r) represents the grayscale value after transformation, L represents the grayscale level, M represents the preset segmentation size of M rows, N represents the preset segmentation size of N columns, k represents the k-th grayscale level, and n represents the grayscale value after transformation. j G(z) represents the number of pixels with a grayscale value of j, where j represents a certain grayscale value j. q ) represents the standard image transformation function, q represents the q-th gray level, i represents a certain gray level i, and p z z represents the probability of a certain gray value in the standard histogram. i z represents the i-th gray level in the standard histogram. q G represents the corrected pixel value. -1 (s k ) is represented as G(z) q The inverse function of ) satisfies G(z) q ) = s k .

6. The image-based automatic defect detection method according to claim 1, characterized in that, Restoring the marked area image to its original size includes: The marked area image is restored to its original size using the following formula: Where, x E The x-coordinate of a pixel after transformation is represented by y. F r represents the ordinate of a pixel after transformation. ** Represents the elements of a two-dimensional rotation matrix, r ** Includes: r 11 r 12 r 21 r 22 , t x t represents the horizontal axis offset. y The x-axis represents the offset of the vertical axis. e The x-coordinate of a pixel before the transformation is represented by y. f This represents the ordinate of a pixel before the transformation.

7. An image-based automatic defect detection system, characterized in that, An image-based automatic defect detection method as described in claims 1-6 includes: a switch, a light source, a camera, and an image processing system; wherein the light source and the camera are located above the object to be tested; and the switch, light source, camera, and image processing system are communicatively connected. The switch is used to control the switching on and off and the brightness of the light source; The light source is used to provide illumination for the object under test; The camera is used to photograph the object to be tested, obtain an image of the object to be tested, and send the image of the object to be tested to the image processing system. The image processing system is configured to acquire a test image, segment the test image to obtain multiple segmented image blocks and histograms of the segmented image blocks; correct the brightness of the segmented image blocks according to the histograms, calculate the correlation of the multiple segmented image blocks, and mark the segmented image blocks to obtain marked segmented images when the correlation of the segmented image blocks is greater than a correlation threshold; acquire an area threshold, calculate the area of ​​connected marked segmented images, and mark connected marked segmented images to obtain marked area images when the area is greater than the area threshold; and restore the marked area images to their original size to obtain a marked defect image. The area threshold for acquisition includes: A defect image is acquired, and a Gaussian filter is used to smooth the defect image to obtain a standard defect image. The standard defect image is then segmented based on a preset size to obtain a defect image block group; wherein, the defect image block group includes multiple defect image segmentation blocks. Calculate the correlation between the defective image patch group and the defect-free image patch group: Where s(x,y) represents the correlation between defective and defect-free image segments, x′ represents the difference in the horizontal coordinate between defective and defect-free image segments, y′ represents the difference in the vertical coordinate between defective and defect-free image segments, T() represents the group of defect-free image blocks, I() represents the group of defective image blocks, and c' T r represents the x-coordinate of a defect-free image segmentation block within a group of defect-free image blocks. T ' represents the ordinate of a defect-free image segment within a group of defect-free image blocks, c' I r represents the x-coordinate of a defective image segmentation block within a defective image block group. I 'Represents the ordinate of a segment of a defective image within a group of defective image blocks; The inter-class variance of similarity is calculated using the following formula, and the similarity threshold is set as the similarity value at which the inter-class variance of similarity is maximized: in, Let represent the inter-class variance of similarity, P1 represent the probability that the similarity threshold is less than or equal to i, P2 represent the probability that the similarity threshold is greater than i, m1 represent the average similarity with a similarity threshold less than or equal to i, and m2 represent the average similarity with a similarity threshold less than or equal to i. G Indicates average similarity; The defective image is segmented according to the similarity threshold to obtain multiple threshold-segmented images; Calculate the area of ​​the threshold segmented image, and set the area of ​​the threshold segmented image with the largest area as the area threshold.

Citation Information

Patent Citations

  • System for visually detecting workpiece appearance defects based on image processing

    CN106053479A

  • Sand mold defect detection method and system based on machine vision

    CN114387233A