A defect identification method based on grayscale features
By combining grayscale histogram construction with Gaussian filtering, textile defects are identified, solving the noise interference problem caused by uneven textile fibers and achieving efficient and accurate defect identification.
Patent Information
- Application Number
- CN202310402417.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-14
- Publication Date
- 2026-01-06
- Estimated Expiration
- 2043-04-14
AI Technical Summary
Existing technologies for textile defect identification suffer from severe noise interference, leading to inaccurate identification results. This is especially true when textile fibers are unevenly distributed, the surface is rough, and the thickness is inconsistent, making it difficult to effectively separate defect points from noise.
By constructing a grayscale histogram, the boundary between regions with holes and continuous regions of pixel count is identified, the optimal traversal path is determined, the threshold segmentation point is determined by the abrupt change in grayscale value, and noise filtering is performed by combining Gaussian filtering and pixel difference. Finally, ultra-large defects are screened out by grayscale variance.
It improves the efficiency of threshold segmentation point determination, reduces grayscale noise interference, and improves the accuracy of defect identification, especially the accuracy of textile defect identification.
Smart Images

Figure CN116468689B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and in particular to a defect recognition method based on grayscale features. Background Technology
[0002] In industry, defect detection of raw materials such as wood, steel, and textiles is often divided into two steps: "processing" and "identification". Due to the texture of wood, the luster of steel, and the roughness of textiles, direct "defect identification" on the original image is extremely unsatisfactory. Therefore, a "processing" operation is usually required to filter out the interference caused by the characteristics of these materials themselves, while retaining the defect information for the "identification" operation.
[0003] For computers, whether a point is a defect is mainly determined by the difference in grayscale value between it and the surrounding background. However, in a large real-world image, the background grayscale values are often uneven. Therefore, a suitable bandpass filter is first used to "process" the image, making the background grayscale values more uniform while highlighting the defect. For relatively smooth and uniform materials such as steel and ceramics, setting an appropriate threshold allows for direct threshold segmentation to find the defect. However, textiles, due to their uneven fiber distribution, rough surface, and inconsistent thickness, still retain a lot of noise in the image after bandpass filtering or other "processing" methods. The grayscale values of this noise are not significantly different from some types of defect points, thus greatly interfering with the defect recognition process and leading to inaccurate defect identification results. Summary of the Invention
[0004] To address the aforementioned technical problems, the technical solution adopted by this invention is as follows:
[0005] A defect identification method based on grayscale features, comprising the following steps:
[0006] Step S100: Obtain the target textile image, and perform grayscale and filtering processing on the target textile image to obtain a grayscale image P;
[0007] Step S200: Traverse all pixels in P, obtain the number of pixels corresponding to each gray value in the gray value range of 0-255, and construct a gray histogram Z based on each gray value and the number of pixels corresponding to each gray value. The X-axis of Z is the gray value of the pixel, and the Y-axis is the number of pixels corresponding to the gray value.
[0008] Step S300: Obtain the array set S = (S0, S1, ..., S...) based on Z. i ,…S 255 ); where S i S is an array of grayscale values i. i =[i,ni ], n i This represents the number of pixels corresponding to grayscale value i.
[0009] Step S400: Traverse S to obtain regions with empty pixel counts and regions with continuous pixel counts; if J = K = 1, then record the gray value at the boundary between the regions with empty pixel counts and regions with continuous pixel counts as g'1; if J = K = 2, then record the gray value at the boundary between the first region with empty pixel counts and the first region with continuous pixel counts as g1, and record the gray value at the boundary between the second region with empty pixel counts and the second region with continuous pixel counts as g2, where J is the number of regions with empty pixel counts and K is the number of regions with continuous pixel counts. The average gray value corresponding to the first region with empty pixel counts is less than the average gray value corresponding to the second region with empty pixel counts, and the average gray value corresponding to the first region with continuous pixel counts is less than the average gray value corresponding to the second region with continuous pixel counts.
[0010] Step S500: Obtain the gray value h corresponding to the maximum number of pixels in the grayscale histogram Z;
[0011] Step S600: If g < h and g < |gh|, then from S0 to S h Perform the traversal; if g > h and |gh| > |255-g|, then start from S 255 To S h Perform a traversal; otherwise, start from S. h Position towards S0 and S 255 Perform a traversal; based on n during the traversal process i The magnitude change is used to obtain the threshold segmentation point Q of the gray value; if J = K = 1, then the value of g is g'1; if J = K = 2, then the value of g is g1 or g2.
[0012] Step S700: Use the gray value corresponding to Q as the upper or lower limit of threshold segmentation to perform threshold segmentation on P to obtain the suspected defect area; and perform noise filtering on the suspected defect area to obtain the first target defect area.
[0013] Optionally, iterate through S to obtain the number of pixels in the hole region, including:
[0014] Step S401: Traverse S in order of grayscale values 0-255 and record the grayscale value d1 of the first pixel with a count of 0.
[0015] Step S402: Continue to traverse the number of pixels corresponding to the gray values after d1, ignore gray values with a number of pixels of 0, and record the gray value d2 that is the first gray value after d1 with a number of pixels of non-zero and the number of pixels corresponding to the following 10 gray values is not zero.
[0016] Step S403: The region between d1 and d2 is designated as the pixel count hole region.
[0017] Optionally, iterate through S to obtain a continuous region containing a certain number of pixels, including:
[0018] Step S410: Traverse S in order of grayscale values 0-255 and record the first grayscale value d3 where the number of pixels is not zero.
[0019] Step S420: Continue to traverse the number of pixels corresponding to the gray values after d3, ignore gray values with a non-zero number of pixels, and record the first gray value after d3 with a zero number of pixels and the gray value d4 with a zero number of pixels corresponding to the gray value among the following 10 gray values.
[0020] Step S430: The region between d3 and d4 is designated as a continuous region for the number of pixels.
[0021] Optionally, step S600 includes:
[0022] Step S601, from S0 to S h Perform the traversal and record n during the traversal. i and n i-1 The order of magnitude of n i The order of magnitude and n i-1 If the ratio of their magnitudes is greater than a preset value, record n. i The grayscale value is A;
[0023] Step S602: Continue to traverse the number of pixels corresponding to the ten gray values after A. If the ratio of the magnitude of the number of pixels of two adjacent gray values is greater than a preset value, then record the second gray value of the two adjacent gray values as Q.
[0024] Optionally, step S600 further includes:
[0025] Step S611, from S 255 To S h Perform the traversal and record n during the traversal. i and n i+1 The order of magnitude of n i The order of magnitude and n i+1 If the ratio of their magnitudes is greater than a preset value, record n. i The grayscale value is A;
[0026] Step S612: Continue to traverse the number of pixels corresponding to the ten gray values after A. If the ratio of the magnitude of the number of pixels of two adjacent gray values is greater than a preset value, then record the second gray value of the two adjacent gray values as Q.
[0027] Optionally, step S600 further includes:
[0028] Step S621, from S h Iterate through S0 and record n during the traversal. i and n i-1 The order of magnitude of n i The order of magnitude and n i-1 The ratio of their magnitudes is greater than the preset value and n i If the ratio of the order of magnitude of the number of pixels with two adjacent gray values in the last ten gray values is greater than a preset value, record n. i The grayscale value is Q;
[0029] Step S623, from S h To S 255 Perform the traversal and record n during the traversal. i and n i+1 The order of magnitude of n i The order of magnitude and n i+1 The ratio of their magnitudes is greater than the preset value and n i If the ratio of the order of magnitude of the number of pixels with two adjacent gray values in the last ten gray values is greater than a preset value, record n. i The grayscale value is Q.
[0030] Optionally, step S700 includes:
[0031] Step S710: Perform threshold segmentation on P according to the upper or lower limit of the threshold segmentation to obtain several defective regions;
[0032] Step S720: Traverse all defective areas and delete defective areas with an area smaller than a preset area to obtain the first target defective area.
[0033] Optionally, the method further includes the following steps:
[0034] Step S800: Perform grayscale processing on the target textile image to obtain a grayscale image P1, and calculate the grayscale variance DX1 of P1.
[0035] Step S900: Filter P1 to obtain a grayscale image P2, and calculate the grayscale variance DX2 of P2.
[0036] Step S1000: If DX1-DX2>DX0, subtract the gray value of the corresponding pixel in P2 from the gray value of each pixel in P1 to obtain the difference between each pixel in P1 and P2; where DX0 is a preset gray variance threshold.
[0037] Step S1100: Mark each connected region in P1 formed by pixels whose difference is greater than a preset difference threshold as a suspected second target defect region;
[0038] Step S1200: If the area of the suspected second target region is greater than j*U P1 The suspected second target area is marked as the second target area; where j is a preset scaling factor, 0 < j < 1, U P1 Let P1 be the area.
[0039] Optionally, the value of j ranges from 5% to 10%.
[0040] Optionally, the filtering process in step S100 includes the following steps:
[0041] Step S110: Subtract E1 from E2 to generate E3; where E1 and E2 are both preset Gaussian filter kernels, and the scale difference between E1 and E2 is 1, and E3 is a filter kernel generated by E1 and E2.
[0042] Step S120: The grayscale image is filtered using E3 to obtain P.
[0043] The present invention has at least the following beneficial effects:
[0044] The defect identification method based on grayscale features of this invention generates a grayscale histogram based on the grayscale values of a grayscale image P. It determines the optimal traversal path based on the boundary between hole regions and continuous regions of pixels, as well as the grayscale value with the highest number of pixels. This method can find threshold segmentation points with the shortest traversal path, thus greatly improving the efficiency of threshold segmentation point determination. Simultaneously, it utilizes the abrupt change in grayscale values of defects, characterizing this characteristic as a magnitude change in the corresponding pixel value. Based on the magnitude change value, it determines the grayscale value corresponding to a specific threshold segmentation point, avoiding interference from individual grayscale noise and improving the accuracy of defect identification. Attached Figure Description
[0045] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0046] Figure 1 A flowchart of a defect identification method based on grayscale features provided in an embodiment of the present invention;
[0047] Figure 2 The grayscale histogram provided in the embodiments of the present invention. Detailed Implementation
[0048] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0049] In one embodiment, a method such as Figure 1 The defect identification method based on grayscale features shown may include the following steps:
[0050] Step S100: Acquire the target textile image, and perform grayscale and filtering processing on the target textile image to obtain a grayscale image P.
[0051] In this embodiment, the object is textile fabric. Grayscale conversion of textile fabric images is an existing technique and will not be described in detail here. Gaussian filtering is used to filter the grayscale-processed image. The specific filtering process includes the following steps:
[0052] Step S110: Subtract E1 from E2 to generate E3; where E1 and E2 are both preset Gaussian filter kernels, and the scale difference between E1 and E2 is 1, and E3 is a Gaussian filter kernel generated by E1 and E2.
[0053] In this embodiment, two Gaussian filter kernels E1 and E2 with a scale difference of 1 are subtracted to generate filter kernel E3. Filter kernel E3 has both the smoothing characteristics of Gaussian filtering and the frequency selection characteristics of bandpass filtering.
[0054] Step S120: The grayscale image is filtered using E3 to obtain P.
[0055] The filter kernel E3 generated by the above method is used to filter grayscale images, which can solve the interference of shadows and uneven lighting in specific scenes; for example, shadow interference caused by uneven textile fibers and uneven lighting interference caused by non-parallel light from the shooting light source.
[0056] Step S200: Traverse all pixels in P, obtain the number of pixels corresponding to each gray value in the gray value range of 0-255, and construct a gray histogram Z based on each gray value and the number of pixels corresponding to each gray value. The X-axis of Z is the gray value of the pixel, and the Y-axis is the number of pixels corresponding to the gray value.
[0057] In this embodiment, by traversing all pixels in image P, the grayscale value of each pixel can be obtained. Since the grayscale value of all pixels is within the range of 0-255, 0-255 is used as the X-axis coordinate parameter of the grayscale histogram, and the number of pixels corresponding to each grayscale value is used as the Y-axis coordinate parameter, thus obtaining the following... Figure 2 The grayscale histogram Z is shown.
[0058] As an example, the sum of the areas of all pixels corresponding to a certain gray value can also be used as the Y-axis coordinate parameter to construct a gray-level histogram Z.
[0059] Step S300: Obtain the array set S = (S0, S1, ..., S...) based on Z. i ,…S 255 ); where S i S is an array of grayscale values i. i =[i,n i ], n i This represents the number of pixels corresponding to grayscale value i.
[0060] Based on the grayscale histogram Z constructed in step S200 above, by sequentially traversing the X-axis coordinate parameters of Z and recording the number of pixels corresponding to the X-axis coordinate parameters, an array set S = (S0, S1, ..., S...) can be obtained. i ,…S 255 S contains 256 groups. i =[i,n i ], where i represents the grayscale value, and the value of i ranges from 0 to 255, n i S represents the number of pixels corresponding to grayscale value i; for example, if the number of pixels corresponding to a grayscale value of 100 is 2000, then S 100 =[100,2000].
[0061] Step S400: Traverse S to obtain regions with empty pixel counts and regions with continuous pixel counts; if J = K = 1, then record the gray value at the boundary between the regions with empty pixel counts and the regions with continuous pixel counts as g'1; if J = K = 2, then record the gray value at the boundary between the first region with empty pixel counts and the first region with continuous pixel counts as g1, and record the gray value at the boundary between the second region with empty pixel counts and the second region with continuous pixel counts as g2. J is the number of regions with empty pixel counts obtained, and K is the number of regions with continuous pixel counts obtained. The average gray value corresponding to the first region with empty pixel counts is less than the average gray value corresponding to the second region with empty pixel counts, and the average gray value corresponding to the first region with continuous pixel counts is less than the average gray value corresponding to the second region with continuous pixel counts.
[0062] It is understandable that defects refer to changes that are not caused by the material itself. Because they are not naturally formed, their grayscale values will have a strong sense of abruptness with the background. Therefore, the grayscale histogram characteristics of defects are: small area and obvious disconnection of grayscale values.
[0063] For the grayscale histogram Z above, firstly, it is necessary to identify regions with empty pixel counts and regions with continuous pixel counts. Identifying regions with empty pixel counts involves the following steps:
[0064] Step S401: Traverse S in order of grayscale values 0-255 and record the grayscale value d1 of the first pixel with a count of 0.
[0065] Iterate through the array set S, using grayscale values as variables, ranging from 0 to 255. In each loop, check the number of pixels. If the number of pixels is 0, record the grayscale value d1 for that loop.
[0066] Step S402: Continue to traverse the number of pixels corresponding to the gray values after d1, ignore gray values with a pixel count of 0, and record the first gray value d2 after d1 with a non-zero pixel count and the pixel counts corresponding to the next 10 gray values are all non-zero.
[0067] Continue iterating. If the number of pixels is still 0, ignore that grayscale value. If the number of pixels has a value, record the grayscale value of this loop as d2. Continue iterating. If, after d2, the number of pixels is not 0 for ten consecutive loops, then it is considered to have left the hole region (because there may be sporadic isolated pixels, these are special cases, so at least ten grayscale values are needed). Then the area d1-d2 is the hole region in terms of the number of pixels.
[0068] Step S403: The region between d1 and d2 is designated as the pixel count hole region.
[0069] Find the region with a continuous number of pixels, including the following steps:
[0070] Step S410: Traverse S in order of grayscale values 0-255 and record the first grayscale value d3 where the number of pixels is not zero.
[0071] Step S420: Continue to traverse the number of pixels corresponding to the gray values after d3, ignore gray values with a non-zero number of pixels, and record the first gray value after d3 with a zero number of pixels and the gray value d4 with a zero number of pixels corresponding to the gray value among the following 10 gray values.
[0072] Step S430: The region between d3 and d4 is designated as a continuous region for the number of pixels.
[0073] For an image of a target textile, its grayscale histogram often shows a peak, located near the center, with void areas on both the left and right sides of the peak. However, if the entire image is too white, the grayscale histogram will shift to the right, eventually covering the void areas to the right of the peak. Conversely, if the entire image is too black, the grayscale histogram will shift to the left, eventually covering the void areas to the left of the peak. Specifically, the number and location distribution of void areas and continuous pixel regions fall into three categories:
[0074] The first case: the number of pixels in the hole region and the number of pixels in the continuous region are both 1, and both are located to the left of the peak.
[0075] The second case is that the number of pixels in both the hole region and the number of pixels in the continuous region is 1, and both are located on the right side of the peak.
[0076] In both the first and second cases, the grayscale value at the boundary between the region with empty pixels and the region with continuous pixels is denoted as g'1.
[0077] The third case: The number of empty regions and the number of continuous regions are both 2. There is one empty region and one continuous region on the left side of the peak, and one empty region and one continuous region on the right side of the peak. In this case, the gray value at the junction of the empty region and the continuous region on the left is recorded as g1, and the gray value at the junction of the empty region and the continuous region on the right is recorded as g2.
[0078] Step S500: Obtain the gray value h corresponding to the maximum number of pixels in the grayscale histogram Z.
[0079] In this embodiment, the array with the largest number of pixels can be found by traversing the number of pixels in each array in S, and the grayscale value in the array is h.
[0080] Step S600: If g < h and g < |gh|, then from S0 to S h Perform the traversal; if g > h and |gh| > |255-g|, then start from S 255 To S h Perform a traversal; otherwise, start from S. h Position towards S0 and S 255 Perform a traversal; based on n during the traversal process i The magnitude change is used to obtain the threshold segmentation point Q of the gray value; if J = K = 1, then the value of g is g'1; if J = K = 2, then the value of g is g1 or g2.
[0081] In this embodiment, S is obtained. g Next, it is necessary to determine whether the gray value corresponding to this part is closer to 0 / 255 or the gray value corresponding to the pixel peak. If it is closer to the peak, then the threshold segmentation is performed starting from the peak. If it is closer to the edge, then the threshold segmentation is performed starting from 0 / 255. The specific method is as follows:
[0082] Determine the magnitudes of g and h. If g < h, it indicates that the junction between the grayscale hole region and the continuous grayscale region is located to the left of the grayscale value corresponding to the pixel peak. Then, determine the magnitudes of g and |gh|, i.e., find the point where g is closer to 0 and h. If g < |gh|, then move from S0 to S... h Perform a traversal; if g > h, it means the intersection of the gray-level hole region and the gray-level continuous region is located to the right of the gray-level value corresponding to the pixel peak. Then, determine the magnitude of g and |gh|, that is, find the point where g is closer to 0 and h. If |gh| > |255-g|, then start from S. 255 To S h Perform the traversal; otherwise, it means that g is closer to h, so start from S. h Position towards S0 and S 255 Perform traversal; this traversal method can minimize the amount of computation, improve traversal efficiency, and save traversal time.
[0083] After determining the target location using the above steps, starting from the determined starting point, traverse the two-dimensional array from "both sides towards the middle (if 0 / 255 is the starting point) / from the middle towards both sides (if the peak is the starting point)". Record the magnitude of the number of pixels. If the magnitude changes tenfold, record the gray value corresponding to the point of change as gray value A.
[0084] Then, iterate through the area. If a change of ten times or more occurs again within ten gray values after gray value A, it is considered that the area at the junction of the "hillside" and the "foot of the mountain" has been reached, and the gray value of that point is recorded as gray value B.
[0085] If it starts from 0 / 255, then grayscale value B is the point where "the uphill begins," and this point is used as the threshold segmentation point Q. If it starts from the peak, then grayscale value A is the point where "the downhill begins," and this point is used as the threshold segmentation point Q.
[0086] The specific traversal method includes the following steps:
[0087] Step S601, from S0 to S h Perform the traversal and record n during the traversal. i and n i-1 The order of magnitude of n i The order of magnitude and n i-1If the ratio of their magnitudes is greater than a preset value, record n. i The grayscale value is A.
[0088] Step S602: Continue to traverse the number of pixels corresponding to the ten gray values after A. If the ratio of the magnitude of the number of pixels of two adjacent gray values is greater than a preset value, then record the second gray value of the two adjacent gray values as Q.
[0089] Step S611, from S 255 To S h Perform the traversal and record n during the traversal. i and n i+1 The order of magnitude of n i The order of magnitude and n i+1 If the ratio of their magnitudes is greater than a preset value, record n. i The grayscale value is A.
[0090] Step S612: Continue to traverse the number of pixels corresponding to the ten gray values after A. If the ratio of the magnitude of the number of pixels of two adjacent gray values is greater than a preset value, then record the second gray value of the two adjacent gray values as Q.
[0091] Step S621, from S h Iterate through S0 and record n during the traversal. i and n i-1 The order of magnitude of n i The order of magnitude and n i-1 The ratio of their magnitudes is greater than the preset value and n i If the ratio of the order of magnitude of the number of pixels with two adjacent gray values in the last ten gray values is greater than a preset value, record n. i The grayscale value is Q.
[0092] Step S622, from S h To S 255 Perform the traversal and record n during the traversal. i and n i+1 The order of magnitude of n i The order of magnitude and n i+1 The ratio of their magnitudes is greater than the preset value and n i If the ratio of the order of magnitude of the number of pixels with two adjacent gray values in the last ten gray values is greater than a preset value, record n. i The grayscale value is Q.
[0093] Step S700: Use the gray value corresponding to Q as the upper or lower limit of threshold segmentation to perform threshold segmentation on P to obtain the suspected defect area; and perform noise filtering on the suspected defect area to obtain the first target defect area.
[0094] After determining the threshold segmentation point Q, threshold segmentation is performed using this point Q as the upper / lower limit of the threshold segmentation. Specifically, if Q is found to the left of the peak in the above steps, then the pixels with gray values less than Q are considered as suspected defective pixels. If Q is found to the right of the peak in the above steps, then the pixels with gray values greater than Q are considered as suspected defective pixels.
[0095] This threshold segmentation identifies all defects and some noise together, achieving a detection rate close to 100%, but its accuracy is not high. To improve accuracy, it is necessary to mask the influence of noise. The method for masking the influence of noise is as follows:
[0096] Step S710: Perform threshold segmentation on P based on the upper or lower limit of the threshold segmentation to obtain several defective regions.
[0097] Step S720: Traverse all defective areas and delete defective areas with an area smaller than a preset area to obtain the first target defective area.
[0098] Because noise is a side effect of Gaussian filtering, which concentrates these noise points within a very small number of pixels (1-4 pixels), and such small defects are almost non-existent in nature, noise interference can be filtered out by performing area filtering on all segmented objects; finally, the remaining objects are the defects.
[0099] The above methods can be used to identify defects caused by material issues. In addition to minor defects such as holes and insects, textiles also have major defects such as wrinkles caused by improper stacking and storage. Since the essence of such defects is still the material itself, they will not appear as "abrupt" on the grayscale histogram as they do with regular defects.
[0100] The definition of this type of defect cannot be based on grayscale histogram features as with regular defects; it needs to be determined based on grayscale variance. Grayscale variance is an indicator used to describe the degree of grayscale variation in an image. The larger the grayscale variance, the more drastic the variation; the smaller the grayscale variance, the smoother the variation. Therefore, images with extremely large defects often have a large grayscale variance. Thus, by using high-intensity mean filtering to "remove" these large defects, the grayscale variance of the resulting image will be significantly reduced.
[0101] For images without significant defects, the grayscale variance before and after mean filtering will not differ much. Therefore, by subtracting the grayscale variance before and after mean filtering, if the difference is greater than the user-defined judgment value, the image is considered to have significant defects.
[0102] This embodiment also includes a method for detecting extremely large defects, which includes the following steps:
[0103] Step S800: Perform grayscale processing on the target textile image to obtain a grayscale image P1, and calculate the grayscale variance DX1 of P1.
[0104] In this embodiment, grayscale processing of the target image is a prior art technique and will not be described in detail here.
[0105] Step S900: Filter P1 to obtain a grayscale image P2, and calculate the grayscale variance DX2 of P2.
[0106] In this embodiment, mean filtering is used to filter the grayscale image P1 to obtain the grayscale image P2.
[0107] Step S1100: Mark each connected region in P1 formed by pixels whose difference is greater than a preset difference threshold as a suspected second target defect region.
[0108] Subtracting the gray values of the corresponding pixels in P2 from the gray values of each pixel in P1 yields the difference in gray values of each pixel. Pixels with a difference greater than a preset difference threshold are identified. The preset difference threshold can be set to 10. Each connected region formed by the identified pixels is considered as a suspected second target defect region.
[0109] Step S1200: If the area of the suspected second target region is greater than j*U P1 The suspected second target area is marked as the second target area; where j is a preset scaling factor, 0 < j < 1, U P1 Let P1 be the area.
[0110] Step S1200: If the area of the suspected second target region is greater than j*U P1 The suspected second target area is marked as the second target area; where j is a preset scaling factor, 0 < j < 1, U P1 Let P1 be the area.
[0111] The above steps can identify large defects, but they also mark many shadowed areas that are filtered out. Therefore, these shadowed areas need to be filtered out. Specifically, the area of the entire image P1 is used as a lower limit (j times the area of the entire image) for area filtering. The filtered objects are the second target defect areas, i.e., large defect areas. In this embodiment, the value of j can range from 5% to 10%.
[0112] The defect identification method based on grayscale features in this embodiment has the following characteristics:
[0113] (1) Generate a grayscale histogram based on the grayscale value of the grayscale image. Determine the best traversal path based on the boundary between the hole area of the pixel and the continuous area of the pixel and the grayscale value with the most pixels. This method can find the threshold segmentation point with the shortest traversal path, thereby greatly improving the efficiency of determining the threshold segmentation point.
[0114] (2) By utilizing the characteristic of the sudden change in gray value of defects, this characteristic is characterized as the magnitude change of the pixel corresponding to the gray value. Based on the magnitude change value, the gray value corresponding to the specific threshold segmentation point is determined, which avoids the interference of individual gray noise and improves the accuracy of defect identification.
[0115] (3) The gray values of each pixel in the grayscale image P1 before mean filtering and the grayscale image P2 after mean filtering are subtracted, and the area where the difference in gray values is greater than the preset value is regarded as the large defect area, so as to avoid the influence of non-real defects on the defect recognition structure and further improve the accuracy of defect recognition.
[0116] Furthermore, although the steps of the method in this disclosure are described in a specific order in the accompanying drawings, this does not require or imply that the steps must be performed in that specific order, or that all the steps shown must be performed to achieve the desired result. Additional or alternative steps may be omitted, multiple steps may be combined into one step, and / or a step may be broken down into multiple steps.
[0117] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A method for identifying a defect based on a gray scale feature, characterized by, The method comprises the following steps: Step S100, acquiring a target textile image, and performing grayscale and filtering processing on the target textile image to obtain a grayscale image P; Step S200, traversing all pixel points in P, acquiring the number of pixel points corresponding to each gray value in the range of 0-255 gray values, and constructing a gray histogram Z according to each gray value and the number of pixel points corresponding to each gray value, wherein the X axis of Z is the gray value of the pixel, and the Y axis is the number of pixel points corresponding to the gray value; Step S300, according to Z acquisition array set S=(S0, S1, …, S i ); wherein, S 255 is the array of gray value i, S i =[i, n i ], n i is the number of pixel points corresponding to the gray value i; i Step S400, traversing S to obtain a pixel point number hollow area and a pixel point number continuous area; if J=K=1, the gray value at the boundary of the pixel point number hollow area and the pixel point number continuous area is recorded as g'1; if J=K=2, the gray value at the boundary of the first pixel point number hollow area and the first pixel point number continuous area is recorded as g1, and the gray value at the boundary of the second pixel point number hollow area and the second pixel point number continuous area is recorded as g2, J is the number of obtained pixel point number hollow areas, K is the number of obtained pixel point number continuous areas, the average of the gray values corresponding to the first pixel point number hollow area is less than the average of the gray values corresponding to the second pixel point number hollow area, and the average of the gray values corresponding to the first pixel point number continuous area is less than the average of the gray values corresponding to the second pixel point number continuous area; Step S500, acquiring the gray value h corresponding to the maximum number of pixel points in the gray histogram Z; Step S600, if g < h and g < |g-h|, then go from S0 to S h ; if g > h and |g-h| > |255-g|, then go from S 255 0 to S h ; otherwise, go from the position of S h 0 and S 255 1 to S0; according to the magnitude change of n i during the traversal, obtain the threshold segmentation point Q of the gray value; if J=K=1, then the value of g is g'1; if J=K=2, then the value of g is g1 or g2. Step S700, taking the gray value corresponding to Q as the upper limit or lower limit of threshold segmentation, performing threshold segmentation on P to obtain a suspected defect area, and performing noise filtering on the suspected defect area to obtain a first target defect area; The step S600 comprises: Step S601, from S0 to S h traversing, recording the magnitude of n i and n i-1 during the traversal, if the ratio of the magnitude of n i to the magnitude of n i-1 is greater than a preset value, recording the gray value of n i as A; Step S602, continuing to traverse the number of pixel points corresponding to the ten gray values after A, and if the magnitude ratio of the number of pixel points of two adjacent gray values is greater than a preset value, recording the latter gray value in the two adjacent gray values as Q; The step S600 further comprises: Step S611, from S 255 to S h Perform traversal, record the magnitude of n i and n i+1 during the traversal, if the ratio of the magnitude of n i to the magnitude of n i+1 is greater than a preset value, record the gray value of n i as A; Step S612, continuing to traverse the number of pixel points corresponding to the ten gray values after A, and if the magnitude ratio of the number of pixel points of two adjacent gray values is greater than a preset value, recording the latter gray value in the two adjacent gray values as Q; The step S600 further comprises: Step S621, from S h traversing to S0, recording the magnitude of n i and n i-1 during the traversal, if the ratio of the magnitude of n i to the magnitude of n i-1 is greater than a preset value and the ratio of the magnitude of the number of pixel points of adjacent two gray scale values in the ten gray scale values after n i is greater than a preset value, recording the gray scale value of n i as Q; Step S622, from S h to S 255 Perform traversal, record the magnitude of n i and n i+1 during the traversal, if the ratio of the magnitude of n i and the magnitude of n i+1 is greater than a preset value and the ratio of the magnitude of the number of pixel points of adjacent two gray scale values in the ten gray scale values after n i is greater than a preset value, record the gray scale value of n i as Q.
2. The defect recognition method according to claim 1, characterized by, Traversing S to obtain a pixel point number hollow area, comprising: Step S401, traversing S in the order of gray values 0-255, and recording the first gray value d1 with a pixel point number of 0; Step S402, continuing to traverse the number of pixel points corresponding to the gray values after d1, ignoring the gray values with a pixel point number of 0, and recording the gray value d2 after d1, which is the first gray value with a pixel point number not equal to 0 and the number of pixel points corresponding to the 10 gray values after it not equal to 0; Step S403, taking the area between d1 and d2 as a pixel point number hollow area.
3. The defect recognition method according to claim 1, characterized by, Traversing S to obtain a pixel point number continuous area, comprising: Step S410, traversing S in the order of gray values 0-255, and recording the first gray value d3 with a pixel point number not equal to 0; Step S420, continue to traverse the pixel point quantity corresponding to the gray value after d3, ignore the gray value whose pixel point quantity is not 0, and record the gray value d4 whose pixel point quantity is 0 and which exists in the 10 gray values after the first pixel point quantity after d3 is 0; Step S430, take the region between d3 and d4 as a pixel point quantity continuous region.
4. The defect recognition method according to claim 1, characterized by, The step S700 comprises: Step S710, threshold segmentation of P according to the upper limit or lower limit of threshold segmentation, to obtain a plurality of defect regions; Step S720, traverse all the defect regions, delete the defect region whose area is less than the preset area, and obtain the first target defect region.
5. The defect recognition method according to claim 1, characterized by, The method further comprises the following steps: Step S800, perform gray processing on the target textile image to obtain a gray image P1, and calculate the gray variance DX1 of P1; Step S900, perform filtering processing on P1 to obtain a gray image P2, and calculate the gray variance DX2 of P2; Step S1000, if DX1-DX2>DX0, subtract the gray value corresponding to the pixel point in P2 from the gray value of each pixel point in P1 to obtain the difference value of each pixel point in P1 and P2; wherein DX0 is a preset gray variance threshold; Step S1100, mark each connected region composed of the pixel points in P1 whose difference value is greater than the preset difference value threshold as a suspected second target defect region; Step S1200, if the area of the suspected second target region is greater than j*U P1 marks the suspected second target region as the second target region; wherein j is a preset proportion coefficient, 0 P1 is the area of P1.
6. The defect recognition method according to claim 5, wherein The value range of j is 5% to 10%.
7. The defect recognition method according to claim 1, characterized by, The filtering processing in step S100 comprises the following steps: Step S110, generate E3 by subtracting E2 from E1; wherein E1 and E2 are both preset Gaussian filtering kernels, the scale of E1 and E2 is different by 1, and E3 is a filtering kernel generated by E1 and E2; Step S120, perform filtering processing on the gray image by E3 to obtain P.
Citation Information
Patent Citations
Textile defect detection method based on machine vision
CN115272321A