A textile defect detection method and system based on machine vision

Through a textile defect detection method based on machine vision, textile defects are segmented using sliding window processing and watershed algorithm, which solves the problem of insufficient accuracy of manual detection and deformation of structural methods, and achieves efficient and accurate defect detection and classification.

CN116523899BActive Publication Date: 2025-09-30RUGAO JINYI TEXTILE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310655392.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-05
Publication Date
2025-09-30
Estimated Expiration
2043-06-05

AI Technical Summary

Technical Problem

In the existing technology, manual inspection of textile defects lacks accuracy and reliability, and the structural method is difficult to effectively describe the deformation and diversity of fabric texture primitives, resulting in inaccurate detection results.

Method used

A textile defect detection method based on machine vision is adopted. The textile grayscale image is processed by sliding window and grayscale co-occurrence matrix is ​​calculated to reconstruct the contrast map. The defect edge is segmented using the watershed algorithm. The defect area is obtained and evaluated by combining contrast and smoothness threshold processing.

Benefits of technology

It improves the accuracy and efficiency of textile defect detection, reduces labor intensity, solves the problems of over-segmentation and boundary fragmentation in traditional methods, and provides better detection effects and classification basis.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116523899B_ABST
    Figure CN116523899B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of textiles and provides a method and system for detecting textile defects based on machine vision, comprising: obtaining a grayscale image of the textile; calculating the contrast of each pixel; calculating the smoothness of the pixel; obtaining a reconstructed contrast map; segmenting the reconstructed contrast map using a watershed algorithm to obtain defect edges; obtaining defect regions based on the defect edges, and evaluating textile defects based on the defect regions. By constructing a contrast watershed segmentation method, the present invention solves the problems of over-segmentation and boundary fragmentation caused by traditional grayscale watershed segmentation, resulting in better detection results.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of textiles, and in particular to a method and system for detecting textile defects based on machine vision. Background Art

[0002] Quality control plays a crucial role in the textile industry, particularly fabric defect detection. Defects can severely impact textile quality. Some defects, such as double warp and weft contamination, significantly impact the textile's appearance but less so its strength. Missing warps, missing wefts, or broken warps and wefts significantly impact not only the textile's appearance but also its strength, necessitating prompt sorting and resolution. Manual fabric inspection is tedious and laborious. Due to the influence of the inspector's physical, psychological, and subjective factors, as well as the limitations of labor intensity, it's difficult to guarantee high accuracy and reliability in test results.

[0003] Structural methods are based on texture primitives and their arrangement rules. However, for fabric images, the yarns in real fabrics are subject to deformation due to weaving tension and yarn flexibility, which makes the extraction of texture primitives and the description of their arrangement rules difficult. Furthermore, the diverse nature of fabric textures also poses challenges for structural methods. Summary of the Invention

[0004] In order to overcome the above-mentioned shortcomings of the prior art, the present invention provides a method and system for detecting textile defects based on machine vision.

[0005] To achieve the above objectives, the present invention adopts the following technical solution: a method for detecting textile defects based on machine vision, comprising the following steps:

[0006] Preprocessing the collected textile surface image to obtain a textile grayscale image;

[0007] Perform sliding window processing on the textile grayscale image, calculate the contrast of each pixel based on the grayscale co-occurrence matrix constructed by each sliding window, and obtain a contrast map;

[0008] The smoothness of each pixel is calculated by the contrast value between each pixel and its neighboring pixels;

[0009] When the smoothness of the neighboring pixels of a pixel is not all less than or equal to the smoothness threshold, the contrast of the pixel remains unchanged; when the smoothness of the neighboring pixels of a pixel is all less than or equal to the smoothness threshold, the maximum contrast of the pixel and its neighboring pixels is used as the contrast of the pixel, and the contrast of all pixels is reconstructed to obtain a reconstructed contrast map;

[0010] The reconstructed contrast image is segmented using the watershed algorithm to obtain the defect edge;

[0011] The defect area is obtained through the defect edge, and the textile defects are evaluated based on the defect area.

[0012] Furthermore, in the method for detecting textile defects based on machine vision, the method for calculating the contrast of each pixel point is: calculating the contrast of the sliding window image based on the grayscale co-occurrence matrix constructed each time the sliding window is performed, and the contrast value of the sliding window image is used as the contrast of the central pixel point of the sliding window.

[0013] Furthermore, in the textile defect detection method based on machine vision, the contrast of the sliding window image is expressed as:

[0014]

[0015] Where: represents the contrast of the sliding window image, Indicates the first The gray value of a pixel, Indicates the first The gray value of a pixel, Represents the probability of a pixel pair appearing.

[0016] Furthermore, the method for detecting textile defects based on machine vision, in which the smoothness of each pixel is calculated by the contrast value between each pixel and its neighboring pixel points, is as follows: the smoothness of the corresponding window is calculated by the contrast value between each pixel and its neighboring pixel points, and the smoothness of the window is used as the smoothness of the pixel point.

[0017] Furthermore, in the textile defect detection method based on machine vision, the expression of the window smoothness is:

[0018]

[0019] Where: G represents the window smoothness, K represents the number of pixels in the window, represents the contrast of the k-th pixel in the window, k represents the k-th pixel in the window, represents a hyperparameter.

[0020] Furthermore, the method for detecting textile defects based on machine vision, wherein the method for evaluating textile defects according to the defect area is as follows: calculating the degree of influence of the defect on the textile according to the defect area, and judging whether the textile is qualified according to the magnitude of the influence degree value;

[0021] The expression for the influence degree of the defect on the textile is:

[0022]

[0023] Where: Indicates the degree of influence of defects on textiles, S indicates the number of defective areas, represents the defect length, L represents the side length of the cloth, X represents the distance between the center point of the defect area and the center point of the textile, and s represents the sth defect area.

[0024] Furthermore, in the method for detecting textile defects based on machine vision, the preprocessing includes: performing semantic segmentation on the textile surface image to obtain a 0-1 mask image, obtaining a segmented textile image through the 0-1 mask image and the textile surface image, and performing grayscale processing on the segmented textile image to obtain a textile grayscale image.

[0025] A textile defect detection system based on machine vision, comprising:

[0026] An image acquisition unit for acquiring images of the textile surface;

[0027] An image processing unit pre-processes the textile surface image acquired by the image acquisition unit to obtain a textile grayscale image; performs sliding window processing on the textile grayscale image, calculates the contrast of each pixel point based on the grayscale co-occurrence matrix constructed by each sliding window, and obtains a contrast map;

[0028] an image reconstruction unit that calculates the smoothness of each pixel point using the contrast values ​​of each pixel point and its neighboring pixel points obtained by the image processing unit; when the smoothness values ​​of the neighboring pixel points of the pixel point are not all less than or equal to the smoothness threshold, the contrast of the pixel point remains unchanged; and when the smoothness values ​​of the neighboring pixel points of the pixel point are all less than or equal to the smoothness threshold, the maximum contrast value among the pixel point and its neighboring pixel points is used as the contrast value of the pixel point, thereby reconstructing the contrast values ​​of all pixels to obtain a reconstructed contrast map;

[0029] The image judgment unit segments the reconstructed contrast image obtained by the image reconstruction unit through a watershed algorithm to obtain defect edges; obtains defect areas through the defect edges, and evaluates textile defects based on the defect areas.

[0030] The beneficial effects of the present invention are: the present invention effectively reduces labor intensity, improves production efficiency, and plays an important role in improving product qualification rate; the present invention solves the problems of over-segmentation and boundary fragmentation caused by traditional grayscale watershed segmentation by constructing a contrast watershed segmentation method, thereby improving the detection effect and providing a basis for subsequent classification. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. 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 any creative work.

[0032] Figure 1 The figure is a flow chart of an embodiment of a method for detecting textile defects based on machine vision according to the present invention.

[0033] Figure 2 The figure is a structural schematic diagram of an embodiment of a textile defect detection system based on machine vision of the present invention. Implementation Method

[0034] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention. Example 1

[0035] An embodiment of a method for detecting textile defects based on machine vision of the present invention is as follows: Figure 1 Shown, including:

[0036] The specific scenario targeted by the present invention is: after the yarn is woven into a textile, the surface image of the textile is collected.

[0037] Preprocessing the collected textile surface image to obtain a textile grayscale image;

[0038] Arrange cameras to capture images of textile surfaces, and use DNN semantic segmentation to identify targets in the segmented images.

[0039] The relevant content of the DNN network is as follows:

[0040] The dataset used is a product image dataset collected from a bird's-eye view, and the product styles are diverse.

[0041] The pixels that need to be segmented are divided into two categories, that is, the labeling process of the training set is: single-channel semantic label, the corresponding position pixel belongs to the background class and is labeled as 0, and belongs to the product class and is labeled as 1.

[0042] The task of the network is classification, and all loss functions used are cross entropy loss functions.

[0043] The 0-1 mask image obtained through semantic segmentation is multiplied by the original image. The resulting image contains only the product image and removes background interference. The obtained image is converted into a grayscale image.

[0044] At this point, by setting up a camera to collect images, the DNN network classification is used to obtain the product surface image, and the image is converted into a grayscale image of the product surface.

[0045] Perform sliding window processing on the textile grayscale image, calculate the contrast of each pixel based on the grayscale co-occurrence matrix constructed by each sliding window, and obtain a contrast map;

[0046] Thread missing and broken defects are sparse textures appearing in certain areas of a regular textile image. This is primarily due to thread missing, abnormal pressure, or thread breakage during the weaving process. Because the structure of these defects differs from that of the background, the contrast between the defective area and the background is low, and the edges of the defects exhibit a gradual grayscale change. Generally, considering that the contrast of pixels within each region is relatively close, while the contrast between pixels in adjacent regions is relatively large, a contrast map of an image can be calculated first, and then the watershed of the contrast map can be found. In the contrast map, pixels with small contrast values ​​correspond to the interior of the region, while pixels with large contrast values ​​correspond to the boundaries of the region. The watershed algorithm searches for the location of pixels with large contrast values, that is, the location of the segmentation boundary.

[0047] In this embodiment, in order to perform relatively accurate quality sorting of textiles, it is necessary to first calculate relatively accurate thread defect areas and classify products according to the severity of thread defect. The specific process is as follows:

[0048] Construct the gray-level co-occurrence matrix: obtain an n×n window on the original gray-level image, calculate the gray-level co-occurrence matrix of the sliding window image, and calculate its contrast through the gray-level co-occurrence matrix, that is:

[0049]

[0050] Where: represents the contrast of the sliding window image, Indicates the first The gray value of a pixel, Indicates the first The gray value of a pixel, Represents the probability of a pixel pair appearing.

[0051] Contrast measures the distribution of matrix values ​​and the amount of local variation within an image, reflecting image clarity and the depth of texture grooves. A higher contrast value indicates deeper texture grooves, greater contrast, and a clearer effect. Conversely, a lower contrast value indicates shallower grooves and a blurred effect.

[0052] Since the sliding window operation will make it impossible to calculate the edge pixels of the image, which may lead to judgment deviation, the original image is multiplied by 2 dimensions. The method is as follows: the original image size is M×N, the sliding window size is n×n, and the image size after dimensionality increase becomes ,The dimension increase element is the gray value of the edge pixel of the original image, and the gray value of the four corner pixel points of the ,image after dimension increase is filled with the gray value of the four corner pixel points of the original image.

[0053] For example, if the original image size is 16×18 and the sliding window size is 3×3, the image size becomes 18×20 after dimensionality increase, and the elements at the increased dimension are the grayscale values ​​of the edge pixels of the original 16×18 image.

[0054] The contrast value calculated in the sliding window is assigned to the center of the sliding window, completing the contrast calculation for the first sliding window (the first pixel) in the original image. The sliding window is then shifted one pixel to form another small window image, and the new gray-level co-occurrence matrix and contrast are calculated again. The contrast of all pixels in the original image is calculated by traversing the increased-dimensional image, thus converting the original image into a contrast map.

[0055] The smoothness of each pixel is calculated by the contrast value between each pixel and its neighboring pixels;

[0056] The idea behind the watershed algorithm is to start from a regional minimum and flood the entire terrain from low to high. When water in different basins is about to converge, a dam (composed of single pixels) is constructed. This process continues until the water level reaches its maximum, corresponding to the maximum grayscale level in the image. However, for segmenting broken or missing threads in textiles, segmentation based on grayscale gradients can result in fragmented boundaries of missing threads, leading to biased judgment and significant oversegmentation. Compared to the texture edges of the background, the texture edges of the defective region should correspond to a larger scale. Therefore, this embodiment first obtains a contrast map and performs a watershed operation in the contrast space. Furthermore, due to the influence of gradient noise, quantization error, and the fine texture within the object, flat regions may produce numerous internal "valleys" and "peaks." After the watershed transformation, these small regions form small areas, which can easily lead to oversegmentation, where the desired correct contour is overwhelmed by a large number of irrelevant contours. Therefore, this embodiment suppresses oversegmentation by removing pseudo local minima. The specific operation is as follows:

[0057] Since pixels with low contrast correspond to the interior of the region, and pixels with high contrast correspond to the boundary of the region, the smoothness of the pixel and its neighboring pixels is calculated. That is, taking the pth pixel as the center point, the smoothness of the window where it and its neighboring pixels are located is calculated, that is:

[0058]

[0059] Where: G represents smoothness, K represents the number of pixels in the window, represents the contrast of the k-th pixel in the window, k represents the k-th pixel in the window, represents a hyperparameter.

[0060] The smaller the value of smoothness G, the smaller the contrast difference of pixels in the window, that is, the local peaks and valleys are more likely to be influencing points.

[0061] Assign the smoothness of the window with the pth pixel as the center point to the center pixel point. Through this operation method, the smoothness of each pixel point can be obtained.

[0062] When the smoothness of the neighboring pixels of a pixel is not all less than or equal to the smoothness threshold, the contrast of the pixel remains unchanged; when the smoothness of the neighboring pixels of a pixel is all less than or equal to the smoothness threshold, the maximum contrast of the pixel and its neighboring pixels is used as the contrast of the pixel, and the contrast of all pixels is reconstructed to obtain a reconstructed contrast map;

[0063] The empirical value of smoothness G is 0.3. When the smoothness of all pixels in the neighborhood window with the pth pixel as the center point is less than or equal to 0.3, the value of the center pixel is modified and the maximum contrast value in the neighborhood window is assigned to the center pixel. If the contrast value of the center pixel is the largest, it will not be processed.

[0064] For example, suppose the smoothness of the neighboring pixels of the p-th pixel is , , , , , , , , the contrast of the p-th pixel is , and the contrasts of its neighborhood pixels are , , , , , , ,like , then the contrast of the p-th pixel is Remain unchanged; if , , , , , , , , then let the contrast of p pixels be .

[0065] The entire contrast image is iterated to remove pixels with local minimum values. The reconstructed contrast image eliminates the interference of local minimum values. That is, if there is a defect, the contrast of the pixels inside the defect is reconstructed with higher similarity, while the contrast of the defect edge is larger and is retained.

[0066] The reconstructed contrast image is segmented using the watershed algorithm to obtain the defect edge;

[0067] The conventional watershed algorithm starts from the local minimum, which will lead to over-segmentation. After reconstruction, the contrast watershed method can effectively avoid over-segmentation and retain the desired segmentation edges.

[0068] The reconstructed contrast image is segmented by watershed to obtain the defect edges of the textile.

[0069] At this point, by constructing the contrast map, performing watershed segmentation in the contrast space, and reconstructing the minimum point in the contrast image, the optimal segmentation starting point is obtained to complete the defect segmentation.

[0070] The defect area is obtained through the defect edge, and the textile defects are evaluated based on the defect area.

[0071] The defect area of ​​the textile is obtained through the defect edge of the textile.

[0072] For broken thread defects, the length and number of broken thread defects have different effects on textile quality. The longer the defect length and the greater the number of defects, the worse the textile quality. Therefore, the degree of influence of the defect on the textile quality is calculated, that is:

[0073]

[0074] Where: Indicates the degree of impact, S indicates the number of defective areas, represents the defect length, L represents the side length of the cloth, X represents the distance between the center point of the defect area and the center point of the textile, and s represents the sth defect area.

[0075] The longer the defects are, the greater their number is, and the closer the center of the defects is to the center of the textile, the worse the quality of the fabric is.

[0076] Implementers can set the corresponding quality level according to their own needs. The size of the textiles is used to divide the quality into different grades, namely first-class, second-class, third-class and unqualified products.

[0077] The present invention effectively reduces labor intensity, improves production efficiency, and plays an important role in improving product qualification rate; the present invention solves the problems of over-segmentation and boundary fragmentation caused by traditional grayscale watershed segmentation by constructing a contrast watershed segmentation method, thereby improving the detection effect and providing a basis for subsequent classification. Example 2

[0078] An embodiment of a textile defect detection system based on machine vision of the present invention is as follows: Figure 2 Shown, including:

[0079] An image acquisition unit for acquiring images of the textile surface;

[0080] The camera is placed in front of the textile so that the camera is facing the textile, and then the surface image of the textile is collected.

[0081] An image processing unit pre-processes the textile surface image acquired by the image acquisition unit to obtain a textile grayscale image; performs sliding window processing on the textile grayscale image, calculates the contrast of each pixel point based on the grayscale co-occurrence matrix constructed by each sliding window, and obtains a contrast map;

[0082] The collected textile surface image is semantically segmented to obtain a 0-1 mask image. The 0-1 mask image and the textile surface image are combined to obtain a segmented textile image. The segmented textile image is then grayscaled to obtain a textile grayscale image. A sliding window process is performed on the textile grayscale image. The contrast of the sliding window image is calculated based on the grayscale co-occurrence matrix constructed with each window slide. Each window slide generates a grayscale co-occurrence matrix, which corresponds to the contrast of a sliding window image. The contrast value of the sliding window image is used as the contrast of the central pixel of the sliding window. In other words, the contrast of the central pixel of the sliding window can be calculated with a single window slide. This method can determine the contrast of each pixel, thereby generating a contrast map.

[0083] an image reconstruction unit that calculates the smoothness of a corresponding window using the contrast values ​​of each pixel point and its neighboring pixel points obtained by the image processing unit, and uses the window smoothness as the smoothness of the pixel point; when the smoothness of the neighboring pixel points of the pixel point is not all less than or equal to the smoothness threshold, the contrast of the pixel point remains unchanged; when the smoothness of the neighboring pixel points of the pixel point is all less than or equal to the smoothness threshold, uses the maximum contrast of the pixel point and its neighboring pixel points as the contrast of the pixel point, and reconstructs the contrast of all pixels in this way to obtain a reconstructed contrast map;

[0084] The image judgment unit segments the reconstructed contrast image obtained by the image reconstruction unit through a watershed algorithm to obtain defect edges; obtains defect areas through the defect edges, and evaluates textile defects based on the defect areas.

[0085] The reconstructed contrast image is segmented using the watershed algorithm to obtain the defect edges of each defect. The defect areas are determined by the defect edges, and the degree of impact of the defect on the textile is calculated based on the defect area. Based on the size of the impact value and the textile grade threshold, it is determined whether the textile is first-class, second-class, third-class or unqualified.

[0086] The present invention effectively reduces labor intensity, improves production efficiency, and plays an important role in improving product qualification rate; the present invention solves the problems of over-segmentation and boundary fragmentation caused by traditional grayscale watershed segmentation by constructing a contrast watershed segmentation method, thereby improving the detection effect and providing a basis for subsequent classification.

[0087] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A method for detecting textile defects based on machine vision, characterized in that: include: Preprocessing the collected textile surface image to obtain a textile grayscale image; Perform sliding window processing on the textile grayscale image, calculate the contrast of each pixel based on the grayscale co-occurrence matrix constructed by each sliding window, and obtain a contrast map; The smoothness of each pixel is calculated by the contrast value between each pixel and its neighboring pixels; When the smoothness of the neighboring pixels of a pixel is not all less than or equal to the smoothness threshold, the contrast of the pixel remains unchanged; when the smoothness of the neighboring pixels of a pixel is all less than or equal to the smoothness threshold, the maximum contrast of the pixel and its neighboring pixels is used as the contrast of the pixel, and the contrast of all pixels is reconstructed to obtain a reconstructed contrast map; The reconstructed contrast image is segmented using the watershed algorithm to obtain the defect edge; The defect area is obtained through the defect edge, and the textile defects are evaluated based on the defect area.

2. The method for detecting textile defects based on machine vision according to claim 1, characterized in that: The method for calculating the contrast of each pixel is as follows: the contrast of the sliding window image is calculated based on the gray level co-occurrence matrix constructed each time the sliding window is opened, and the contrast value of the sliding window image is used as the contrast of the central pixel of the sliding window.

3. The method for detecting textile defects based on machine vision according to claim 2, characterized in that: The contrast of the sliding window image is expressed as: Where: represents the contrast of the sliding window image, Indicates the first The gray value of a pixel, Indicates the first The gray value of a pixel, Represents the probability of a pixel pair appearing.

4. The method for detecting textile defects based on machine vision according to claim 1, characterized in that: The method for calculating the smoothness of each pixel point by the contrast value between each pixel point and its neighboring pixel points is as follows: the smoothness of the corresponding window is calculated by the contrast value between each pixel point and its neighboring pixel points, and the smoothness of the window is used as the smoothness of the pixel point.

5. The method for detecting textile defects based on machine vision according to claim 4, characterized in that: The expression of the window smoothness is: Where: G represents the window smoothness, K represents the number of pixels in the window, represents the contrast of the k-th pixel in the window, k represents the k-th pixel in the window, represents a hyperparameter.

6. The method for detecting textile defects based on machine vision according to claim 1, characterized in that: The method of evaluating textile defects based on defect areas is as follows: calculating the degree of influence of the defect on the textile through the defect area, and judging whether the textile is qualified based on the value of the influence degree; The expression for the influence degree of the defect on the textile is: Where: Indicates the degree of impact of defects on textiles, Indicates the number of defective areas, Indicates the defect length, represents the side length of the cloth, X represents the distance between the center point of the defect area and the center point of the textile, Indicates the defective areas.

7. The method for detecting textile defects based on machine vision according to claim 1, characterized in that: The preprocessing includes: performing semantic segmentation on the textile surface image to obtain a 0-1 mask image, obtaining a segmented textile image through the 0-1 mask image and the textile surface image, and performing grayscale processing on the segmented textile image to obtain a textile grayscale image.

8. A textile defect detection system based on machine vision, characterized in that: include: An image acquisition unit for acquiring images of the textile surface; An image processing unit, which preprocesses the textile surface image acquired by the image acquisition unit to obtain a textile grayscale image; Perform sliding window processing on the textile grayscale image, calculate the contrast of each pixel based on the grayscale co-occurrence matrix constructed by each sliding window, and obtain a contrast map; An image reconstruction unit calculates the smoothness of each pixel point using the contrast value between each pixel point and its neighboring pixel points obtained by the image processing unit; When the smoothness of the neighboring pixels of a pixel is not all less than or equal to the smoothness threshold, the contrast of the pixel remains unchanged; when the smoothness of the neighboring pixels of a pixel is all less than or equal to the smoothness threshold, the maximum contrast of the pixel and its neighboring pixels is used as the contrast of the pixel, and the contrast of all pixels is reconstructed to obtain a reconstructed contrast map; The image judgment unit segments the reconstructed contrast image obtained by the image reconstruction unit through a watershed algorithm to obtain the defect edge; The defect area is obtained through the defect edge, and the textile defects are evaluated based on the defect area.