Textile defect intelligent classification and traceability method based on machine vision
By using a machine vision-based intelligent classification and traceability method for textile defects, the problem of low efficiency in manual inspection has been solved, and automated and accurate detection of textile defects and process traceability have been achieved, thereby improving detection efficiency and model training effect.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHENZHEN VISDUAL FASHIONS
- Filing Date
- 2025-12-31
- Publication Date
- 2026-04-21
AI Technical Summary
Current methods for detecting defects in textiles mainly rely on manual vision, which is inefficient and has a success rate of only 60%-75%, failing to meet the needs of high-quality development in the textile industry.
A machine vision-based intelligent classification and traceability method for textile defects is adopted. The defect area is determined by the edge detection model, the repair model generates an ideal image without defects, the sub-regions are divided based on attention weights, and the defect classification model is used for accurate classification and process traceability.
It enables automated detection of textile defects, improves detection accuracy and model training efficiency, reduces waste of computing resources, and avoids reliance on manual inspection.
Smart Images

Figure CN121903992A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of textile defect identification technology, specifically to a machine vision-based intelligent classification and traceability method for textile defects. Background Technology
[0002] With the incorporation of various new fabric models and attractive patterns into textiles, the textile industry is facing significant quality challenges. Defect detection is a crucial element in promoting the high-quality development of the textile industry. However, current quality inspection processes still primarily rely on human vision. Due to physiological and psychological limitations such as eye fatigue and slow visual scanning speed, manual inspection is inefficient; even highly trained workers achieve a success rate of only 60%. 75%. As the requirements for high-quality development in the textile industry continue to increase, automated textile defect detection technology is indispensable.
[0003] The information disclosed in the background section is only intended to enhance the understanding of the background of this disclosure, and therefore may include information that does not constitute prior art known to those skilled in the art. Summary of the Invention
[0004] The purpose of this invention is to provide a machine vision-based intelligent classification and traceability method for textile defects, in order to solve the problems mentioned in the background art.
[0005] To achieve the above objectives, the present invention provides the following technical solution: A machine vision-based intelligent classification and traceability method for textile defects includes the following steps: S1. Analyze the grayscale image of the textile to be identified based on the edge detection model to determine the defect area, and based on the defect area, cut out the image of the area to be repaired, including the target area and the reference area, and its binary mask image from the color image of the textile to be identified. S2, based on the repair model, analyze the image of the region to be repaired and its binary mask image to obtain the repaired region image, and compare and analyze it with the image of the region to be repaired to determine the attention weight of each pixel in the target region of the image of the region to be repaired; S3, extract the target region image from the image to be repaired, and divide the target region image into several sub-region images based on the attention weight, including high attention sub-region images, medium attention sub-region images and low attention sub-region images; S4 analyzes the images of each sub-region based on the defect classification model to output the defect type of the target region image, and performs process tracing based on the defect type. The defect classification model includes three convolution branches with successively decreasing convolution depths, which are used to process high-interest sub-region images, medium-interest sub-region images, and low-interest sub-region images, respectively.
[0006] Furthermore, the edge detection model is constructed based on a convolutional neural network, which includes an input layer for receiving a grayscale image, one or more convolutional layers for performing convolution operations to extract image features, a pooling layer connected after the convolutional layers and performing pooling operations, and an output layer for outputting a binarized image, which includes defective and non-defective regions.
[0007] Furthermore, the logic for cropping the image of the area to be repaired is as follows: For each defect area, the outer contour of the defect area is extracted, and a high scaling factor and a low scaling factor are preset. Both the high scaling factor and the low scaling factor are greater than 1, and the high scaling factor is greater than the low scaling factor. The outer contour of the defect area is scaled with the geometric center of the outer contour of the defect area as the origin and the high scaling factor as the scaling ratio to obtain the first extended outer contour of the defect area. Similarly, the outer contour of the defect area is scaled with the geometric center of the outer contour of the defect area as the origin and the low scaling factor as the scaling ratio to obtain the second extended outer contour of the defect area. The smallest bounding rectangle of the first extended outer contour is projected onto the color image of the textile to be identified. The image area within the smallest bounding rectangle of the first extended outer contour in the color image is selected and cropped to serve as the repair area image of the defect area. The smallest bounding rectangle of the second extended outer contour is projected onto the repair area image. The image area within the smallest bounding rectangle of the second extended outer contour in the repair area image is selected to serve as the target area. The area in the repair area image that does not belong to the target area is used as the reference area. The logic for constructing a binary mask image of the region to be repaired is as follows: copy the region to be repaired image to obtain a copy of the region to be repaired image, convert the copy of the region to be repaired image to grayscale, replace the grayscale values of the pixels in the target region with 0, and replace the grayscale values of the pixels in the reference region with 255, so as to obtain a binary mask image used to identify the target region and the reference region.
[0008] Furthermore, the repair model is based on generative adversarial networks, which includes a generator based on convolutional neural networks and a discriminator based on deep convolutional networks. The repair model is used to analyze and process the image of the region to be repaired and its binary mask image to output the repaired region image after the target region has been repaired. The generator includes an input layer for receiving the image of the region to be repaired and its binary mask image, and fusing the two into a stitched image based on channel stitching; an encoder for downsampling the stitched image to extract image features; a bottleneck layer for extracting features from the output of the encoder; a decoder for upsampling the output of the bottleneck layer to restore the image size; and an output layer for outputting the repaired region image. The discriminator includes an input layer for receiving the generator output, one or more convolutional layers for performing convolution operations to extract image features, pooling layers connected after the convolutional layers to perform pooling operations, and a fully connected layer for outputting the true probability.
[0009] Furthermore, the logic for determining the attention weights is as follows: for any pixel in the target area of the image to be repaired, its RGB value is extracted, and the RGB value of the corresponding pixel in the repaired image is extracted. The degree of difference between the two is used as the attention index of the pixel. The degree of difference is specifically represented by Euclidean distance, Manhattan distance or squared difference. The attention indices of all pixels in the target area of the image to be repaired are normalized to obtain the attention weight of each pixel in the target area of the image to be repaired.
[0010] Furthermore, the logic for dividing the image into sub-regions is as follows: a high attention threshold and a low attention threshold are preset, and attention weights are combined to determine the attention category of each pixel in the target region image, which includes high attention pixels, medium attention pixels and low attention pixels, and the high attention threshold is greater than the low attention threshold. Set the state of each pixel in the target region image to unvisited. Randomly select an unvisited pixel as the seed of the sub-region. Iterate through all unvisited pixels adjacent to the seed. If the interest category of a pixel is the same as that of the seed, include the pixel in the sub-region of the seed to update the sub-region. Iterate through all unvisited pixels adjacent to the newly included sub-region to include new pixels in the sub-region of the seed. Iterate through the sub-region in this way until the sub-region of the seed no longer includes new pixels to determine a final sub-region. Update the state of each pixel in the final sub-region to visited. Randomly select a pixel from the unvisited pixels as the new seed. Repeat the iteration until the state of all pixels is updated to visited to divide the target region image into several sub-regions. The specific logic for determining the type of any sub-region is as follows: if the pixels in the sub-region are high-interest pixels, then the sub-region is designated as a high-interest sub-region; if the pixels in the sub-region are medium-interest pixels, then the sub-region is designated as a medium-interest sub-region; if the pixels in the sub-region are low-interest pixels, then the sub-region is designated as a low-interest sub-region.
[0011] Furthermore, the specific method for determining the attention category is as follows: if the attention weight of a pixel in the target region image is not less than the high attention threshold, then the pixel is classified as a high attention pixel; if the attention weight of a pixel in the target region image is not greater than the low attention threshold, then the pixel is classified as a low attention pixel; if the attention weight of a pixel in the target region image is between the high attention threshold and the low attention threshold, then the pixel is classified as a medium attention pixel.
[0012] Furthermore, for each sub-region, the ratio of the number of pixels in the sub-region to the number of pixels in the target region is calculated as the pixel proportion of the sub-region. A preset proportion threshold is set, and the sub-region with the smallest pixel proportion is selected as the target sub-region. It is then determined whether its pixel proportion is greater than the proportion threshold. If it is, no merging operation is performed on it. If it is not, the sub-regions adjacent to the target sub-region are selected as sub-regions to be merged. The target sub-region is then merged with the sub-region to be merged with the smallest pixel proportion. The type of the merged sub-region is set to the type of the sub-region with higher attention among the two sub-regions before merging, so as to update the sub-region distribution in the target region image. From the updated sub-region distribution, the sub-region with the smallest pixel proportion is selected again as the target sub-region. The above judgment, merging and update operations are repeated until the pixel proportion of the target sub-region is greater than the proportion threshold, thereby determining the final sub-region distribution in the target region image.
[0013] Furthermore, the defect classification model is built based on a convolutional neural network, and its architecture is as follows: The input layer is used to receive images of each sub-region. The first convolutional branch is used to extract deep features from the high-interest sub-region image; The second convolutional branch is used to extract moderate features from the image of the region of interest. The third convolutional branch is used to perform shallow feature extraction on the low-interest sub-region image; The feature merging layer is used to flatten the outputs of the three convolutional branches and concatenate them together to form a merged feature vector; The fully connected layer uses the ReLU activation function to process and merge feature vectors in order to capture the complex relationships between features; The output layer, with the same number of neurons as the number of defect types, uses the Softmax activation function to process the output of the fully connected layer in order to determine the defect types in the target region image.
[0014] Furthermore, the defect types include stains, color differences, wrinkles, fuzzing, damage, and uneven yarn. The logic for process tracing based on defect types is as follows: For the stain type of defect, the source can be traced back to the dyeing, printing and post-treatment processes; For the defect type of color difference, the source is traced back to the dyeing process; For the defect type of wrinkles, the source can be traced back to the sewing, packaging and post-processing procedures; For the defect type of pilling, the source can be traced back to the weaving and finishing processes; For the defect type of breakage, the source can be traced back to the weaving, cutting and sewing processes; For the defect type of uneven yarn, the source can be traced back to the yarn production and weaving process.
[0015] Compared with the prior art, the beneficial effects of the present invention are: The present invention provides a machine vision-based intelligent classification and traceability method for textile defects. First, a repair model is used to repair the target area containing the defect, generating an ideal image of the target area without defects. Then, a difference analysis is performed between this image and the real image of the target area to determine the attention weight of each pixel within the target area. The target area image is then divided into multiple sub-region images with different levels of attention. Finally, based on the defect classification model, features are extracted from each sub-region image with different convolution depths to focus on the pixels at the defect location. This ensures the accuracy of defect classification based on machine vision, achieving automated detection of textile defects without relying on manual inspection. Furthermore, the differential feature extraction setting significantly improves model training efficiency compared to global deep feature extraction of the target area, greatly reducing unnecessary computational resource waste. Attached Figure Description
[0016] Figure 1 This is a schematic flowchart of the overall method of the present invention; Figure 2 This is a comparison chart of the recognition accuracy of this scheme and the control model. Detailed Implementation
[0017] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to specific embodiments.
[0018] It should be noted that, unless otherwise defined, the technical or scientific terms used in this invention should have the ordinary meaning understood by one of ordinary skill in the art to which this invention pertains. The terms "first," "second," and similar terms used in this invention do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Terms such as "comprising" or "including" mean that the element or object preceding the word encompasses the elements or objects listed following the word and their equivalents, without excluding other elements or objects. Terms such as "connected" or "linked" are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. Terms such as "upper," "lower," "left," and "right" are used only to indicate relative positional relationships; when the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0019] Example: Please see Figures 1-2 This invention provides a machine vision-based intelligent classification and traceability method for textile defects, comprising the following steps: S1. Analyze the grayscale image of the textile to be identified based on the edge detection model to determine the defect area, and based on the defect area, cut out the image of the area to be repaired, including the target area and the reference area, and its binary mask image from the color image of the textile to be identified. It should be noted that the color image of the textile to be identified can be obtained through an industrial camera. When the textile to be identified moves to the working area of the industrial camera, the camera takes a picture of the textile to obtain the corresponding color image. The specific installation and working process of the industrial camera will not be described in detail here. The grayscale image is obtained by converting the color image to grayscale, and the specific mathematical expression is as follows: In the formula, pixels in a grayscale image grayscale value, The coordinates of the pixel. , , Each pixel The brightness values of the red, green, and blue channels in a color image are used in grayscale images, which are converted from color images. The pixels in the two correspond one-to-one. This is existing technology and will not be elaborated here. The edge detection model is built on a convolutional neural network, which includes an input layer for receiving grayscale images, one or more convolutional layers for performing convolution operations to extract image features, a pooling layer connected after the convolutional layers and performing pooling operations, and an output layer for outputting a binary image, which includes defective and non-defective regions. As an example, convolutional layers are typically set between 5 and 10 layers, with each convolutional layer followed by a pooling layer. The convolutional layers use the ReLU activation function, and the pooling operation of the pooling layers is max pooling, specifically performing max pooling on the output of the convolutional layers they are connected to, in order to simplify the output of the convolutional layers and retain important features. The first convolutional layer is used to perform convolution operations on the grayscale image of the input layer, and the other convolutional layers are used to perform convolution operations on the output of the pooling layer connected to the previous convolutional layer. The output layer is used to process the output of the pooling layer connected to the last convolutional layer using the Sigmoid activation function to generate a binarized image corresponding to the grayscale image. The process of training the edge detection model is as follows: A large number of textiles with known defect areas are acquired and their grayscale images are collected. The grayscale images are copied to generate a grayscale image copy. The positions of the defect areas on the grayscale image copy are located. The grayscale values of the pixels at the positions of the defect areas in the grayscale image copy are assigned to 0, and the grayscale values of the pixels at other positions are assigned to 255. The grayscale image copy is then converted into a binary image corresponding to the grayscale image. In the binary image, defect areas and non-defect areas are distinguished. Defect areas are areas composed of pixels with a grayscale value of 0, and non-defect areas are areas composed of pixels with a grayscale value of 255. All grayscale images and their corresponding binary images are collected to construct a first sample set. The first sample set is randomly divided into a training set, a validation set, and a test set in a ratio of 70:15:15. The edge detection model is trained by using grayscale images from the training set as input and corresponding binarized images as output labels. During training, cross-entropy loss is used as the loss function, and the model parameters of the edge detection model are updated using Adam or SGD optimizers to minimize the loss function. After each training round, the edge detection model is evaluated on the validation set to adjust model hyperparameters such as learning rate and batch size in a timely manner. Training stops after a predetermined number of training rounds, and the edge detection model is tested on the test set. Specifically, accuracy, recall, F1 score, etc. can be used as test metrics. The edge detection model is considered to have completed training after the test metrics are met; otherwise, the model parameters are adjusted and training is repeated until the test metrics are met. During the model training process described above, the learning rate is generally set between 0.00001 and 0.001, the number of iterations is generally set between 30 and 100, the batch size is generally set between 32 and 256, and the regularization coefficient is generally set between 0.00001 and 0.0001. The specific criteria for determining whether the test metrics meet the standards can be set by the staff according to the actual situation. For example, when the accuracy and recall reach 85% or higher and the F1 score reaches 0.85 or higher, it can be considered as meeting the standards. These are conventional technical means used by those skilled in the art in the model training process, and will not be elaborated here. The logic for determining the defect area of the textile to be identified is as follows: input the grayscale image of the textile to be identified into the edge detection model after training to obtain its binarized image, and determine the defect area of the textile to be identified based on the binarized image. The logic for cropping the image of the area to be repaired is as follows: For each defect area, the outer contour of the defect area is extracted, and a high scaling factor and a low scaling factor are preset. Both the high scaling factor and the low scaling factor are greater than 1, and the high scaling factor is greater than the low scaling factor. The outer contour of the defect area is scaled with the geometric center of the outer contour of the defect area as the origin and the high scaling factor as the scaling ratio to obtain the first extended outer contour of the defect area. Similarly, the outer contour of the defect area is scaled with the geometric center of the outer contour of the defect area as the origin and the low scaling factor as the scaling ratio to obtain the second extended outer contour of the defect area. The smallest bounding rectangle of the first extended outer contour is projected onto the color image of the textile to be identified. The image area within the smallest bounding rectangle of the first extended outer contour in the color image is selected and cropped to serve as the repair area image of the defect area. The smallest bounding rectangle of the second extended outer contour is projected onto the repair area image. The image area within the smallest bounding rectangle of the second extended outer contour in the repair area image is selected to serve as the target area. The area in the repair area image that does not belong to the target area is used as the reference area. The logic for constructing the binary mask image of the region to be repaired is as follows: copy the region to be repaired to obtain a copy of the region to be repaired image; after converting the copy of the region to be repaired image to grayscale, uniformly replace the grayscale values of the pixels in the target region with 0, and uniformly replace the grayscale values of the pixels in the reference region with 255, so as to obtain a binary mask image used to identify the target region and the reference region. The setting of the binary mask image is used to guide the repair target when repairing the target region of the region to be repaired in the subsequent process. It should be noted that because the accuracy of edge recognition of defect areas determined solely by edge detection models is not high, a target area code that covers and is slightly larger than the defect area is selected as the subsequent repair area. A reference area located outside the target area is used as a reference for repairing the target area, so as to obtain a normal image of the defect area without defects. The low scaling factor setting is used to slightly expand the outer contour of the defect area to ensure that the target area covered the defect area for subsequent image repair. The low scaling factor value is between 1.1 and 1.5 to ensure complete coverage of the defect area. The specific value can be set by the staff according to the actual situation. The high scaling factor setting is used to significantly expand the outer contour of the defect area to ensure that the obtained reference area contains sufficient image features to guide the subsequent repair of the target area. The specific value of the high scaling factor is between 3 and 5 to ensure that enough reference areas are selected to provide reference for subsequent image repair. The specific value is also set by the staff according to the actual situation.
[0020] S2, based on the repair model, analyze the image of the region to be repaired and its binary mask image to obtain the repaired region image, and compare and analyze it with the image of the region to be repaired to determine the attention weight of each pixel in the target region of the image of the region to be repaired; The repair model is based on generative adversarial networks, which includes a generator based on convolutional neural networks and a discriminator based on deep convolutional networks. The repair model is used to analyze and process the image of the region to be repaired and its binary mask image to output the repaired region image after the target region is repaired. The generator includes an input layer for receiving the image of the region to be repaired and its binary mask image, and fusing the two into a stitched image based on channel stitching; an encoder for downsampling the stitched image to extract image features; a bottleneck layer for extracting features from the output of the encoder; a decoder for upsampling the output of the bottleneck layer to restore the image size; and an output layer for outputting the repaired region image. Furthermore, before stitching together the image of the area to be repaired and its binary mask, the pixels of the target area in the image of the area to be repaired are uniformly replaced with black or white to avoid interference during subsequent image repair. It should be noted that the encoder includes multiple sequentially connected convolutional layers, which use the ReLU activation function to downsample the stitched image multiple times to extract image features. Each convolutional layer may also be followed by a corresponding batch normalization layer or max pooling layer to accelerate training convergence. The bottleneck layer is connected after the last convolutional layer of the encoder and uses a smaller convolutional kernel than the convolutional layers in the encoder, such as a 1×1 convolutional kernel, to extract features from the output of the last convolutional layer of the encoder, reducing the number of channels while extracting high-level features. The decoder includes multiple sequentially connected transposed convolutional layers, and the number of transposed convolutional layers is the same as that of the convolutional layers, such as 5-8 layers, to perform upsampling to restore the image size. The outputs of the convolutional layers and the corresponding transposed convolutional layers are combined through skip connections to preserve detail information. The output layer is a convolutional layer using the Sigmoid activation function, which is used to analyze and process the output of the last transposed convolutional layer of the decoder to output the repaired region image. The discriminator includes an input layer for receiving the generator output, one or more convolutional layers for performing convolution operations to extract image features, a pooling layer connected after the convolutional layers to perform pooling operations, and a fully connected layer for outputting the true probability. It should be noted that the discriminator typically has 4-8 convolutional layers, with each convolutional layer followed by a pooling layer. The convolutional layers use the ReLU activation function, and the pooling operation is max pooling, specifically performing max pooling on the output of the convolutional layers it is connected to, in order to simplify the output of the convolutional layers and retain important features. The first convolutional layer is used to perform convolution operations on the generator output, and the other convolutional layers are used to perform convolution operations on the output of the pooling layer connected to the previous convolutional layer. The fully connected layer is connected after the pooling layer connected to the last convolutional layer and is used to analyze the output of the pooling layer using the Sigmoid activation function to output the true probability of the generator output. The process of training the repair model is as follows: Multiple regions are randomly selected within the defect-free area of a textile color image as sample regions. The outer contour of the sample region is scaled using a high scaling factor as the scaling ratio, with the geometric center of the outer contour as the origin, to obtain the first extended outer contour of the sample region. Similarly, the outer contour of the sample region is scaled using a low scaling factor as the scaling ratio, with the geometric center of the outer contour as the origin, to obtain the second extended outer contour of the sample region. When selecting sample regions, it is ensured that the minimum bounding rectangle of the first extended outer contour is located within the defect-free area. The image region located within the minimum bounding rectangle of the first extended outer contour is cropped from the defect-free area as the repaired sample image of the sample region. The image region located within the minimum bounding rectangle of the second extended outer contour is selected from the inner frame of the repaired sample image as the target region of the repaired sample image. Regions in the repaired sample image that do not belong to the target region are used as reference regions. Copy the repair sample image to obtain repair sample image copy one. Replace the pixels in the target area of repair sample image copy one with black or white to convert repair sample image copy one into a sample image to be repaired. Copy the repair sample image again to obtain repair sample image copy two. After grayscale conversion of repair sample image copy two, replace the grayscale value of the pixels in the target area with 0 and replace the grayscale value of the pixels in the reference area with 255 to obtain a binary mask image used to identify the target area and the reference area. The batch size for each training round is preset, specifically between 32 and 256. In each iteration, the generator and discriminator are trained alternately. Specifically, the generator is trained by first using the image to be repaired and its binary mask as input, and the corresponding repaired image as output. Backpropagation is used to update the generator's parameters so that the generator's output is correctly identified as a real sample by the discriminator. Then, the repaired image output by the generator is assigned a "false" label (represented by "0"), and the corresponding real repaired image is assigned a "real" label. The “1” indicates that the repair sample image output by the generator and the corresponding real repair sample image are taken as inputs, and the label is taken as the output to train the discriminator. The discriminator uses binary cross-entropy loss as the loss function. Similarly, the backpropagation algorithm updates the parameters of the generator to minimize its loss function until the predetermined number of iterations is reached to complete the training of the repair model. The number of iterations can be set between 30 and 60. The learning rate of the generator and the discriminator during the training process is generally set between 0.00001 and 0.001. The specific setting is determined by the staff according to the actual situation and is not limited here. The logic for determining the attention weight is as follows: For any pixel in the target area of the image to be repaired, its RGB value is extracted, and the RGB value of the corresponding pixel is extracted from the image of the repaired area. The degree of difference between the two is used as the attention index of the pixel. The degree of difference is specifically represented by Euclidean distance, Manhattan distance or squared difference. The attention index of all pixels in the target area of the image to be repaired is normalized to obtain the attention weight of each pixel in the target area of the image to be repaired. Taking Euclidean distance as an example, the mathematical expression for the attention index is as follows: In the formula, For the target region of the image to be repaired, the first Attention index per pixel , , The first and second parts of the target area of the image to be repaired are respectively the first and second parts of the target area. The red, green, and blue channel brightness values of each pixel. This refers to the index of the pixels within the target region of the image to be repaired. , , The image within the repaired region and the first The red, green, and blue channel brightness values of the corresponding pixel are used to determine the size and pixel alignment of the repaired and unrepaired regions. The image corresponding to the pixel in the repaired region is then found within the repaired region image. The number of pixels corresponding to each pixel is common knowledge in this field and will not be elaborated upon here. The larger it is, the more likely it is to be the first The greater the difference between the nth pixel and its corresponding pixel, the more likely it is to indicate that the nth pixel is the most likely to be ... The higher the probability that a pixel belongs to a defect area, the greater its attention weight is given so that it will be the focus of the analysis of the image of the area to be repaired in the following text, so as to facilitate accurate defect classification in the future. The attention index is normalized to determine the mathematical expression for the attention weight, as follows: In the formula, For the target region of the image to be repaired, the first The attention weight of each pixel The attention index is normalized to the number of pixels in the target area of the image to be repaired. The resulting attention weight is quantized between 0 and 1 to unify the units of measurement.
[0021] S3, extract the target region image from the image to be repaired, and divide the target region image into several sub-region images based on the attention weight, including high attention sub-region images, medium attention sub-region images and low attention sub-region images; The logic for dividing the image into sub-regions is as follows: Preset high and low attention thresholds, combined with attention weights, determine the attention category of each pixel within the target region image. This category includes high-attention pixels, medium-attention pixels, and low-attention pixels, with the high attention threshold being greater than the low attention threshold. Specifically, if the attention weight of a pixel within the target region image is not less than the high attention threshold, it indicates a higher attention weight, suggesting a greater likelihood that the pixel is a defective pixel. Therefore, the pixel is classified as a high-attention pixel. The threshold for attention indicates that the attention weight of a pixel is low, which means that the pixel is less likely to be a defective pixel. Therefore, the pixel is classified as a low attention pixel. If the attention weight of a pixel in the target area image is between the high attention threshold and the low attention threshold, it means that the attention weight of the pixel is moderate, which means that the pixel is moderately likely to be a defective pixel. Therefore, the pixel is classified as a medium attention pixel. This completes the classification of each pixel in the target area image, providing a basis for the subsequent division of high attention sub-region images, medium attention sub-region images, and low attention sub-region images. The specific values of the high attention threshold and the low attention threshold are set according to the attention weight. Specifically, the attention weights of each pixel in the target area image are arranged in ascending order to form an attention weight sequence. The quarter-threshold value in the attention weight sequence is selected as the low attention threshold, and the third-quarter value in the attention weight sequence is selected as the high attention threshold. The high attention threshold and the low attention threshold are adaptively adjusted according to the attention weight to identify high attention pixels, medium attention pixels, and low attention pixels. Of course, the specific settings of the high attention threshold and the low attention threshold can also be determined by technical personnel based on relevant experience and common sense. Set the state of each pixel in the target region image to unvisited. Randomly select an unvisited pixel as the seed of the sub-region. Iterate through all unvisited pixels adjacent to the seed. If the interest category of a pixel is the same as that of the seed, include the pixel in the sub-region of the seed to update the sub-region. Iterate through all unvisited pixels adjacent to the newly included sub-region to include new pixels in the sub-region of the seed. Iterate through the sub-region in this way until the sub-region of the seed no longer includes new pixels to determine a final sub-region. Update the state of each pixel in the final sub-region to visited. Randomly select a pixel from the unvisited pixels as the new seed. Repeat the iteration until the state of all pixels is updated to visited to divide the target region image into several sub-regions. The specific logic for determining the type of any sub-region is as follows: if the pixels in the sub-region are high-attention pixels, then the sub-region is designated as a high-attention sub-region; if the pixels in the sub-region are medium-attention pixels, then the sub-region is designated as a medium-attention sub-region; if the pixels in the sub-region are low-attention pixels, then the sub-region is designated as a low-attention sub-region. It should be noted that if among all the pixels adjacent to the seed pixel that are in an unvisited state, there is no pixel whose interest category is the same as the seed, then the seed is treated as a separate sub-region. Furthermore, for each sub-region, the ratio of the number of pixels in the sub-region to the number of pixels in the target region is calculated as the pixel proportion of the sub-region. A preset proportion threshold is set, and the sub-region with the smallest pixel proportion is selected as the target sub-region. It is then determined whether its pixel proportion is greater than the proportion threshold. If it is greater, no merging operation is performed on it. If it is not greater, the sub-region adjacent to the target sub-region is selected as the sub-region to be merged. The target sub-region is then merged with the sub-region to be merged with the smallest pixel proportion. The type of the merged sub-region is set to the type of the sub-region with the higher attention among the two sub-regions before merging. If the merged sub-region has the same type as its adjacent sub-region, the two are also merged to update the sub-region distribution in the target region image. From the updated sub-region distribution, the sub-region with the smallest pixel proportion is selected again as the target sub-region. The above judgment, merging and updating operations are repeated until the pixel proportion of the target sub-region is greater than the proportion threshold, thereby determining the final sub-region distribution in the target region image. It should be noted that the above method of generating sub-regions through seed expansion has the problem of a large number of sub-regions and some sub-regions being too small. If feature extraction and splicing operations are directly performed on all sub-regions, it will generate an excessive workload. Therefore, a merging operation is performed on the excessively small sub-regions to reduce the number of sub-regions, improve the training efficiency and convergence of the subsequent model, and reduce the computational workload. The percentage threshold is set to identify excessively small sub-regions, and its value can be set between 5% and 10%, which is determined by the staff according to the actual situation. The attention level of high-attention sub-regions, medium-attention sub-regions, and low-attention sub-regions decreases in that order. The method of setting the type of the merged sub-region as the type of the sub-region with the higher attention level among the two sub-regions before merging ensures the attention level of key regions.
[0022] S4, based on the defect classification model, analyze each sub-region image to output the defect type of the target region image, and perform process traceability based on the defect type. The defect classification model includes three convolution branches with successively decreasing convolution depth, which are used to process high-attention sub-region images, medium-attention sub-region images and low-attention sub-region images respectively. The defect classification model is based on a convolutional neural network, and its architecture is as follows: The input layer is used to receive images of each sub-region. The first convolutional branch is used to extract deep features from the high-interest sub-region image. Specifically, it consists of a first convolutional layer, a second convolutional layer, and a first pooling layer connected in sequence. The first convolutional layer uses 64 3×3 convolutional kernels to perform feature extraction on the high-interest sub-region image, and the second convolutional layer uses 128 3×3 convolutional kernels to perform feature extraction on the output of the first convolutional layer. This achieves deep feature extraction from the high-interest sub-region image, fully capturing the details and complex features of the high-interest sub-region image, and providing strong support for subsequent classification. The first pooling layer uses a 2×2 max pooling layer to perform max pooling on the output of the second convolutional layer, in order to reduce computational complexity while preserving important features. The second convolutional branch is used to perform moderate feature extraction on the center of interest region image. Specifically, it consists of a third convolutional layer, a fourth convolutional layer, and a second pooling layer connected in sequence. The third convolutional layer uses 32 3×3 convolutional kernels to perform feature extraction on the center of interest region image, and the fourth convolutional layer uses 64 3×3 convolutional kernels to perform feature extraction on the output of the third convolutional layer. This achieves moderate feature extraction on the center of interest region image and ensures that the classification model does not ignore the importance of the center of interest region image. The second pooling layer uses a 2×2 max pooling layer to perform max pooling on the output of the fourth convolutional layer, which also reduces computational complexity while maintaining important features. The third convolutional branch is used to perform shallow feature extraction on the low-interest sub-region image. Specifically, it can be composed of a fifth convolutional layer and a third pooling layer connected in sequence. The fifth convolutional layer uses 16 3×3 convolutional kernels to perform feature extraction on the low-interest sub-region image, so as to ensure computational efficiency while extracting basic features. The third pooling layer uses a 2×2 max pooling layer to perform max pooling on the output of the fifth convolutional layer, which also reduces computational complexity while maintaining important features. The feature merging layer is used to flatten the outputs of the three convolutional branches and concatenate them together to form a merged feature vector; Fully connected layers, which consist of 128 or 256 neurons, use the ReLU activation function to process and merge feature vectors in order to capture the complex relationships between features; The output layer has the same number of neurons as the number of defect types. The output of the fully connected layer is processed by the Softmax activation function to determine the defect types of the target region image. For example, if there are six defect types, such as stains, color difference, wrinkles, fuzz, damage, and uneven yarn, then the output layer also has 6 neurons. The process of training the defect classification model is as follows: Acquire a large number of color images of textiles with known defect types, crop out the target area images corresponding to each defect area, and divide the target area images into several sub-region images using the same method as above. Label the defect type of the defect area on the target area image. Specifically, specific codes can be used to represent various defect types, such as using 1, 2, 3, 4, 5, 6 to represent stains, color difference, wrinkles, pilling, damage, and uneven yarn, respectively. Summarize the sub-region images and the labeled target area images to construct the first sample set. Randomly divide the second sample set into training set, validation set, and test set in a ratio of 70:15:15. The target region image labeled in the training set is used as the output label, and the corresponding sub-region image is used as the input to train the defect classification model. During training, cross-entropy loss is used as the loss function, and the model parameters of the defect classification model are updated using Adam or SGD optimizer to minimize the loss function. After each training round, the defect classification model is evaluated on the validation set, and model hyperparameters such as learning rate and batch size are adjusted in time. Training stops after reaching the predetermined number of training rounds, and the defect classification model is tested on the test set. Specifically, accuracy, recall, F1 score, etc. can be used as test indicators. The edge detection model is considered to have completed training after the test indicators are met; otherwise, the model parameters are adjusted and retraining is carried out until the test indicators are met. During the model training process described above, the learning rate is generally set between 0.00001 and 0.001, the number of iterations is generally set between 30 and 50, the batch size is generally set between 32 and 256, and the regularization coefficient is generally set between 0.00001 and 0.0001. The specific criteria for determining whether the test metrics meet the standards can be set by the staff according to the actual situation. For example, when the accuracy and recall reach 90% or higher and the F1 score reaches 0.9 or higher, it can be considered as meeting the standards. These are conventional technical means used by those skilled in the art in the model training process, and will not be elaborated here. As one implementation method, target area images were collected for 126 stain samples, 113 color difference samples, 98 wrinkle samples, 134 fuzzy samples, 62 damaged samples, and 85 yarn unevenness samples. A conventional convolutional neural network was used to construct and train a reference model that takes the target area images as input and outputs the defect type. The samples were then processed based on the reference model and the proposed technical solution. The recognition accuracy for each defect type is shown in the table below: Table 1. Summary Table of Defect Type Identification Results Through Table 1 above and the following text Figure 2 It is clear that this solution outperforms the control model in the identification of various defect types, with an average recognition accuracy rate 10 percentage points higher than the control model. In particular, the superiority of this solution in the identification of wrinkles is the most significant, with an average recognition accuracy rate 19 percentage points higher than the control model. This shows that the differential feature extraction of this solution can focus on the pixels in the defect area, which significantly improves the accuracy of defect type classification. The logic for tracing the source of a process based on the type of defect is as follows: Stains may be caused by equipment contamination or chemical splashes during the dyeing or printing process, or they may be caused by contact with unclean items during post-processing. Therefore, for this type of defect, stains should be traced back to the dyeing, printing and post-processing steps. Color difference usually originates from the dyeing process and may be caused by factors such as uneven dye ratio, improper control of dye bath, and inconsistent dyeing processes in different batches. Therefore, for this type of defect, color difference should be traced back to the dyeing process. Wrinkles may be caused by uneven stretching of the material or improper storage during the sewing process. Improper heat treatment during the finishing process may also cause this problem. Therefore, for wrinkles as a defect type, the source should be traced back to the sewing, packaging and finishing processes. Pilling may be caused by poor yarn quality or improper weaving methods during the weaving stage. If proper treatment is not carried out during the finishing process, pilling may also occur. Therefore, for this type of defect, the source should be traced back to the weaving and finishing processes. Damage is usually caused by mechanical failure or improper operation during the weaving process, or it may be caused by carelessness during cutting, or by poor sewing or excessive stretching during the sewing process. Therefore, for this type of defect, the source should be traced back to the weaving, cutting and sewing processes. Uneven yarn thickness may be caused by poor control of spinning equipment during the yarn production stage or by improper loom settings during the weaving process. Therefore, for this type of defect, the source should be traced back to the yarn production and weaving processes.
[0023] The above formulas are all dimensionless calculations. The formulas are derived from software simulations based on a large amount of collected data to obtain the most recent real-world results. The preset parameters in the formulas are set by those skilled in the art according to the actual situation.
[0024] The above embodiments can be implemented, in whole or in part, by software, hardware, firmware, or any other combination thereof. When implemented in software, the above embodiments can be implemented, in whole or in part, as a computer program product. Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution.
[0025] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment, depending on actual needs.
[0026] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application.
Claims
1. A machine vision-based intelligent classification and traceability method for textile defects, characterized in that, Includes the following steps: S1. Analyze the grayscale image of the textile to be identified based on the edge detection model to determine the defect area, and based on the defect area, cut out the image of the area to be repaired, including the target area and the reference area, and its binary mask image from the color image of the textile to be identified. S2, based on the repair model, analyze the image of the region to be repaired and its binary mask image to obtain the repaired region image, and compare and analyze it with the image of the region to be repaired to determine the attention weight of each pixel in the target region of the image of the region to be repaired; S3, extract the target region image from the image to be repaired, and divide the target region image into several sub-region images based on the attention weight, including high attention sub-region images, medium attention sub-region images and low attention sub-region images; S4 analyzes the images of each sub-region based on the defect classification model to output the defect type of the target region image, and performs process tracing based on the defect type. The defect classification model includes three convolution branches with successively decreasing convolution depths, which are used to process high-interest sub-region images, medium-interest sub-region images, and low-interest sub-region images, respectively.
2. The intelligent classification and traceability method for textile defects based on machine vision according to claim 1, characterized in that: The edge detection model is constructed based on a convolutional neural network, which includes an input layer for receiving a grayscale image, one or more convolutional layers for performing convolution operations to extract image features, a pooling layer connected after the convolutional layers and performing pooling operations, and an output layer for outputting a binary image, which includes defective and non-defective regions.
3. The intelligent classification and traceability method for textile defects based on machine vision according to claim 1, characterized in that, The logic for cropping the image of the area to be repaired is as follows: For each defect area, the outer contour of the defect area is extracted, and a high scaling factor and a low scaling factor are preset. Both the high scaling factor and the low scaling factor are greater than 1, and the high scaling factor is greater than the low scaling factor. The outer contour of the defect area is scaled with the geometric center of the outer contour of the defect area as the origin and the high scaling factor as the scaling ratio to obtain the first extended outer contour of the defect area. Similarly, the outer contour of the defect area is scaled with the geometric center of the outer contour of the defect area as the origin and the low scaling factor as the scaling ratio to obtain the second extended outer contour of the defect area. The smallest bounding rectangle of the first extended outer contour is projected onto the color image of the textile to be identified. The image area within the smallest bounding rectangle of the first extended outer contour in the color image is selected and cropped to serve as the repair area image of the defect area. The smallest bounding rectangle of the second extended outer contour is projected onto the repair area image. The image area within the smallest bounding rectangle of the second extended outer contour in the repair area image is selected to serve as the target area. The area in the repair area image that does not belong to the target area is used as the reference area. The logic for constructing a binary mask image of the region to be repaired is as follows: copy the region to be repaired image to obtain a copy of the region to be repaired image, convert the copy of the region to be repaired image to grayscale, replace the grayscale values of the pixels in the target region with 0, and replace the grayscale values of the pixels in the reference region with 255, so as to obtain a binary mask image used to identify the target region and the reference region.
4. The intelligent classification and traceability method for textile defects based on machine vision according to claim 1, characterized in that: The repair model is based on generative adversarial networks and includes a generator based on convolutional neural networks and a discriminator based on deep convolutional networks. The repair model is used to analyze and process the image of the region to be repaired and its binary mask image to output the repaired region image after the target region is repaired. The generator includes an input layer for receiving the image of the region to be repaired and its binary mask image, and fusing the two into a stitched image based on channel stitching; an encoder for downsampling the stitched image to extract image features; a bottleneck layer for extracting features from the output of the encoder; a decoder for upsampling the output of the bottleneck layer to restore the image size; and an output layer for outputting the repaired region image. The discriminator includes an input layer for receiving the generator output, one or more convolutional layers for performing convolution operations to extract image features, pooling layers connected after the convolutional layers to perform pooling operations, and a fully connected layer for outputting the true probability.
5. The intelligent classification and traceability method for textile defects based on machine vision according to claim 1, characterized in that, The logic for determining attention weights is as follows: For any pixel in the target region of the image to be repaired, extract its RGB value, and extract the RGB value of the corresponding pixel in the repaired image. The degree of difference between the two is used as the attention index of the pixel. The degree of difference is specifically represented by Euclidean distance, Manhattan distance or squared difference. The attention indexes of all pixels in the target region of the image to be repaired are normalized to obtain the attention weight of each pixel in the target region of the image to be repaired.
6. The intelligent classification and traceability method for textile defects based on machine vision according to claim 1, characterized in that, The logic for dividing the image into sub-regions is as follows: a high attention threshold and a low attention threshold are preset, and attention weights are combined to determine the attention category of each pixel in the target region image, which includes high attention pixels, medium attention pixels and low attention pixels, and the high attention threshold is greater than the low attention threshold. Set the state of each pixel in the target region image to unvisited. Randomly select an unvisited pixel as the seed of the sub-region. Iterate through all unvisited pixels adjacent to the seed. If the interest category of a pixel is the same as that of the seed, include the pixel in the sub-region of the seed to update the sub-region. Iterate through all unvisited pixels adjacent to the newly included sub-region to include new pixels in the sub-region of the seed. Iterate through the sub-region in this way until the sub-region of the seed no longer includes new pixels to determine a final sub-region. Update the state of each pixel in the final sub-region to visited. Randomly select a pixel from the unvisited pixels as the new seed. Repeat the iteration until the state of all pixels is updated to visited to divide the target region image into several sub-regions. For any sub-region, the specific logic for determining its type is as follows: if the pixels in the sub-region are high-interest pixels, then the sub-region is designated as a high-interest sub-region; if the pixels in the sub-region are medium-interest pixels, then the sub-region is designated as a medium-interest sub-region; if the pixels in the sub-region are low-interest pixels, then the sub-region is designated as a low-interest sub-region.
7. The intelligent classification and traceability method for textile defects based on machine vision according to claim 6, characterized in that, The specific method for determining the attention category is as follows: if the attention weight of a pixel in the target region image is not less than the high attention threshold, then the pixel is classified as a high attention pixel; if the attention weight of a pixel in the target region image is not greater than the low attention threshold, then the pixel is classified as a low attention pixel; if the attention weight of a pixel in the target region image is between the high attention threshold and the low attention threshold, then the pixel is classified as a medium attention pixel.
8. The intelligent classification and traceability method for textile defects based on machine vision according to claim 6, characterized in that: For each sub-region, the ratio of the number of pixels in the sub-region to the number of pixels in the target region is calculated as the pixel proportion of the sub-region. A preset proportion threshold is set, and the sub-region with the smallest pixel proportion is selected as the target sub-region. It is then determined whether its pixel proportion is greater than the proportion threshold. If it is, no merging operation is performed on it. If it is not, the sub-regions adjacent to the target sub-region are selected as sub-regions to be merged. The target sub-region is then merged with the sub-region to be merged with the smallest pixel proportion. The type of the merged sub-region is set to the type of the sub-region with higher attention among the two sub-regions before merging, so as to update the sub-region distribution in the target region image. From the updated sub-region distribution, the sub-region with the smallest pixel proportion is selected again as the target sub-region. The above judgment, merging and update operations are repeated until the pixel proportion of the target sub-region is greater than the proportion threshold, thereby determining the final sub-region distribution in the target region image.
9. The intelligent classification and traceability method for textile defects based on machine vision according to claim 1, characterized in that: The defect classification model is built on a convolutional neural network, and its architecture is as follows: The input layer is used to receive images of each sub-region. The first convolutional branch is used to extract deep features from the high-interest sub-region image; The second convolutional branch is used to extract moderate features from the image of the region of interest. The third convolutional branch is used to perform shallow feature extraction on the low-interest sub-region image; The feature merging layer is used to flatten the outputs of the three convolutional branches and concatenate them together to form a merged feature vector; The fully connected layer uses the ReLU activation function to process and merge feature vectors in order to capture the complex relationships between features; The output layer, with the same number of neurons as the number of defect types, uses the Softmax activation function to process the output of the fully connected layer in order to determine the defect types in the target region image.
10. The intelligent classification and traceability method for textile defects based on machine vision according to claim 1, characterized in that, The defect types include stains, color differences, wrinkles, fuzzing, damage, and uneven yarn. The logic for process traceability based on defect types is as follows: For the stain type of defect, the source can be traced back to the dyeing, printing and post-treatment processes; For the defect type of color difference, the source is traced back to the dyeing process; For the defect type of wrinkles, the source can be traced back to the sewing, packaging and post-processing procedures; For the defect type of pilling, the source can be traced back to the weaving and finishing processes; For the defect type of breakage, the source can be traced back to the weaving, cutting and sewing processes; For the defect type of uneven yarn, the source can be traced back to the yarn production and weaving process.