Method for detecting defects of a product
By using grayscale image processing technology, selecting the target grayscale range and performing image calibration, the problem of imaging differences between products of different materials under the same device is solved, improving detection stability and equipment compatibility, and reducing costs.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SUZHOU JIERUISI INTELLIGENT TECH CO LTD
- Filing Date
- 2022-07-29
- Publication Date
- 2026-06-09
AI Technical Summary
Products made of different materials produce significantly different images when tested using the same equipment, resulting in poor testing results and increased equipment costs.
By processing grayscale images, a target grayscale range is selected and the image is calibrated to generate a new grayscale image to enhance contrast, improve detection stability and equipment compatibility.
It enables unified image calibration of products of different materials under the same equipment, reducing inspection costs.
Smart Images

Figure CN115345839B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of digital image processing, and in particular to a method for detecting defects in products. Background Technology
[0002] In industrial production, it's common to encounter products that use the same manufacturing process but different materials. These products are often the same size and shape, with surface and internal materials that are either identical or completely different. When such products are introduced into automated inspection equipment for defect detection, the different materials refract and reflect light differently under the same lighting conditions, resulting in significantly different images in the imaging system. Even identical defect morphologies will appear very different, leading to a substantial reduction in the detection effectiveness and performance of the same equipment for products of the same model but different materials. In such cases, it is often necessary to use multiple devices for separate inspections based on the product's material, increasing costs. Summary of the Invention
[0003] In view of the technical problems existing in the background technology, the product defect detection method proposed in this invention can effectively solve the problem of image differences of the same product made of different materials on the same detection equipment.
[0004] To achieve the above objectives, the product defect detection method disclosed in this invention includes: obtaining a grayscale image of the product; obtaining a grayscale histogram of the grayscale image; selecting at least one continuous grayscale interval from the grayscale histogram as a target grayscale interval; expanding the at least one target grayscale interval into a grayscale interval of [0, 255] to form a new grayscale image; and detecting defects in the new grayscale image. The target grayscale interval is determined based on the grayscale distribution of the grayscale histogram and the defect type of the product.
[0005] In one embodiment, the target grayscale range is [Index1, Index2], where 0 <Index1,index2<255。
[0006] In one embodiment, the number of pixels in the grayscale range [0, Index1] accounts for no more than 0.5% of the grayscale image of the product.
[0007] In one embodiment, the number of pixels in the grayscale range [Index2, 255] accounts for no more than 0.5% of the grayscale image of the product.
[0008] In one embodiment, the method further includes a step of determining the grayscale distribution of the grayscale image of the product, and dynamically selecting the target grayscale range based on the characteristics of the grayscale distribution.
[0009] In one embodiment, after the step of obtaining the grayscale histogram of the grayscale image, an upper limit coefficient, a lower limit coefficient, and a dynamic equalization parameter are set. The products of the upper limit coefficient and the lower limit coefficient with the dynamic equalization parameter and the number of pixels of the grayscale image respectively yield the upper limit pixel number and the lower limit pixel number within the grayscale intervals [0, Index1] and [Index2, 255].
[0010] In one embodiment, the upper limit coefficient and the lower limit coefficient are determined according to the grayscale distribution of the grayscale histogram, and the dynamic equalization parameter is determined according to the defect type of the product.
[0011] In one embodiment, the upper limit coefficient and the lower limit coefficient are respectively set to 0.1, and the dynamic equalization parameter is set to 0.05.
[0012] In one embodiment, in the step of forming a new grayscale image, the mapping relationship is: when x < minPar, g(x) = 0; when x > MaxPar, g(x) = 255; when x ∈ [minPar, maxPar], g(x) = 255 * ((x - MinPar) / (MaxPar - MinPar)) ^ AdjustPara; where x is the pixel grayscale value on the grayscale image of the product, g(x) is the pixel grayscale value of the new image, MinPar is the lower limit value of the target grayscale interval, MaxPar is the upper limit value of the target grayscale interval, AdjustPara is the correction coefficient, and AdjustPara ∈ [1, 10].
[0013] In one embodiment, the correction coefficient is calculated using the following formula:
[0014] AdjustPara = log(0.5) / log((MeanGray - MinPar) / (MaxPar - MinPar))
[0015] If AdjustPara is less than 1, then AdjustPara = 1; if AdjustPara is greater than 10, then AdjustPara = 10; in other cases, AdjustPara is rounded to the nearest integer; where MeanGray is the grayscale weighted average value of the grayscale image of the product.
[0016] The technical solution provided by the embodiments of the present application, through image processing technology, uniformly calibrates and enhances the different images obtained by products of the same model and different materials under the same lighting conditions to a stable level, improves the compatibility of the automated detection device and the stability of detection, and reduces the cost of the user for introducing the detection device. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 This is a flowchart illustrating the product defect detection method provided in the embodiments of this application;
[0018] Figure 2 This is a block diagram of the apparatus used in the product defect detection method provided in one embodiment of this application;
[0019] Figure 3 This is a comparison image of a product before and after defect detection according to an embodiment of this application. Detailed Implementation
[0020] The present invention will be further described below with reference to the accompanying drawings and specific embodiments, so that those skilled in the art can better understand and implement the present invention. However, the embodiments described are not intended to limit the present invention.
[0021] Figure 1 This is a schematic flowchart of the product defect detection method provided in the embodiments of this application. Figure 1 The process includes the following steps:
[0022] Step S1: Acquire the image and perform grayscale statistics on the image;
[0023] Step S2: Set an upper limit coefficient LimitHigh, a lower limit coefficient LimitLow, and a dynamic balancing parameter DMPar;
[0024] Step S3: Based on the aforementioned upper limit parameter, lower limit parameter and dynamic equalization parameter, obtain an upper limit gray level MaxPar and a lower limit gray level MinPar, and then determine an upper limit gray level and a lower limit gray level, thereby obtaining a target gray level range for the current detection process;
[0025] Step S4: Obtain a correction coefficient AdjustPara based on the aforementioned upper limit gray level, lower limit gray level, and the gray level distribution of the current image;
[0026] Step S5: Establish a mapping relationship between the target grayscale range and the grayscale range of the original image based on the correction coefficient;
[0027] Step S6: Based on the mapping relationship in step S5, generate a new image based on the target grayscale range, and perform defect detection on the new image.
[0028] Among them, the above-mentioned image refers to the image to be processed. The gray level Index of each pixel of the image to be processed is collected, and the value range of the gray level Index is [0, 255]. Gray level statistics means calculating the number of pixels Gray at each gray level, forming a statistical array Histo[Gray(Index)] of each gray level, and obtaining the gray level histogram of the image. A continuous gray level interval is selected from the gray level histogram as the target gray level interval, and the target gray level interval is [Index1, Index2], where 0 < Index1, index2 < 255, so as to delete some low-order gray level values and high-order gray level values and reduce the noise interference of gray level values with large difference values.
[0029] For example: In this embodiment, the number of pixels with gray levels of 0, 1, 2... 255 in the image to be processed are a0, a1, a2... a 255 . Then the total number of pixels GrayNums of the image = a0 + a1 + a2 +... + a 255 , and the total gray level value of the image is 0 * a0 + 1 * a1 + 2 * a2 +... + 255 * a 255 .
[0030] In the following description, it is assumed that the number of pixels GrayNums of the current image is 32640, and the total gray level value of the image is 3264000.
[0031] In step S2, the selection of the upper limit coefficient LimitHigh and the lower limit coefficient LimitLow
[0032] is related to the gray level distribution of the gray level image obtained for the specific material product, and this gray level distribution can be represented by the weighted average gray level value of the image. If the overall gray level image is darker, it usually means that a large amount of details are hidden in the high-order gray level interval. At this time, the lower limit coefficient and the upper limit coefficient can be appropriately increased to retain relatively more high-order gray level pixels. If the gray level image is brighter, the opposite adjustment can be made to retain relatively low-order gray level pixels. The dynamic equalization parameter DMPar can be adjusted according to the type of defect. In the gray level image, different defects such as scratches, cracks, pits, and stains have different gray level characteristics relative to the product material. The corresponding relationship between these parameters and different types of defects in the gray level image can be obtained through multiple experiments in the deep neural network system.
[0033] The obtained parameters can be stored in the defect detection system and called when detecting each obtained gray level image, so as to obtain a more targeted target gray level interval for each detection. In this case, in order to obtain the defect type in the current image and further determine the dynamic equalization parameters to be called, a preliminary determination can be made in step S3 for the defect type of the image collected in step S1.
[0034] In this embodiment, the upper and lower limit coefficients are set to 0.1, and the dynamic equilibrium parameter is set to 0.05. These values have been repeatedly verified and confirmed to be the most widely applicable values.
[0035] The upper limit coefficient and lower limit coefficient are multiplied by the dynamic equalization parameter and the number of pixels in the grayscale image, respectively, to obtain the upper limit number of pixels and the lower limit number of pixels in the grayscale interval [0, Index1] and the grayscale interval [Index2, 255].
[0036] In step S3, the upper and lower grayscale limits MaxPar and MinPar are calculated using the following formulas:
[0037] sum=sum+Gray(Index) (1)
[0038] The initial value of sum is 0. Gray(Index) is the distribution statistics of each gray level corresponding to different gray levels. The gray level statistics array is accumulated level by level.
[0039] The grayscale index value changes from [0, 255]. When sum ≧ GrayNums * LimitLow * DMPar, MinPar = Index1. This can be understood as the number of pixels with grayscale values increasing from small to large, and when it reaches a certain proportion of the total number of pixels in the image (i.e., the lower limit number of pixels), the grayscale value is the lower limit grayscale value.
[0040] The grayscale index value changes from [255, 0]. When sum ≧ GrayNums * LimitHigh * DMPar, MaxPar = Index2. This can be understood as the number of pixels with grayscale values increasing from large to small, and when it reaches a certain proportion of the total number of pixels in the image (i.e., the upper limit number of pixels), the grayscale value is the upper limit grayscale value.
[0041] Calculate the lower limit gray level MinPar:
[0042] The grayscale index value gradually increases from 0, and the distribution statistics of each grayscale value are substituted into formula (1) and accumulated step by step. Assuming that when the grayscale value ranges from 0 to 10, sum≧GrayNums*LimitLow*DMPar, then MinPar=10.
[0043] Calculate the upper limit of grayscale, MaxPar:
[0044] The grayscale index value gradually decreases from 255. The distribution statistics of each grayscale value are substituted into formula (1) and accumulated step by step. Assuming that when the grayscale value reaches 200, sum≧GrayNums*LimitHigh*DMPar, then MaxPar=200.
[0045] In step S4, the correction coefficient AdjustPara is calculated using the following formula:
[0046] AdjustPara = log(0.5) / log((MeanGray - MinPar) / (MaxPar - MinPar)) (2)
[0047] When the calculated AdjustPara ≤ 1, the value of AdjustPara is taken as 1;
[0048] When the calculated 1 < AdjustPara < 10, AdjustPara is rounded to the nearest integer;
[0049] When the calculated AdjustPara ≥ 10, the value of AdjustPara is taken as 10.
[0050] First, find the weighted average MeanGray of the entire image. MeanGray = total image gray value / total number of image pixels = (0 * a0 + 1 * a1 + 2 * a2 + …… + 255 * a 255 ) / GrayNums; The weighted average MeanGray of the image is between the upper limit gray value and the lower limit gray value, and can reflect whether the overall image gray value tends to the large gray value or the small gray value.
[0051] For example: According to the values of the total number of pixels and the number of pixels in step S1, in this embodiment, the value of MeanGray is 100.
[0052] Substitute the weighted average MeanGray 100, the upper and lower limit grays MaxPar 200 and MinPar 10 calculated in step 3 into formula (2);
[0053] log(0.5) / log((100 - 10) / (200 - 10)) < 1, then the value of AdjustPara is taken as 1.
[0054] In step S5, the mapping relationship is established as follows:
[0055] When x < MinPar, g(x) = 0;
[0056] When MinPar ≤ x ≤ MaxPar,
[0057] g(x) = 255 * ((x - MinPar) / (MaxPar - MinPar)) AdjustPara (3)
[0058] When x > MaxPar, g(x) = 255;
[0059] x represents the grayscale value of each pixel in the product image, and g(x) represents the grayscale value of each pixel in the new image.
[0060] In this embodiment: MinPar is 10, and MaxPar is 200;
[0061] In step S6, a new image is generated:
[0062] The pixel g(x) in the new image corresponding to a pixel with a value less than 10 in the original image is 0;
[0063] The pixel g(x) of the new image corresponding to the pixel with a pixel value greater than 200 in the original image is 255;
[0064] Substituting the pixel g(x) of the new image corresponding to the pixels greater than 10 and less than 200 in the original image into formula (3), we get g(x) = 255 * ((x-10) / (200-10)). 1 :
[0065] The original pixel 20 in the image generates a new pixel with a value of 13;
[0066] The original pixel 30 in the image generates a new pixel with a value of 27;
[0067] The original pixel 39 in the image generates a new pixel with a value of 39.
[0068] The original pixel 50 in the image generates a new pixel with a value of 54;
[0069] The original pixel 100 in the image generates a new pixel with a value of 121;
[0070] The original pixel 150 in the image generates a new pixel with a value of 188;
[0071] The original pixel 180 in the image generates a new pixel with a value of 228;
[0072] The original pixel 190 in the image generates a new pixel with a value of 241;
[0073] As can be seen, the defect detection method of this embodiment makes the original large gray value larger and the original small gray value smaller, thereby increasing the difference between the two, enhancing the contrast, and generating a new image.
[0074] Figure 2 This is a block diagram of an apparatus used in a product defect detection method according to an embodiment of this application. Figure 2 As shown, the device includes an image acquisition module, a grayscale value processing module, and an image generation module.
[0075] The image acquisition module is used to acquire images, which can be achieved by an image sensor or CCD camera, and then convert the images into data information for storage.
[0076] The grayscale processing module processes the grayscale of each pixel in the image and includes a setting module and a calculation module. The setting module can utilize existing technologies such as a touchscreen or keyboard to configure relevant parameters. The calculation module is implemented in software and installed on the hardware controller. Application developers pre-set the calculation conditions and generate new data information after processing the existing data.
[0077] The image generation module is used to obtain a processed new image based on the mapping relationship set by the calculation module, and to generate a new image based on the new data information from the calculation module.
[0078] The above-described embodiments are merely preferred embodiments provided to fully illustrate the present invention, and the scope of protection of the present invention is not limited thereto. Equivalent substitutions or modifications made by those skilled in the art based on the present invention are all within the scope of protection of the present invention. The scope of protection of the present invention is defined by the claims.
Claims
1. A method for detecting defects in a product, characterized by comprising: Obtain a grayscale image of the product; Obtain the grayscale histogram of the grayscale image; Select at least one continuous gray-level interval from the gray-level histogram as the target gray-level interval; At least one target grayscale range is expanded into the grayscale range of [0, 255] to form a new grayscale image; defects in the new grayscale image are detected; wherein the target grayscale range is determined based on the grayscale distribution of the grayscale histogram and the defect type of the product; and the number of pixels in the selected target grayscale range is greater than the number of pixels in the unselected grayscale range of the grayscale image of the product. The target grayscale range is [Index1, Index2], where 0 <Index1,index2<255; The selection of the target grayscale range follows these principles: sum = sum + Gray(Index), where the initial value of sum is 0, and Gray(Index) is the distribution statistics of each gray level corresponding to different gray levels. The gray level statistics array is accumulated level by level. The grayscale index value changes from [0, 255]. When sum ≧ GrayNums * LimitLow * DMPar, the grayscale value is the lower limit grayscale MinPar = Index1. The grayscale index value changes to [255, 0]. When sum ≧ GrayNums * LimitHigh * DMPar, the grayscale value is the upper limit grayscale MaxPar = Index2. GrayNums is the number of pixels, LimitLow is the lower limit coefficient, LimitHigh is the upper limit coefficient, which are determined according to the gray level distribution of the gray level histogram, and DMPar is the dynamic equalization parameter, which is determined according to the defect type of the product.
2. The product defect detection method as described in claim 1, characterized in that, The number of pixels in the grayscale range [0, Index1] accounts for no more than 0.5% of the grayscale image of the product.
3. The product defect detection method as described in claim 1, characterized in that, The number of pixels in the grayscale range [Index2, 255] does not exceed 0.5% of the grayscale image of the product.
4. The product defect detection method as described in claim 1, characterized in that, It also includes the step of determining the grayscale distribution of the grayscale image of the product, and dynamically selecting the target grayscale range based on the characteristics of the grayscale distribution.
5. The product defect detection method as described in claim 1, characterized in that, in After obtaining the grayscale histogram of the grayscale image, an upper limit coefficient, a lower limit coefficient, and a dynamic equalization parameter are set. The upper limit coefficient and the lower limit coefficient are multiplied by the dynamic equalization parameter and the number of pixels in the grayscale image, respectively, to obtain the upper limit number of pixels and the lower limit number of pixels in the grayscale interval [0, Index1] and the grayscale interval [Index2, 255].
6. The product defect detection method as described in claim 1, characterized in that, The upper limit coefficient and lower limit coefficient are each set to 0.1, and the dynamic equilibrium parameter is set to 0.
05.
7. The product defect detection method as described in claim 1, characterized in that, In the step of forming the new grayscale image, the mapping relationship is as follows: when x < minPar, g(x) = 0; when x > MaxPar, g(x) = 255; when x ∈ [minPar, maxPar], g(x) = 255 * ((x - MinPar) / (MaxPar - MinPar)) ^ AdjustPara; where x is the pixel grayscale value on the grayscale image of the product, g(x) is the pixel grayscale value of the new image, MinPar is the lower limit value of the target grayscale interval, MaxPar is the upper limit value of the target grayscale interval, AdjustPara is the correction coefficient, and AdjustPara ∈ [1, 10].
8. The product defect detection method as described in claim 7, characterized in that, The correction coefficient is calculated using the following formula: AdjustPara = log(0.5) / log((MeanGray - MinPar) / (MaxPar - MinPar)) If AdjustPara is less than 1, then AdjustPara = 1; if AdjustPara is greater than 10, then AdjustPara = 10; in other cases, AdjustPara is rounded to the nearest integer; where MeanGray is the grayscale weighted average of the grayscale image of the product.