Textile defect detection method based on image processing
Through image processing technology, the grayscale and gradient characteristics of textile surfaces are analyzed, the extension and random parameters are calculated, the accuracy of textile defect detection is improved, and the problem of textile texture affecting detection results is solved.
Patent Information
- Application Number
- CN202411074427.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-07
- Publication Date
- 2024-11-05
- Estimated Expiration
- 2044-08-07
AI Technical Summary
In the prior art, the texture characteristics of textiles will affect edge detection, resulting in insufficient accuracy and reliability of defect detection.
Using an image processing-based method, by obtaining the grayscale image of the textile surface, dividing it into image blocks of preset size, analyzing the grayscale aggregation degree and gradient direction of each image block, and determining the extension parameters and randomness based on the grayscale and gradient characteristics. , calculate defect probability, perform defect block screening and binarization analysis to improve detection accuracy.
Effectively avoid the impact of textile texture on defect detection, improve the accuracy and reliability of defect detection, and can more accurately analyze defect areas on textile surfaces.
Smart Images

Figure CN118587223B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of image analysis, and in particular to a textile defect detection method based on image processing. Background Art
[0002] Textiles are important materials for clothing, home furnishings, industry and other fields. Ensuring the quality of textiles is crucial for comfort, aesthetics and functionality. Structural defects, especially missing and misaligned threads, may affect the appearance, durability and use of textiles. Therefore, defect detection of textile surfaces is required during the textile production process.
[0003] In the related art, defects such as missing lines and misaligned lines on the surface of textiles are detected directly based on edge detection. In this method, since the textile itself also has a corresponding textile texture, the textile texture will also affect the edge detection, and then affect the analysis of defect detection, resulting in insufficient accuracy and reliability of defect detection. Summary of the invention
[0004] In order to solve the technical problem in the related art that normal textile texture also affects edge detection, and further affects the analysis of defect detection, resulting in insufficient accuracy and reliability of defect detection, the present invention provides a textile defect detection method based on image processing, and the technical solution adopted is as follows:
[0005] The present invention proposes a textile defect detection method based on image processing, the method comprising:
[0006] Acquire a grayscale image of the textile surface, divide the grayscale image into image blocks of a preset size, and determine the grayscale aggregation degree of the image blocks according to the grayscale distribution of pixels in each image block within a corresponding preset first neighborhood range;
[0007] Any image block is used as a block to be tested, and other image blocks within a preset second neighborhood range of the block to be tested are used as neighborhood blocks; the defect extension direction of the block to be tested is determined according to the gradient direction of all pixels in the block to be tested; and the extension parameter of the block to be tested is determined according to the difference between the grayscale aggregation degree of the block to be tested and the grayscale aggregation degrees of the neighborhood blocks and all neighborhood blocks in the defect extension direction;
[0008] Determine the randomness parameter of the block to be tested according to the difference in grayscale values of pixels in the block to be tested and all other image blocks except the block to be tested; determine the defect probability of the block to be tested according to the extension parameter of the block to be tested and the randomness parameter of the block to be tested;
[0009] All image blocks are screened according to the defect probability of each image block to obtain defect blocks, the grayscale image is binarized according to the grayscale values of the pixels in all the defect blocks to obtain a binarized image, and defect detection is performed according to the binarized image to obtain a detection result.
[0010] Furthermore, the grayscale aggregation degree of the image block is determined according to the grayscale distribution of the pixel points in each image block within the corresponding preset first neighborhood range, and the corresponding calculation formula is:
[0011] ; In the formula, represents the grayscale aggregation degree of the zth image block, z represents the index of the image block, M represents the number of all pixels in the image block, and x represents the index of the pixel in the image block. Represents the gray value of the xth pixel in the zth image block, Represents the maximum grayscale value of all pixels in the z-th image block, represents the gray value of the yth pixel in the preset first neighborhood of the xth pixel in the image block, y represents the index of other pixels in the corresponding preset first neighborhood, and N represents the total number of all pixels in the corresponding preset first neighborhood. Indicates taking the absolute value.
[0012] Further, determining the defect extension direction of the block to be tested according to the gradient directions of all pixels in the block to be tested includes:
[0013] Constructing a two-dimensional angle coordinate system to determine the angle value corresponding to the gradient direction of each pixel point in the block to be tested;
[0014] The average of the angle values corresponding to the gradient directions of all the pixels in the block to be tested is calculated, and any direction perpendicular to the direction corresponding to the average is used as the defect extension direction of the block to be tested.
[0015] Further, determining the extension parameter of the block to be tested according to the difference between the grayscale aggregation degree of the block to be tested and the grayscale aggregation degrees of the neighboring blocks and all neighboring blocks in the defect extension direction, includes:
[0016] Calculating the absolute value of the difference between the grayscale aggregation degree of the block to be tested and the grayscale aggregation degree of each neighboring block to obtain the neighborhood aggregation difference;
[0017] Taking the neighborhood clustering difference corresponding to the neighborhood blocks in the defect extension direction as the extension clustering difference;
[0018] The extension parameter of the block to be tested is determined according to all neighborhood clustering differences and extension clustering differences.
[0019] Further, determining the extension parameter of the block to be tested according to all neighborhood clustering differences and extended clustering differences includes:
[0020] Calculating the mean of the extension aggregation differences as the extension mean;
[0021] The extension index is calculated by taking the extension mean as the numerator and the maximum value of the neighborhood aggregation difference as the denominator;
[0022] The extension index is negatively correlated and normalized to obtain the extension parameter of the block to be tested.
[0023] Furthermore, determining the randomness parameter of the block to be tested according to the grayscale value difference between the block to be tested and pixels in all other image blocks except the block to be tested includes:
[0024] Calculate the mean grayscale value of all pixels in each image block to obtain the block grayscale index of the corresponding image block;
[0025] Based on the mean square error formula, the mean square error of the block gray index of the block to be tested and the block gray indexes of all other image blocks except the block to be tested are calculated to obtain the block gray dispersion coefficient of the block to be tested;
[0026] The block grayscale discrete coefficient of the block to be tested is normalized to obtain the randomness parameter of the block to be tested.
[0027] Furthermore, the extension parameter of the block to be tested is positively correlated with the defect probability of the block to be tested, the randomness parameter of the block to be tested is positively correlated with the defect probability of the block to be tested, and the value of the defect probability is a normalized value.
[0028] Furthermore, the step of screening all image blocks according to the defect probability of each image block to obtain defective blocks includes:
[0029] When the defect probability of the image block is greater than a preset defect threshold, the image block is regarded as a defect block.
[0030] Furthermore, the performing binarization analysis on the grayscale image according to the grayscale values of the pixels in all the defective blocks to obtain a binarized image includes:
[0031] Calculate the maximum inter-class variance segmentation threshold of the grayscale values of all pixels in the defective blocks based on the Otsu threshold method;
[0032] The pixel points in the grayscale image whose grayscale values are greater than the maximum inter-class variance segmentation threshold are marked as 0; otherwise, they are marked as 1 to obtain a binary image.
[0033] Further, the performing defect detection according to the binary image to obtain a detection result includes:
[0034] According to preset distribution characteristics of different defect types in the binary image, feature matching is performed on the binary image to determine the defect type of the defect area in the binary image, and the defect type is used as the detection result.
[0035] The present invention has the following beneficial effects:
[0036] The present invention obtains a grayscale image of the surface of a textile and divides the grayscale image into blocks. The grayscale aggregation degree is determined according to the grayscale distribution of each image block. The grayscale aggregation degree characterizes the distribution characteristics of the pixels in the image block. An effective grayscale distribution analysis is performed on each image block. Then, the defect extension direction is determined according to the gradient direction of all the pixels in the image block. The extension parameter is determined by combining the grayscale aggregation degree and the defect extension direction. The extension parameter is determined by combining the grayscale distribution and the gradient distribution. Thus, the texture characteristics of the textile surface, such as missing lines and wrong lines, can be analyzed by combining multiple angles of grayscale changes and gradient changes, so as to avoid the influence of the texture characteristics of the textile itself on defect detection, so that the extension parameter can effectively characterize the extension of the pixel distribution. The grayscale changes of the image block are used to determine the randomness parameters of the block to be tested. Since the texture features such as missing lines and wrong lines on the surface of the textile will affect multiple adjacent image blocks, while the normal texture only affects a smaller area, this solution analyzes the randomness parameters to analyze the abnormal conditions of the adjacent image blocks to improve the accuracy of the overall defect analysis; thus, the present invention combines the extension parameters and the randomness parameters to determine the defect probability, so that the defect probability can effectively divide the abnormal texture and normal texture of the textile itself, and screen the image blocks by the defect probability to determine the defective blocks, and perform a binary analysis based on the grayscale of the pixels in the defective blocks, so that the binary analysis further avoids the influence of the normal textile texture, thereby improving the accuracy of the detection results obtained by defect detection. In summary, the present invention combines the differentiated characteristics of the defective texture and the normal texture on the surface of the textile to effectively analyze the defective area and improve the accuracy and reliability of defect detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the technical solutions and advantages in the embodiments of the present invention or the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0038] Figure 1A flow chart of a textile defect detection method based on image processing provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0039] In order to further explain the technical means and effects adopted by the present invention to achieve the predetermined invention purpose, the following is a detailed description of the specific implementation, structure, features and effects of a textile defect detection method based on image processing proposed by the present invention in combination with the accompanying drawings and preferred embodiments. In the following description, different "one embodiment" or "another embodiment" does not necessarily refer to the same embodiment. In addition, specific features, structures or characteristics in one or more embodiments may be combined in any suitable form.
[0040] Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs.
[0041] A specific scheme of a textile defect detection method based on image processing provided by the present invention is described in detail below with reference to the accompanying drawings.
[0042] See also Figure 1 , which shows a flow chart of a textile defect detection method based on image processing provided by an embodiment of the present invention, the method comprising:
[0043] S101: Acquire a grayscale image of a textile surface, divide the grayscale image into image blocks of a preset size, and determine the grayscale aggregation degree of the image block according to the grayscale distribution of pixels in each image block within a corresponding preset first neighborhood range.
[0044] A specific implementation scenario of the present invention is to analyze the grayscale image of the textile surface to determine the defects of the textile surface. It is understandable that after the production of textiles, due to mechanical problems, yarn quality or operational errors, corresponding defects such as missing threads and wrong threads will occur. Therefore, they need to be screened. Since the textile surface has certain normal texture details, when performing abnormal screening, the normal texture of the textile surface will affect the actual defect detection effect. Therefore, it is necessary to perform abnormal analysis to avoid the influence of the textile texture itself and improve the accuracy and reliability of defect detection.
[0045] In an embodiment of the present invention, a light source and a high-precision image acquisition device may be arranged directly above the textile to acquire an original image of the textile surface, and then the original image is subjected to image preprocessing to obtain a grayscale image. The image preprocessing in the embodiment of the present invention may specifically include, for example, image denoising, image grayscale processing, and semantic segmentation and other preprocessing means, wherein the image denoising may specifically include, for example, mean denoising, and the image grayscale processing may specifically include, for example, mean grayscale processing. Of course, in other embodiments of the present invention, the technical means used for preprocessing may also be adjusted as required to meet the actual usage scenario, and no further elaboration or limitation is made thereon.
[0046] Among them, the preset size is the size of the image block. In an embodiment of the present invention, the grayscale image can be divided into image blocks of size 11×11. Of course, in other embodiments of the present invention, the size of the image block can also be adjusted according to the actual textile texture and detection requirements, and there is no limitation on this.
[0047] It is understandable that within the image block, the distribution range of the texture area is large and the distribution is relatively discrete. Due to the influence of missing lines and wrong lines, the abnormal area of the textile will produce the phenomenon of missing textile lines at the corresponding position, which will lead to gaps in the corresponding position, and low grayscale texture will be formed under light. While the abnormal textile area shows a large grayscale difference from the normal area, the distribution is relatively concentrated, and the abnormal area is usually caused by a textile line, generally in a straight line. Therefore, the concentration of low grayscale value pixels within the image block is analyzed. When the distribution of low grayscale value pixels in the image block is relatively concentrated, there may be textile abnormalities in the image block. If the distribution of low grayscale value pixels in the image block is relatively discrete, the low grayscale value pixels in the image block are normal textile texture pixels.
[0048] Furthermore, in some embodiments of the present invention, the grayscale aggregation degree of the image block is determined according to the grayscale distribution of the pixels in each image block within the corresponding preset first neighborhood range, and the corresponding calculation formula is:
[0049]
[0050] In the formula, represents the grayscale aggregation degree of the zth image block, z represents the index of the image block, M represents the number of all pixels in the image block, and x represents the index of the pixel in the image block. Represents the gray value of the xth pixel in the zth image block, Represents the maximum grayscale value of all pixels in the z-th image block, represents the gray value of the yth pixel in the preset first neighborhood of the xth pixel in the image block, y represents the index of other pixels in the corresponding preset first neighborhood, and N represents the total number of all pixels in the corresponding preset first neighborhood. Indicates taking the absolute value.
[0051] Among them, the preset first neighborhood range is the neighborhood range when performing grayscale aggregation degree analysis. Optionally, the preset first neighborhood range in the embodiment of the present invention can be specifically, for example, an eight-neighborhood range, which is not limited.
[0052] From the above formula, we can see that Indicates the grayscale difference of the neighborhood. The greater the grayscale value difference between any pixel and other pixels in the corresponding preset first neighborhood, the greater the grayscale change around the corresponding central pixel, and the lower the degree of aggregation. Therefore, negative correlation mapping is performed and normalized. It represents the ratio of the grayscale value of the xth pixel in the zth image block to the maximum grayscale value in the zth image block. The smaller the ratio is, the lower the grayscale of the xth pixel is, and the more it conforms to the characteristics of low grayscale pixels, the higher the weight of the pixel is.
[0053] Thus, the grayscale aggregation degree of the image block is calculated. The larger the grayscale aggregation degree value is, the more likely the corresponding image block is to have abnormal texture features, that is, the more likely the image block is to be a region where textile abnormalities occur.
[0054] S102: Take any image block as a block to be tested, and other image blocks within a preset second neighborhood range of the block to be tested as neighborhood blocks; determine the defect extension direction of the block to be tested according to the gradient direction of all pixels in the block to be tested; determine the extension parameters of the block to be tested according to the difference between the grayscale aggregation degree of the block to be tested and the grayscale aggregation degrees of the neighborhood blocks and all neighborhood blocks in the defect extension direction.
[0055] In the embodiment of the present invention, any image block can be selected as the block to be tested, and the neighborhood blocks of the block to be tested can be determined, so as to perform specific analysis on the block to be tested. The preset second neighborhood range is the range corresponding to the block to be tested when performing local texture analysis. Other image blocks within the eight neighborhood ranges around the block to be tested can be used as neighborhood blocks, or fixed distance features can be selected to use other image blocks within a specific spatial range around the block to be tested as neighborhood blocks, and there is no limitation on this.
[0056] Among them, extensibility is the characteristic of the block to be tested that is affected by the extension effect of abnormal textures such as missing lines and wrong lines. It is manifested in that the texture characteristics of the block to be tested itself are similar to those of other image blocks in the abnormal direction, and the extension parameters are analyzed based on this.
[0057] Furthermore, in some embodiments of the present invention, the defect extension direction of the block to be tested is determined based on the gradient direction of all pixel points in the block to be tested, including: constructing a two-dimensional angular coordinate system to determine the angle value corresponding to the gradient direction of each pixel point in the block to be tested; calculating the mean of the angle values corresponding to the gradient directions of all pixel points in the block to be tested, and taking any perpendicular direction to the direction corresponding to the mean as the defect extension direction of the block to be tested.
[0058] Among them, the defect extension direction, that is, the texture direction caused by abnormal defects such as missing lines and misaligned lines. In the embodiment of the present invention, the gradient direction of each pixel point in the block to be tested can be determined, and the gradient direction is placed in the constructed two-dimensional angular coordinate system. Since in the same coordinate system, different gradient directions can be assigned corresponding angle values based on a fixed clockwise direction, then the average of the angle values of the gradient directions of all pixel points is calculated, and the average is used as the block gradient direction of the corresponding block to be tested, which also represents the gradient direction of the block to be tested itself.
[0059] In an embodiment of the present invention, any perpendicular direction of the block gradient direction can be used as the defect extension direction of the block to be tested. Through the perpendicular direction of the gradient direction, the texture of the pixel points in the block to be tested can be accurately analyzed. Since the grayscale distribution of normal textile texture is relatively discrete, the defect extension direction of the normal texture is significantly different from the defect extension direction of the abnormal texture, and abnormal analysis can be performed based on this.
[0060] Furthermore, in some embodiments of the present invention, the extension parameters of the block to be tested are determined based on the differences in the grayscale aggregation levels of the block to be tested and the grayscale aggregation levels of the neighboring blocks and all neighboring blocks in the defect extension direction, including: calculating the absolute values of the differences between the grayscale aggregation levels of the block to be tested and the grayscale aggregation levels of each neighboring block to obtain the neighborhood aggregation difference; taking the neighborhood aggregation difference corresponding to the neighboring blocks in the defect extension direction as the extended aggregation difference; and determining the extension parameters of the block to be tested based on all neighborhood aggregation differences and the extended aggregation difference.
[0061] In an embodiment of the present invention, the grayscale aggregation degree of the block to be tested and the neighboring blocks is calculated to obtain the neighborhood aggregation difference. Since anomalies such as missing lines and wrong lines usually affect image blocks within a continuous range, the grayscale aggregation degree of the block to be tested and the neighboring blocks is analyzed. The smaller the neighborhood aggregation difference, the more similar the texture features of the neighboring block and the block to be tested are, and the larger the neighborhood aggregation difference, the greater the texture difference between the neighboring block and the block to be tested.
[0062] In the embodiment of the present invention, since the abnormal effects such as missing lines and misaligned lines are usually straight lines and in the defect extension direction, the neighborhood clustering difference corresponding to the neighborhood blocks in the defect extension direction is used as the extended clustering difference.
[0063] Furthermore, in some embodiments of the present invention, the extension parameters of the block to be tested are determined based on all neighborhood clustering differences and extended clustering differences, including: calculating the mean of the extended clustering differences as the extended mean; using the extended mean as the numerator and the maximum value of the neighborhood clustering differences as the denominator to calculate the extension index; performing negative correlation mapping on the extension index and normalizing it to obtain the extension parameters of the block to be tested.
[0064] Since there may be multiple neighboring blocks in the defect extension direction, the mean of multiple extension aggregation differences is calculated as the extension mean, and then the ratio of the extension mean to the maximum value of the neighborhood aggregation difference is calculated. The larger the ratio is, the greater the difference in the degree of aggregation of the low grayscale components of the block to be tested and the neighboring blocks in the defect extension direction. The greater the difference is compared with the difference of all its neighboring single blocks, which means that the extensibility of the block to be tested is worse. The extension index is negatively correlated and normalized to obtain the extension parameter of the block to be tested. That is, the larger the extension parameter is, the greater the abnormal texture extension feature of the block to be tested in the defect extension direction, and the more it conforms to abnormal features such as missing lines and wrong lines.
[0065] In one embodiment of the present invention, the normalization processing can be specifically, for example, maximum and minimum value normalization processing, and the normalization in subsequent steps can all adopt maximum and minimum value normalization processing. In other embodiments of the present invention, other normalization methods can be selected according to the specific range of numerical values, which will not be described in detail.
[0066] Among them, a positive correlation means that the dependent variable will increase as the independent variable increases, and the dependent variable will decrease as the independent variable decreases. The specific relationship can be a multiplication relationship, an addition relationship, or the power of an exponential function, which is determined by actual application; a negative correlation means that the dependent variable will decrease as the independent variable increases, and the dependent variable will increase as the independent variable decreases. It can be a subtraction relationship, a division relationship, etc., which is determined by actual application.
[0067] That is to say, in the embodiment of the present invention, the extension index is negatively correlated and normalized to obtain the extension parameter of the block to be tested. Specifically, for example, the negative of the extension index is calculated and the negative number is normalized, or the inverse of the extension index can be calculated and normalized. There is no limitation on this.
[0068] S103: determining a randomness parameter of the block to be tested according to a difference in grayscale values of pixels in the block to be tested and all other image blocks except the block to be tested; determining a defect probability of the block to be tested according to an extension parameter of the block to be tested and the randomness parameter of the block to be tested.
[0069] Furthermore, in some embodiments of the present invention, the randomness parameter of the block to be tested is determined based on the difference in grayscale values of pixels in the block to be tested and all other image blocks except the block to be tested, including: calculating the mean grayscale value of all pixels in each image block to obtain a block grayscale index of the corresponding image block; based on the mean square error formula, calculating the mean square error of the block grayscale index of the block to be tested and the block grayscale index of all other image blocks except the block to be tested to obtain a block grayscale discrete coefficient of the block to be tested; and normalizing the block grayscale discrete coefficient of the block to be tested to obtain the randomness parameter of the block to be tested.
[0070] Among them, the extensibility means that the block to be tested is affected by the extension effect of abnormal textures such as missing lines and misaligned lines. Since abnormal textures such as missing lines and misaligned lines will also affect the grayscale value distribution of pixel points, the present invention performs feature analysis on the grayscale value distribution to determine the randomness, that is, the similarity between the grayscale distribution of the block to be tested and the grayscale distribution of all other image blocks except the block to be tested.
[0071] The present invention uses the grayscale mean as the grayscale feature for analysis, calculates the grayscale value mean of all pixels in each image block, and obtains the block grayscale index of the corresponding image block; then, based on the mean square error formula, calculates the mean square error of the block grayscale index of the block to be tested and the block grayscale index of all other image blocks except the block to be tested, and obtains the block grayscale dispersion coefficient of the block to be tested, that is, the larger the value of the block grayscale dispersion coefficient, the greater the difference between the grayscale feature of the corresponding block to be tested and the grayscale feature of the grayscale image of the entire textile. The block grayscale dispersion coefficient of the block to be tested is normalized to obtain the randomness parameter of the block to be tested. The larger the randomness parameter, the more likely the block to be tested is an image block corresponding to a defective area.
[0072] Therefore, the present invention can combine extension parameters and randomness parameters to perform defect analysis. Furthermore, in some embodiments of the present invention, the extension parameters of the block to be tested are positively correlated with the defect probability of the block to be tested, the randomness parameters of the block to be tested are positively correlated with the defect probability of the block to be tested, and the value of the defect probability is a normalized value.
[0073] That is, the product of the extension parameter and the randomness parameter can be calculated and normalized to obtain the defect probability, or the sum of the extension parameter and the randomness parameter can be calculated and normalized to obtain the defect probability, and there is no restriction on this.
[0074] In the embodiment of the present invention, the defect probability can be combined with the extension parameter and the randomness parameter to perform a specific abnormality analysis, thereby avoiding the influence of normal textile texture characteristics on the abnormality analysis when the abnormality analysis is performed only based on the grayscale value, thereby improving the reliability and objectivity of the defect analysis.
[0075] S104: Screen all image blocks according to the defect probability of each image block to obtain defect blocks, perform binarization analysis on the grayscale image according to the grayscale values of the pixels in all defect blocks to obtain a binary image, and perform defect detection based on the binary image to obtain a detection result.
[0076] In the embodiment of the present invention, after the defect probability of each image block is determined, the image blocks may be screened in combination with the defect probability.
[0077] Furthermore, in some embodiments of the present invention, all image blocks are screened according to the defect probability of each image block to obtain defective blocks, including: when the defect probability of an image block is greater than a preset defect threshold, the image block is regarded as a defective block.
[0078] The preset defect threshold is a threshold value of the defect probability. The preset defect threshold in the embodiment of the present invention can be specifically, for example, 0.8, that is, an image block with a defect probability greater than 0.8 is regarded as a defective block. Of course, in other embodiments of the present invention, the preset defect threshold can also be adjusted according to actual detection requirements, and there is no limitation on this.
[0079] Furthermore, in some embodiments of the present invention, a grayscale image is binarized according to the grayscale values of pixels in all defective blocks to obtain a binary image, including: calculating the maximum inter-class variance segmentation threshold of the grayscale values of pixels in all defective blocks based on the Otsu threshold method; marking the pixels in the grayscale image whose grayscale values are greater than the maximum inter-class variance segmentation threshold as 0; otherwise, marking them as 1 to obtain a binary image.
[0080] Among them, the Otsu threshold method is a threshold calculation method well known to technical personnel in this field. Based on the Otsu threshold method, the maximum inter-class variance analysis can be performed on the grayscale values of pixels in all defective blocks to determine the maximum inter-class variance segmentation threshold. This process is a commonly used analysis process in this field and will not be further limited or elaborated on.
[0081] After determining the maximum inter-class variance segmentation threshold, the entire grayscale image can be binarized and the pixels in the grayscale image whose grayscale values are greater than the maximum inter-class variance segmentation threshold are marked as 0; otherwise, they are marked as 1 to obtain a binary image.
[0082] In the embodiment of the present invention, the acquisition of the binary image combines the extension parameter and the randomness parameter, that is, the binarization analysis is performed according to the extension effect and the grayscale difference effect of the image texture, thereby ensuring that the binary image can more accurately and effectively characterize the abnormal texture details, effectively distinguish the texture features, and facilitate the subsequent abnormality analysis.
[0083] Furthermore, in some embodiments of the present invention, defect detection is performed based on a binary image to obtain a detection result, including: performing feature matching on the binary image based on preset distribution characteristics of different defect types in the binary image, determining the defect type of the defective area in the binary image, and using the defect type as the detection result.
[0084] Among them, the preset distribution features are texture distribution features corresponding to abnormal conditions such as missing lines and wrong lines. In the embodiment of the present invention, historical samples can be used for feature analysis to obtain the preset distribution features, or a corresponding neural network analysis model can be constructed to extract features and obtain the preset distribution features. There is no limitation on this.
[0085] In the embodiment of the present invention, feature matching can specifically use the SIFT feature matching algorithm, or can also use a variety of other possible feature matching algorithms according to actual detection requirements to achieve feature matching processing of the binary image, without limitation. Obtaining the defect type by performing feature matching on the binary image can effectively avoid the influence of the textile surface texture on the abnormal situation when directly analyzing based on the gray value, thereby improving the accuracy of defect type analysis.
[0086] The present invention obtains a grayscale image of the surface of a textile and divides the grayscale image into blocks. The grayscale aggregation degree is determined according to the grayscale distribution of each image block. The grayscale aggregation degree characterizes the distribution characteristics of the pixels in the image block. An effective grayscale distribution analysis is performed on each image block. Then, the defect extension direction is determined according to the gradient direction of all the pixels in the image block. The extension parameter is determined by combining the grayscale aggregation degree and the defect extension direction. The extension parameter is determined by combining the grayscale distribution and the gradient distribution. Thus, the texture characteristics of the textile surface, such as missing lines and wrong lines, can be analyzed by combining multiple angles of grayscale changes and gradient changes, so as to avoid the influence of the texture characteristics of the textile itself on defect detection, so that the extension parameter can effectively characterize the extension of the pixel distribution. The grayscale changes of the image block are used to determine the randomness parameters of the block to be tested. Since the texture features such as missing lines and wrong lines on the surface of the textile will affect multiple adjacent image blocks, while the normal texture only affects a smaller area, this solution analyzes the randomness parameters to analyze the abnormal conditions of the adjacent image blocks to improve the accuracy of the overall defect analysis; thus, the present invention combines the extension parameters and the randomness parameters to determine the defect probability, so that the defect probability can effectively divide the abnormal texture and normal texture of the textile itself, and screen the image blocks by the defect probability to determine the defective blocks, and perform a binary analysis based on the grayscale of the pixels in the defective blocks, so that the binary analysis further avoids the influence of the normal textile texture, thereby improving the accuracy of the detection results obtained by defect detection. In summary, the present invention combines the differentiated characteristics of the defective texture and the normal texture on the surface of the textile to effectively analyze the defective area and improve the accuracy and reliability of defect detection.
[0087] It should be noted that the sequence of the above embodiments of the present invention is only for description and does not represent the advantages and disadvantages of the embodiments. The processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0088] The various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referenced to each other, and each embodiment focuses on the differences from other embodiments.
Claims
1. A textile defect detection method based on image processing, characterized in that: The method comprises: Acquire a grayscale image of the textile surface, divide the grayscale image into image blocks of a preset size, and determine the grayscale aggregation degree of the image block according to the grayscale distribution of pixels in each image block within a corresponding preset first neighborhood range, wherein the preset first neighborhood range is a neighborhood range for grayscale aggregation degree analysis; Any image block is used as a block to be tested, and other image blocks within a preset second neighborhood range of the block to be tested are used as neighborhood blocks; the defect extension direction of the block to be tested is determined according to the gradient direction of all pixel points in the block to be tested; the extension parameter of the block to be tested is determined according to the difference between the grayscale aggregation degree of the block to be tested and the grayscale aggregation degree of the neighborhood block and all neighborhood blocks in the defect extension direction, wherein the preset second neighborhood range is the range corresponding to the block to be tested when performing local texture analysis; Determine the randomness parameter of the block to be tested according to the difference in grayscale values of pixels in the block to be tested and all other image blocks except the block to be tested; determine the defect probability of the block to be tested according to the extension parameter of the block to be tested and the randomness parameter of the block to be tested; Screening all image blocks according to the defect probability of each image block to obtain defect blocks, performing binarization analysis on the grayscale image according to the grayscale values of the pixels in all the defect blocks to obtain a binarized image, and performing defect detection according to the binarized image to obtain a detection result; The step of determining the defect extension direction of the block to be tested according to the gradient directions of all pixels in the block to be tested includes: Constructing a two-dimensional angle coordinate system to determine the angle value corresponding to the gradient direction of each pixel point in the block to be tested; Calculate the average of the angle values corresponding to the gradient directions of all the pixels in the block to be tested, and use any direction perpendicular to the direction corresponding to the average as the defect extension direction of the block to be tested; Determining the extension parameter of the block to be tested according to the difference between the grayscale aggregation degree of the block to be tested and the grayscale aggregation degrees of the neighboring blocks and all neighboring blocks in the defect extension direction, comprises: Calculating the absolute value of the difference between the grayscale aggregation degree of the block to be tested and the grayscale aggregation degree of each neighboring block to obtain the neighborhood aggregation difference; Taking the neighborhood clustering difference corresponding to the neighborhood blocks in the defect extension direction as the extension clustering difference; Determining the extension parameter of the block to be tested according to all neighborhood clustering differences and extension clustering differences; The step of determining the extension parameter of the block to be tested according to all neighborhood clustering differences and extension clustering differences includes: Calculating the mean of the extension aggregation differences as the extension mean; The extension index is calculated by taking the extension mean as the numerator and the maximum value of the neighborhood aggregation difference as the denominator; Performing negative correlation mapping and normalization processing on the extension index to obtain the extension parameter of the block to be tested; The step of determining the randomness parameter of the block to be tested according to the difference in grayscale values of pixels in the block to be tested and all other image blocks except the block to be tested comprises: Calculate the mean grayscale value of all pixels in each image block to obtain the block grayscale index of the corresponding image block; Based on the mean square error formula, the mean square error of the block gray index of the block to be tested and the block gray indexes of all other image blocks except the block to be tested are calculated to obtain the block gray dispersion coefficient of the block to be tested; Normalizing the block grayscale discrete coefficient of the block to be tested to obtain a randomness parameter of the block to be tested; The extension parameter of the block to be tested is positively correlated with the defect probability of the block to be tested, the randomness parameter of the block to be tested is positively correlated with the defect probability of the block to be tested, and the value of the defect probability is a normalized value.
2. A textile defect detection method based on image processing as claimed in claim 1, characterized in that: According to the grayscale distribution of the pixels in each image block within the corresponding preset first neighborhood, the grayscale aggregation degree of the image block is determined, and the corresponding calculation formula is: ; In the formula, represents the grayscale aggregation degree of the zth image block, z represents the index of the image block, M represents the number of all pixels in the image block, and x represents the index of the pixel in the image block. Represents the gray value of the xth pixel in the zth image block, Represents the maximum grayscale value of all pixels in the z-th image block, represents the gray value of the yth pixel in the preset first neighborhood of the xth pixel in the image block, y represents the index of other pixels in the corresponding preset first neighborhood, and N represents the total number of all pixels in the corresponding preset first neighborhood. Indicates taking the absolute value.
3. A textile defect detection method based on image processing as claimed in claim 1, characterized in that: The step of screening all image blocks according to the defect probability of each image block to obtain defective blocks includes: When the defect probability of the image block is greater than a preset defect threshold, the image block is regarded as a defect block.
4. A textile defect detection method based on image processing as claimed in claim 1, characterized in that: The step of performing binarization analysis on the grayscale image according to the grayscale values of the pixels in all the defective blocks to obtain a binarized image comprises: Calculate the maximum inter-class variance segmentation threshold of the grayscale values of all pixels in the defective blocks based on the Otsu threshold method; The pixel points in the grayscale image whose grayscale values are greater than the maximum inter-class variance segmentation threshold are marked as 0; otherwise, they are marked as 1 to obtain a binary image.
5. A textile defect detection method based on image processing as claimed in claim 1, characterized in that: The performing defect detection according to the binary image to obtain a detection result includes: According to preset distribution characteristics of different defect types in the binary image, feature matching is performed on the binary image to determine the defect type of the defect area in the binary image, and the defect type is used as the detection result.
