A detection method for color difference and stain defects of colored textured fabrics
Through the U-shaped denoising convolutional autoencoder model and the post-processing method of double-threshold segmentation, the problems of low color difference and stain defect detection accuracy and high cost in color texture fabric detection are solved, and efficient and accurate defect detection is achieved.
Patent Information
- Application Number
- CN202111307343.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-05
- Publication Date
- 2025-05-27
- Estimated Expiration
- 2041-11-05
AI Technical Summary
When detecting color difference and stain defects of colored textured fabrics, the detection accuracy is low and the cost is high. Unsupervised algorithms require a large amount of labeled data, making it difficult to achieve efficient detection.
The U-shaped denoising convolutional autoencoder model is used to train the defect-free color textured fabric images to superimpose Gaussian noise, so as to realize defect detection and positioning of color textured fabrics. The post-treatment phase uses a residual treatment method with double threshold segmentation to optimize the detection ability of chromatic aberration and stain defects.
Without the need to mark the defect samples, the efficient detection of colored textured fabrics is achieved through unsupervised learning, which significantly improves the detection accuracy of color aberrations and stain defects, and reduces the detection cost.
Smart Images

Figure CN114119502B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of fabric cut piece defect detection methods in clothing production, and relates to a detection method for color difference and stain defects of colored texture fabrics. Background Art
[0002] In the clothing manufacturing industry, due to the numerous patterns of colored texture fabrics, the diverse characteristics and types of defects, and the difficulty in collecting defect samples, fabric defect detection has always been regarded as a challenging task. Moreover, the price and quality of textiles greatly depend on the efficiency and results of defect detection. Therefore, fabric defect detection has always been an important link in the textile industry. However, the long-term adopted manual detection method requires prior training of workers, and due to reasons such as visual fatigue, there will inevitably be problems of missed detection and low detection efficiency. As a result, enterprises need to spend high labor costs.
[0003] To address the above challenges, automated fabric defect detection systems based on computer vision have gradually replaced manual detection. Many researchers have proposed various defect detection methods based on computer vision and applied them in the fabric production process, which has played a great role in promoting the development of the fabric defect detection field. However, due to the limitations of these algorithms themselves, there are problems of low detection accuracy and high detection cost when dealing with colored texture fabrics with numerous patterns and diverse defect types.
[0004] In recent years, with the rapid development of deep neural networks, detection algorithms based on deep learning have achieved good results in various fields of computer vision, and have also become the mainstream research direction in the fabric defect detection field with a great improvement in effect. However, due to the variable patterns of colored texture fabrics, the scarcity of defect samples and the imbalance of numerous defect types, the cost of manually designing defect features is high, and supervised fabric defect algorithms require a large number of pixel-level labels manually annotated. The defect detection effect of such algorithms and models is often strongly related to the quality of the dataset. In practice, the defects generated in the fabric production process by textile enterprises often exceed 200 types and vary in size. Labeling large-scale defect datasets for each type of fabric is a laborious and inefficient measure.
[0005] In the training phase, unsupervised fabric defect detection algorithms only require defect-free fabric sample images and do not need to use classified and labeled defect samples to train the model. To a certain extent, they can break through the limitations of supervised algorithms. Therefore, some fabric defect detection algorithms based on unsupervised deep learning have gradually been proposed by researchers. Zhang et al. proposed a color texture fabric defect detection algorithm based on an unsupervised denoising convolutional autoencoder (DCAE). By processing the residual between the test image and its reconstructed image, the detection and localization of color texture fabric defects were achieved. However, this method is only applicable to fabrics with relatively simple background textures. Wei et al. used a combined loss function of mean squared error and structural similarity to measure the similarity between the generated image and the input image, and proposed a variational autoencoder (VAE-L2SSIM) algorithm for real-time automatic detection of fabric defects, which meets the real-time computing requirements for fabric defect detection. However, its performance in detecting defects in color textures, especially complex plaid fabrics, is poor. Mei et al. proposed an unsupervised multi-scale denoising convolutional neural autoencoder model (MSCDAE) for automatic detection of fabric defects. By extracting and fusing features of the input training image at different scales and comparing the differences between the reconstructed image and the original image, the localization and detection of fabric defects were achieved. However, its performance in detecting defects in irregular texture fabrics needs to be improved. Zhang et al. proposed a U-shaped deep denoising convolutional autoencoder (UDCAE), which achieved defect detection and localization of yarn-dyed shirt pieces through residual analysis. However, since the post-processing part uses the method of first grayscaling the image and then performing residual processing, it is difficult to detect stain and color difference defects. The above unsupervised fabric defect detection algorithms can complete the training of the model and the detection of fabric defect areas through defect-free samples under certain conditions, but they all have limitations and room for improvement. Summary of the Invention
[0006] The object of the present invention is to provide a detection method for color difference and stain defects of color texture fabrics, which can specifically optimize the detection ability for color difference and stain defects while ensuring the unchanged detection ability for other types of defects.
[0007] The technical solution adopted by the present invention is a detection method for color difference and stain defects of color texture fabrics, which is specifically implemented according to the following steps:
[0008] Step 1: Construct a color texture fabric dataset, which includes defect-free color texture fabric images as training samples and defective color texture fabric images as test samples, and add Gaussian noise to the defect-free color texture fabric images;
[0009] Step 2: Construct a U-shaped denoising convolutional autoencoder model;
[0010] Step 3: Input the defect-free color texture fabric image with added Gaussian noise in Step 1 into the U-shaped denoising convolutional autoencoder model constructed in Step 2, and train the U-shaped denoising convolutional autoencoder model according to the training parameters to obtain a trained U-shaped denoising convolutional autoencoder model;
[0011] Step 4: The trained U-shaped denoising convolutional autoencoder model in Step 3 reconstructs the test sample image, outputs the corresponding reconstructed image, and performs residual processing of double-threshold segmentation on the test sample image and the corresponding reconstructed image to obtain the detected defect area.
[0012] The feature of the present invention further lies in that
[0013] In Step 1, adding Gaussian noise to the defect-free color texture fabric image specifically is: The process of adding noise is shown in Equation (1):
[0014]
[0015] In the formula, is the defect-free color texture fabric image after adding Gaussian noise, I is the defect-free color texture fabric image, g represents the level of the added Gaussian noise, and N represents the Gaussian noise subject to normal distribution.
[0016] The U-shaped denoising convolutional autoencoder model in Step 2 includes two parts: an encoder and a decoder connected in sequence;
[0017] The EfficientNet-B4 network used in the encoder part consists of five stages: D1, D2, D3, D4, and D5. The D1 stage includes a convolutional layer with a convolutional kernel size of 3×3 and a stride of 2, followed by a Swish activation function, and two MBConvBlocks with a channel expansion ratio of 1 and a depth convolutional kernel of 3×3 connected in sequence; the D2 stage includes four MBConvBlocks with a channel expansion ratio of 6 and a depth convolutional kernel of 3×3 connected in sequence; the D3 stage includes four MBConvBlocks with a channel expansion ratio of 6 and a depth convolutional kernel of 5×5 connected in sequence; the D4 stage includes six MBConvBlocks with a channel expansion ratio of 6 and a depth convolutional kernel of 3×3, and six MBConvBlocks with a channel expansion ratio of 6 and a depth convolutional kernel of 5×5 connected in sequence; the D5 stage includes eight MBConvBlocks with a channel expansion ratio of 6 and a depth convolutional kernel of 5×5, two MBConvBlocks with a channel expansion ratio of 6 and a depth convolutional kernel of 3×3, a convolutional layer with a convolutional kernel size of 1×1 and a stride of 1, and a Swish activation function connected in sequence. The outputs of the five stages correspond to feature maps with sizes of 128×128, 64×64, 32×32, 16×16, and 8×8, and the number of channels is 24, 32, 56, 112, and 160 respectively. The output of the previous stage serves as the input of the next stage;
[0018] The decoder part includes five stages: U1, U2, U3, U4, and U5, which are composed of alternating connections of 5 transposed convolutional layers and 5 double convolutional layers and connected to the final output layer. The U1, U2, U3, and U4 stages all include a transposed convolution and a double convolutional layer connected in sequence. The U5 stage includes a transposed convolution, a double convolutional layer, and an output layer connected in sequence. The output of the previous stage serves as the input of the next stage. The input of the U1 stage is the output of the encoder D5 stage. Among them, the parameters of the 5 transposed convolutional layers are the same, and all use ConvTranspose with a convolutional kernel of 2×2 and a stride of 2. The 5 double convolutional layers are all composed of a convolutional block with a convolutional kernel of 3×3, a stride of 1, and a padding of 1, a ReLU activation function, a convolutional block with a convolutional kernel of 3×3, a stride of 1, and a padding of 1, and a ReLU activation function connected in sequence. The output layer is a convolutional block with a convolutional kernel of 1×1 and a stride of 1;
[0019] The input of the double convolutional layer in the U1 stage is also connected to the output of the encoder D4 stage; the input of the double convolutional layer in the U2 stage is also connected to the output of the encoder D3 stage; the input of the double convolutional layer in the U3 stage is also connected to the output of the encoder D2 stage; the input of the double convolutional layer in the U4 stage is also connected to the output of the encoder D1 stage.
[0020] The working process of each stage of the decoder is as follows:
[0021] The specific operations in the U1 stage are as follows:
[0022] The input of the transposed convolution is the feature map with a size of 8×8 and 1792 channels output by the encoder D5 stage. The input of the double convolutional layer is the feature map with a size of 16×16 and 624 channels obtained by concatenating the feature map with a size of 16×16 and 512 channels output by the transposed convolution and the feature map with a size of 16×16 and 112 channels output by the encoder D4 stage on the channels. The output is the feature map with a size of 16×16 and 512 channels.
[0023] The specific operations in the U2 stage are as follows:
[0024] The input of the transposed convolution is the output of the U1 stage. The input of the double convolutional layer is the feature map with a size of 32×32 and 312 channels obtained by concatenating the feature map with a size of 32×32 and 256 channels output by the transposed convolution and the feature map with a size of 32×32 and 56 channels output by the encoder D3 stage on the channels. The output is the feature map with a size of 32×32 and 256 channels.
[0025] The specific operations in the U3 stage are as follows:
[0026] The input of the transposed convolution is the output of the U2 stage. The input of the double convolutional layer is the feature map with a size of 64×64 and 160 channels obtained by concatenating the feature map with a size of 64×64 and 128 channels output by the transposed convolution and the feature map with a size of 64×64 and 32 channels output by the encoder D2 stage on the channels. The output is the feature map with a size of 64×64 and 128 channels.
[0027] The specific operations in the U4 stage are as follows:
[0028] The input of the transposed convolution is the output of the U3 stage. The input of the double convolutional layer is the feature map with a size of 128×128 and 88 channels obtained by concatenating the feature map with a size of 128×128 and 64 channels output by the transposed convolution and the feature map with a size of 128×128 and 24 channels output by the encoder D1 stage on the channels. The output is the feature map with a size of 128×128 and 64 channels.
[0029] The specific operations in the U5 stage are as follows:
[0030] The input of the transposed convolution is the output of the U4 stage. The input of the double convolutional layer is a feature map with a size of 256×256 and 32 channels, which is obtained by concatenating the feature map output by the transposed convolution and the original image with a size of 256×256 and 3 channels in the initial input of the model along the channels. The feature map with a size of 256×256 and 32 channels output by the double convolutional layer is used as the input of the output layer, and the final reconstructed image with a size of 256×256 and 3 channels is output.
[0031] Step 3 is specifically as follows:
[0032] In step 3.1, a defect-free color texture fabric image with superimposed Gaussian noise randomly selected in step 1 is put into the U-shaped denoising autoencoder to obtain a reconstructed output image with the same dimension as the input image sample.
[0033] In step 3.2, during the model training process, a defect-free color texture fabric image without superimposed Gaussian noise is used as the training target, and the loss function between the reconstructed output image and the training target is calculated. The loss function is defined as in Equation (7):
[0034]
[0035] Among them, is the structural similarity loss, is the multi-scale gradient magnitude similarity loss, is the Charbonnier loss; λ S and λ G are respectively the loss weights of the structural similarity loss and the multi-scale gradient magnitude similarity loss;
[0036] During the training process, the purpose is to minimize this loss function, and the training stops when the number of training times reaches the set maximum number of training times.
[0037] In step 3.2, is calculated according to the following formula:
[0038]
[0039] In the formula, ε is a constant selected for numerical stability, ε = 1e-3, I represents the defect-free color texture fabric image, represents the reconstructed image corresponding to the defect-free color texture fabric image output by the model;
[0040] is calculated according to the following formula:
[0041]
[0042] In the formula, is the structural similarity value between the defect - free color texture fabric image and its corresponding reconstructed image;
[0043] It is calculated according to the following formula:
[0044]
[0045] where, is the gradient magnitude similarity value between the defect - free color texture fabric image and the reconstructed image at different scales. l = 1 - 4 represent the original image of the defect - free color texture fabric image, and images at scales of 1 / 2, 1 / 4, and 1 / 8 respectively; I l represents the images of the defect - free color texture fabric image at four different scales, represents the images of the reconstructed image corresponding to the defect - free color texture fabric image output by the model at four different scales;
[0046] where, is calculated according to the following formula:
[0047]
[0048] In the formula, s is a constant to ensure stability, and g() represents the gradient magnitude map of the image, which is defined as formula (6):
[0049]
[0050] In the formula, g(M) represents the gradient magnitude map of image M, h x and h y are 3×3 Prewitt filters along the x and y directions, and * is the convolution operation.
[0051] Step 4 is specifically as follows:
[0052] Step 4.1, input the test sample image in Step 1 into the trained U - shaped denoising convolutional auto - encoder model in Step 3, and output the corresponding reconstructed image;
[0053] Step 4.2, perform Gaussian filtering on both the test sample image and its corresponding reconstructed image;
[0054] Step 4.3, obtain the residual image of the test sample image and its corresponding reconstructed image after Gaussian filtering, and perform Gaussian filtering again to smooth the residual image. Specifically, according to the following formula:
[0055]
[0056] where, G(I), They are the test sample image after Gaussian filtering and its corresponding reconstructed image respectively. G() represents performing Gaussian filtering processing, and I Gaussian&res is the residual image after Gaussian filtering;
[0057] Step 4.4: Perform three-channel threshold segmentation on the residual image after Gaussian filtering to obtain a binary image, so as to eliminate randomly distributed and small-valued random noise. The threshold segmentation is carried out by using the method of adaptive threshold, as shown in Equation (10):
[0058]
[0059] In the formula: p is the pixel value of the image, T is the adaptive threshold, μ and σ are the mean and standard deviation of the image respectively, and c is the coefficient of the standard deviation during threshold segmentation;
[0060] Step 4.5: Perform grayscale operation on the three-channel binary image to obtain a single-channel grayscale image. The grayscale operation is as shown in Equation (11):
[0061] I gray = 0.299·I r + 0.587·I g + 0.114·I b (11)
[0062] In the formula: I gray is the image after grayscale operation; I r , I g , I b are the pixel values under the three different color channels of RGB corresponding to the binary image respectively. The pixel range of the image after grayscale operation is from 0 to 255;
[0063] Step 4.6: Perform single-channel threshold segmentation on the grayscale image, and perform opening operation of erosion first and then dilation on the binary image after threshold segmentation to obtain the detection result image;
[0064] The opening operation is as shown in Equation (12):
[0065]
[0066] In the formula: I opening is the image after opening operation, I binary is the binary image after threshold segmentation,!, are erosion and dilation operations respectively, and E is the structural element;
[0067] Step 4.7: Analyze the values of each pixel point in the most recently detected result image to determine whether there is a defective area. If there is no difference in the detected result image, that is, all pixel values in the image are 0, it means that the input colored woven fabric has no defects. If there are two pixel values, 0 and 1, in the detected result image, it means that the input colored woven fabric image has defects, and the defective area is the area where the pixel value is 1.
[0068] The beneficial effects of the present invention are
[0069] In the model training stage of the method of the present invention, it is not necessary to use labeled defective samples. The efficient U-shaped denoising autoencoder model trained only with defect-free samples superimposed with noise can effectively reconstruct the color texture fabric image. Then, in the post-processing stage, a post-processing method of double-threshold segmentation is adopted. Through Gaussian filtering and residual processing of the color reconstruction image and the original defective image, color differences and stain defects are revealed, so as to specifically optimize the detection ability for color differences and stain defects. And thanks to the design of skip connections and combined loss functions in the network model, the details and quality of the model reconstruction image can be guaranteed, so as to maintain the detection ability for other types of defects. The detection accuracy of this method can meet the requirements of the production detection process of color texture fabrics, and provides an automatic defect detection solution that is easy to implement in engineering practice for the detection process of the color texture fabric manufacturing industry. Description of the Drawings
[0070] Figure 1 is a partial pattern sample of the color texture fabric dataset in a method for detecting color difference and stain defects of color texture fabrics according to the present invention;
[0071] Figure 2 is a model structure diagram of an efficient U-shaped denoising convolutional autoencoder in a method for detecting color difference and stain defects of color texture fabrics according to the present invention;
[0072] Figure 3 is a structure diagram of the mobile flip bottleneck convolutional block MBConvBlock used in the encoder part in a method for detecting color difference and stain defects of color texture fabrics according to the present invention;
[0073] Figure 4 is a schematic flow chart of Step 4 in a method for detecting color difference and stain defects of color texture fabrics according to the present invention;
[0074] Figure 5 is a comparison chart of the detection results of the EUDCAE model used in the experiment and the AE-L2SSIM, VAE-L2SSIM, MSCDAE, and UDCAE models on 10 patterns in a method for detecting color difference and stain defects of color texture fabrics according to the present invention;
[0075] Figure 6This is a comparison chart of the detection results of the current processing method and the post-processing method of double-threshold segmentation used in the present invention for color difference and stain defects of colored texture fabrics on stain and color difference type defects. Detailed implementation manners
[0076] The present invention will be described in detail below with reference to the accompanying drawings and specific implementation manners.
[0077] A detection method for color difference and stain defects of colored texture fabrics according to the present invention is specifically implemented according to the following steps:
[0078] Step 1, construct a dataset of colored texture fabrics. The dataset of colored texture fabrics includes defect-free colored texture fabric images as training samples and defective colored texture fabric images as test samples. A total of 10 representative patterns are selected for the training of the model and the verification of the detection effect, namely CL1, CL2, CL4, CL12, SL1, SL9, SL13, SP3, SP5, SP19. As Figure 1 shown, the first row of the attached Figure 1 is the defect-free colored texture fabric image, the second row is the defective colored texture fabric image, and the third row is the marked true defect area corresponding to the defective colored texture fabric image in the second row. Gaussian noise is superimposed on the defect-free colored texture fabric image. Specifically, superimposing Gaussian noise on the defect-free colored texture fabric image is as follows: The process of superimposing noise is shown in Equation (1):
[0079]
[0080] In the formula, is the defect-free colored texture fabric image after superimposing Gaussian noise, I is the defect-free colored texture fabric image, g represents the level of the superimposed Gaussian noise, g is 0.3, and N represents Gaussian noise subject to a normal distribution;
[0081] Step 2, construct a U-shaped denoising convolutional autoencoder model, the structure of which is as Figure 2 shown. The U-shaped denoising convolutional autoencoder model includes two parts: an encoder and a decoder connected in sequence;
[0082] The EfficientNet-B4 network used in the encoder part consists of five stages: D1, D2, D3, D4, and D5. The D1 stage includes a convolutional layer with a kernel size of 3×3 and a stride of 2, followed by a Swish activation function, and two MBConvBlocks with a channel expansion ratio of 1 and a depthwise convolutional kernel of 3×3 connected in sequence. The D2 stage includes four MBConvBlocks with a channel expansion ratio of 6 and a depthwise convolutional kernel of 3×3 connected in sequence. The D3 stage includes four MBConvBlocks with a channel expansion ratio of 6 and a depthwise convolutional kernel of 5×5 connected in sequence. The D4 stage includes six MBConvBlocks with a channel expansion ratio of 6 and a depthwise convolutional kernel of 3×3, and six MBConvBlocks with a channel expansion ratio of 6 and a depthwise convolutional kernel of 5×5 connected in sequence. The D5 stage includes eight MBConvBlocks with a channel expansion ratio of 6 and a depthwise convolutional kernel of 5×5, two MBConvBlocks with a channel expansion ratio of 6 and a depthwise convolutional kernel of 3×3, a convolutional layer with a kernel size of 1×1 and a stride of 1, and a Swish activation function. The outputs of the five stages correspond to feature maps with sizes of 128×128, 64×64, 32×32, 16×16, and 8×8, and the number of channels is 24, 32, 56, 112, and 160 respectively. The output of the previous stage is used as the input of the next stage.
[0083] Among them, the MBConvBlock included in EfficientNet-B4 refers to the mobile inverted bottleneck convolutional block, and its structure is as Figure 3 shown. In this mobile inverted bottleneck convolutional block, first, a pointwise convolution with a kernel size of 1×1 is performed on the input, and the number of output channels is changed according to the expansion ratio. Then, a depthwise convolution with a kernel size of k×k (where k is the size of the depthwise convolutional kernel of the MBConvBlock mentioned above) is performed. Then, the SE module first performs a compression operation on the feature map obtained by convolution to obtain the global feature at the channel level, and then performs an excitation operation to learn the relationship between channels to obtain the weights of different channels. Finally, it is multiplied by the original feature map to obtain the final feature for output. At this time, a convolution with a kernel size of 1×1 is used to restore the original number of channels. Finally, to make the model have random depth and shorten the training time required for the model, when the mobile inverted bottleneck convolutional blocks with the same parameters appear repeatedly, dropout and skip connections are performed. The stride of the depthwise convolution in the mobile inverted bottleneck convolutional blocks with the same parameters becomes 1, which avoids the degradation problem of the deep network while improving the model performance. It is worth mentioning that the activation function in the encoder uses the Swish activation function, and the convolutional blocks all use the SamePadding method with the same or halved resolution of the output and input feature maps.
[0084] The decoder part includes five stages of U1, U2, U3, U4, and U5 connected in sequence. It is composed of five transposed convolutional layers and five double convolutional layers connected alternately and connected to the final output layer. The U1, U2, U3, and U4 stages each include a transposed convolution and a double convolutional layer connected in sequence. The U5 stage includes a transposed convolution, a double convolutional layer, and an output layer connected in sequence. The output of the previous stage is used as the input of the next stage. The input of the U1 stage is the output of the D5 stage of the encoder. Among them, the parameters of the five transposed convolutional layers are the same, and all use ConvTranspose with a convolution kernel of 2×2 and a stride of 2. The five double convolutional layers are all composed of a convolutional block with a convolution kernel of 3×3, a stride of 1, and a padding of 1, a ReLU activation function, a convolutional block with a convolution kernel of 3×3, a stride of 1, and a padding of 1, and a ReLU activation function connected. The output layer is a convolutional block with a convolution kernel of 1×1 and a stride of 1.
[0085] The input of the double convolutional layer in the U1 stage is also connected to the output of the D4 stage of the encoder. The input of the double convolutional layer in the U2 stage is also connected to the output of the D3 stage of the encoder. The input of the double convolutional layer in the U3 stage is also connected to the output of the D2 stage of the encoder. The input of the double convolutional layer in the U4 stage is also connected to the output of the D1 stage of the encoder.
[0086] The working process of each stage of the decoder is as follows:
[0087] The specific operation of the U1 stage is:
[0088] The input of the transposed convolution is a feature map with a size of 8×8 and 1792 channels output by the D5 stage of the encoder. The input of the double convolutional layer is a feature map with a size of 16×16 and 624 channels obtained by concatenating the feature map with a size of 16×16 and 512 channels output by the transposed convolution and the feature map with a size of 16×16 and 112 channels output by the D4 stage of the encoder on the channel. The output is a feature map with a size of 16×16 and 512 channels.
[0089] The specific operation of the U2 stage is:
[0090] The input of the transposed convolution is the output of the U1 stage. The input of the double convolutional layer is a feature map with a size of 32×32 and 312 channels obtained by concatenating the feature map with a size of 32×32 and 256 channels output by the transposed convolution and the feature map with a size of 32×32 and 56 channels output by the D3 stage of the encoder on the channel. The output is a feature map with a size of 32×32 and 256 channels.
[0091] The specific operation of the U3 stage is:
[0092] The input of the transposed convolution is the output of the U2 stage. The input of the double convolutional layer is a feature map with a size of 64×64 and 128 channels output by the transposed convolution and a feature map with a size of 64×64 and 32 channels output by the encoder D2 stage, which are concatenated on the channel dimension to form a feature map with a size of 64×64 and 160 channels. The output is a feature map with a size of 64×64 and 128 channels;
[0093] The specific operations of the U4 stage are as follows:
[0094] The input of the transposed convolution is the output of the U3 stage. The input of the double convolutional layer is a feature map with a size of 128×128 and 64 channels output by the transposed convolution and a feature map with a size of 128×128 and 24 channels output by the encoder D1 stage, which are concatenated on the channel dimension to form a feature map with a size of 128×128 and 88 channels. The output is a feature map with a size of 128×128 and 64 channels;
[0095] The specific operations of the U5 stage are as follows:
[0096] The input of the transposed convolution is the output of the U4 stage. The input of the double convolutional layer is a feature map with a size of 256×256 and 32 channels output by the transposed convolution and the original image with a size of 256×256 and 3 channels as the initial input of the model, which are concatenated on the channel dimension to form a feature map with a size of 256×256 and 35 channels. The feature map with a size of 256×256 and 32 channels output by the double convolutional layer is used as the input of the output layer, and the final output is a reconstructed image with a size of 256×256 and 3 channels.
[0097] Step 3: Input the defect-free color texture fabric image with added Gaussian noise in Step 1 into the U-shaped denoising convolutional autoencoder model constructed in Step 2, and train the U-shaped denoising convolutional autoencoder model according to the training parameters to obtain a trained U-shaped denoising convolutional autoencoder model. Specifically:
[0098] Step 3.1: Randomly select the defect-free color texture fabric image with added Gaussian noise in Step 1 and put it into the U-shaped denoising autoencoder to obtain a reconstructed output image with the same dimension as the input image sample;
[0099] Step 3.2: During the model training process, use the defect-free color texture fabric image without added Gaussian noise as the training target, and calculate the loss function between the reconstructed output image and the training target, where the loss function is defined as in Equation (7):
[0100]
[0101] Among them, is the structural similarity loss, is the multi-scale gradient amplitude similarity loss, is the Charbonnier loss; λ S and λ G are the loss weights of the structural similarity loss and the multi-scale gradient amplitude similarity loss respectively. Set λ G = 0.2, λ S = 0.1
[0102] Among them, is calculated according to the following formula:
[0103]
[0104] In the formula, ε is a constant selected for numerical stability, ε = 1e-3, I represents the defect-free color texture fabric image, represents the reconstructed image corresponding to the defect-free color texture fabric image output by the model;
[0105] is calculated according to the following formula:
[0106]
[0107] In the formula, is the structural similarity value between the defect-free color texture fabric image and its corresponding reconstructed image;
[0108] First, the original image is downsampled and average pooled several times to obtain the original images at four different scales of 1 / 2, 1 / 4, and 1 / 8 respectively. Then, together with the original image, an image pyramid is formed. Finally, the average value of the GMS distance maps at the four scales is calculated, that is is calculated according to the following formula:
[0109]
[0110] Among them, is the gradient amplitude similarity value between the defect-free color texture fabric image and the reconstructed image at different scales. l = 1 - 4 represent the original image of the defect-free color texture fabric image, the images at four different scales of 1 / 2, 1 / 4, and 1 / 8 respectively; I l represents the images of the defect-free color texture fabric image at four different scales, represents the images of the reconstructed image corresponding to the defect-free color texture fabric image output by the model at four different scales;
[0111] Among them, is calculated according to the following formula:
[0112]
[0113] Where s is a constant to ensure stability, and g() represents the gradient magnitude map of the image, which is defined by Equation (6):
[0114]
[0115] Where g(M) represents the gradient magnitude map of image M, and h x and h y are 3×3 Prewitt filters along the x and y directions, and * is the convolution operation;
[0116] During the training process, aiming to minimize this loss function, the maximum number of training iterations is 1500 times, that is, each data sample is trained 100 times; the learning rate scheduling of the model adopts a one-cycle adaptive scheduling method, increasing the learning rate from the initial learning rate to the maximum learning rate of 0.01, and then decreasing from the maximum learning rate to the minimum learning rate far lower than the initial learning rate; the batch size for each input into the model training is set to 8.
[0117] Step 4, as Figure 4 shown, use the trained U-shaped denoising convolutional autoencoder model in Step 3 to reconstruct the test sample image, output the corresponding reconstructed image, and perform residual processing of double-threshold segmentation on the test sample image and the corresponding reconstructed image to obtain the detected defect area; specifically:
[0118] Step 4.1, input the test sample image in Step 1 into the trained U-shaped denoising convolutional autoencoder model in Step 3, and output the corresponding reconstructed image;
[0119] Step 4.2, perform Gaussian filtering on both the test sample image and its corresponding reconstructed image to avoid over-detection caused by the lack of edge information in the reconstructed image; Gaussian filtering uses a 3×3 Gaussian kernel to perform convolution operation on the image, as shown in Equation (8):
[0120]
[0121] Where (x, y) are the pixel coordinates of image I; σ x is the pixel standard deviation of the image in the x-axis direction; σ y is the pixel standard deviation of the image in the y-axis direction;
[0122] Step 4.3, take the residual image of the test sample image and its corresponding reconstructed image after Gaussian filtering, and perform Gaussian filtering again to smooth the residual image, specifically according to the following formula:
[0123]
[0124] Where G(I), They are the test sample image after Gaussian filtering and its corresponding reconstructed image respectively. G() represents performing Gaussian filtering, and I Gaussian&res is the residual image after Gaussian filtering;
[0125] Step 4.4: Perform three-channel threshold segmentation on the residual image after Gaussian filtering to obtain a binary image, so as to eliminate randomly distributed and small-valued random noise. The threshold segmentation is carried out by using the method of adaptive threshold, as shown in Equation (10):
[0126]
[0127] In the formula: p is the pixel value of the image, T is the adaptive threshold, μ and σ are the mean and standard deviation of the image respectively, and c is the coefficient of the standard deviation during threshold segmentation;
[0128] Step 4.5: Perform grayscale operation on the three-channel binary image to obtain a single-channel grayscale image. The grayscale operation is as shown in Equation (11):
[0129] I gray = 0.299·I r + 0.587·I g + 0.114·I b (11)
[0130] In the formula: I gray is the image after grayscale conversion; I r , I g , I b are the pixel values under the three different color channels of RGB corresponding to the binary image respectively. The pixel range of the image after grayscale conversion is from 0 to 255;
[0131] Step 4.6: Perform single-channel threshold segmentation on the grayscale image. Since most of the noise has been filtered out in the first threshold segmentation, and the distribution difference of the grayscale image is small during the second threshold segmentation, the mean and standard deviation can be directly used as the threshold to complete the segmentation. Therefore, the coefficient c of the second threshold segmentation is set to 1. Perform an opening operation of erosion followed by dilation on the binary image after threshold segmentation to obtain the detection result image;
[0132] The opening operation is as shown in Equation (12):
[0133]
[0134] In the formula: I opening is the image after the opening operation, I binary is the binary image after threshold segmentation,!, are the erosion and dilation operations respectively, and E is the structuring element;
[0135] Step 4.7: Analyze the values of each pixel in the most recently detected result image to determine whether there is a defective area. If there is no difference in the detected result image, that is, all pixel values in the image are 0, it means that the input colored woven fabric has no defects. If there are two pixel values, 0 and 1, in the detected result image, it means that the input colored woven fabric image has defects, and the defective area is the area where the pixel value is 1.
[0136] In the training stage of the present invention, it is not necessary to use labeled defective samples. The efficient U-shaped denoising autoencoder model trained only with defect-free samples superimposed with noise can effectively reconstruct color texture fabric images. Then, through the post-processing method of double-threshold segmentation, it is possible to specifically optimize the detection ability for color difference and stain defects while ensuring the detection ability for other types of defects remains unchanged. The detection accuracy of this method can meet the requirements of the production detection process of color texture fabrics, providing an automatic defect detection solution that is easy to implement in engineering practice for the detection process of the color texture fabric manufacturing industry.
[0137] The following uses specific implementation cases to illustrate a detection method for color difference and stain defects of color texture fabrics according to the present invention:
[0138] Prepare software and hardware devices: The detailed configurations of the hardware and software environments used during training and detection are as follows. Hardware environment: The central processing unit is Intel(R) Core(TM) i9-10980XE; the graphics processing unit is GeForce RTX 3090 (24G); the memory is 128G. Software configuration: The operating system is Ubuntu 18.04.10; PyTorch 1.7.1, Anaconda3, Python 3.6.12, CUDA 11.2 deep learning environment.
[0139] Prepare a color texture fabric dataset: It is divided into three categories according to the complexity of the fabric pattern, namely simple lattices (SinpleLattices, SL), stripe patterns (Stripe Patterns, SP), and complex lattices (Complex Lattices, CL). A total of 10 different flower-shaped color texture fabric defect-free images and color texture fabric defect images are prepared for the experiment, which are: CL1, CL2, CL4, CL12, SL1, SL9, SL13, SP3, SP5, SP19. The fabric pattern of SL is mainly composed of small stripes of the same color, the fabric pattern of SP is mainly composed of large stripes of different colors arranged in sequence, and CL is mainly composed of various color stripes intersecting vertically and horizontally. The images in the dataset are all three-channel RGB images of 512×512×3. Prepare the dataset, including defect-free color texture fabric images with superimposed noise for model training and defective color texture fabric images for testing. Attached Figure 1The first row is an image of a defect-free colored texture fabric, the second row is an image of a defective colored texture fabric, and the third row is the marked true defect area corresponding to the defective colored texture fabric image in the second row, which is the basis for calculating evaluation metrics during defect detection.
[0140] Evaluation Metrics: Pixel-level evaluation metrics are adopted, including Precision (P), Recall (R), F1-measure (F1), and Intersection over Union (IoU). The definitions of these evaluation metrics are as shown in Equations (13 - 16):
[0141]
[0142]
[0143]
[0144]
[0145] Among them, TP represents the number of pixels in the defective area that are successfully detected; TN represents the number of pixels in the defective area that are not detected; FP represents the number of pixels in the defect-free area that are wrongly detected as the defective area; FN represents the number of pixels in the defect-free area that are successfully detected as the defect-free area. In the evaluation metrics, Precision and Recall are used to evaluate the precision and recall rate of the model when detecting defects; F1-Measure is an evaluation metric that combines P and R, and the Intersection over Union IoU is used to measure the overlap degree between the defect detection result and the Ground Truth.
[0146] Experimental Process: First, construct a colored texture fabric dataset. Use the defect-free colored texture fabric image with superimposed Gaussian noise as the training input sample, the defect-free colored texture fabric image without superimposed Gaussian noise as the training target, the defective colored texture fabric image without superimposed Gaussian noise as the test input sample, and the true value map corresponding to the colored texture fabric defect sample as the basis for calculating evaluation metrics during defect detection. Secondly, construct a U-shaped denoising convolutional autoencoder model. The model learns the features of the defect-free image through training and can then repair the input defective image. During defect detection, the model performs restorative reconstruction on the input fabric sample image to be tested and outputs a three-channel color image with the same size as the original image. Ideally, if there are no defects in the image to be tested, the difference between the reconstructed image and the original image to be tested is random noise; on the contrary, if there are defects in the image to be tested, due to the significant pixel value difference between the defective area of the original image and the reconstructed image, the actual defective area can be detected and located through the post-processing method of double-threshold segmentation.
[0147] Qualitative analysis of experimental results: To more intuitively compare the detection results of different unsupervised detection methods, the U-shaped denoising convolutional autoencoder (EUDCAE) proposed in this application was experimentally compared with four color fabric defect detection methods, including AE-L2SSIM, VAE-L2SSIM, MSDCAE, and UDCAE. Some detection results are shown as follows Figure 5 ; AE-L2SSIM can detect defects in 4 flower patterns, but there are missed detections in the SL1, SL9, SL13, SP3, and SP19 flower patterns; VAE-L2SSIM can only detect some defects in the CL12 flower pattern; MSCDAE can accurately detect defects in 8 flower patterns, but there are false detections in the CL1 flower pattern and missed detections in the CL12, SL1, and SP19 flower patterns; UDCAE can accurately detect defects in 5 flower patterns, but there are false detections in the CL1 and CL4 flower patterns and missed detections in the CL12, SL1, SL9, and SP19 flower patterns; EUDCAE can accurately detect defects in 9 flower patterns, but there are false detections and missed detections in the CL12 and SP5 flower patterns. By comprehensively comparing the detection, missed detection, and false detection situations of the defect areas, the proposed EUDCAE model can better complete defect detection while producing fewer false detections than other models, and can achieve good defect detection results for flower patterns of three types of complexity;
[0148] In addition, to intuitively show the detection effect of the post-processing method of double-threshold segmentation on color difference and stain defects, for the reconstructed images of the same model, the current and double-threshold segmentation post-processing methods are respectively used to detect some representative stain and color difference defect samples, and the results are shown as follows Figure 6 ; In the figure, GT (Ground Truth) represents the real defect area, Previous represents the current post-processing method, and DTS represents the post-processing method of double-threshold segmentation. The post-processing method of double-threshold segmentation is obviously more in line with the actual defect area in the detection of stain and color-difference defect samples, and the missed detection and false detection areas are less than those of the current post-processing method, achieving a better detection effect.
[0149] Quantitative analysis of experimental results: To more comprehensively and accurately evaluate the detection performance of the U-shaped denoising convolutional autoencoder (EUDCAE) proposed in this application and the detection effect of the post-processing method of double-threshold segmentation on color difference and stain defects, Table 1 lists the values of the comprehensive evaluation index (F1) and the intersection over union (IoU), and makes quantitative comparisons with four color fabric defect detection methods, including AE-L2SSIM, VAE-L2SSIM, MSDCAE, and UDCAE, as well as the current post-processing method and double-threshold segmentation on the CL1, SL9, and SP5 flower patterns; the larger the numerical value of the above indicators, the better the detection result.
[0150] Quantitative Analysis and Comparison of the Detection Results of Five Models under Two Evaluation Metrics
[0151]
[0152] As can be seen from Table 1, the U-shaped denoising convolutional autoencoder (EUDCAE) proposed in this application has an absolute advantage in the two evaluation metrics of F1 and IOU calculated for the three flower patterns of CL1, SL9, and SP5 compared to other models. Moreover, in the EUDCAE model, the post-processing method using double-threshold segmentation (EUDCAE DTS ) also has an absolute advantage in the detection effect achieved.
[0153] Experimental Summary: The present invention proposes a method for detecting color difference and stain defects in colored textured fabrics, and constructs a U-shaped denoising convolutional autoencoder (EUDCAE). The process of this method is as follows: First, a dataset of colored textured fabrics is constructed; Second, a U-shaped denoising convolutional autoencoder model is constructed. For a specific colored textured fabric flower pattern sample, the U-shaped denoising convolutional autoencoder (EUDCAE) is trained using easily obtainable defect-free colored fabric sample images; Then, the image of the colored textured fabric to be tested is put into the trained model for reconstruction, and the post-processing method using double-threshold segmentation is used to achieve rapid detection and positioning of the defect area. The experimental results show that the post-processing method based on the U-shaped denoising convolutional autoencoder (EUDCAE) and double-threshold segmentation can meet the requirements of the production detection process of colored textured fabrics, and significantly improves the detection ability for color difference and stain defects, providing an automatic defect detection scheme that is easy to implement in engineering practice for the detection process in the colored textured fabric manufacturing industry.
Claims
1. A detection method for color difference and stain defects of colored textured fabrics, characterized in that, it is specifically implemented according to the following steps: Step 1, construct a dataset of colored textured fabrics, which includes defect-free colored textured fabric images as training samples and defective colored textured fabric images as test samples, and superimpose Gaussian noise on the defect-free colored textured fabric images; Step 2, construct a U-shaped denoising convolutional autoencoder model, which includes two parts: an encoder and a decoder connected in sequence. The EfficientNet-B4 network used in the encoder part includes five stages: D1, D2, D3, D4, and D5; the decoder part includes five stages: U1, U2, U3, U4, and U5, which are composed of alternating connections of 5 transposed convolutional layers and 5 double convolutional layers and connections to the final output layer; The input of the double convolutional layer in the U1 stage is also connected to the output of the D4 stage of the encoder; The input of the double convolutional layer in the U2 stage is also connected to the output of the D3 stage of the encoder; the input of the double convolutional layer in the U3 stage is also connected to the output of the D2 stage of the encoder; the input of the double convolutional layer in the U4 stage is also connected to the output of the D1 stage of the encoder; Step 3, input the defect-free colored textured fabric images with superimposed Gaussian noise in Step 1 into the U-shaped denoising convolutional autoencoder model constructed in Step 2, and train the U-shaped denoising convolutional autoencoder model according to the training parameters to obtain a trained U-shaped denoising convolutional autoencoder model. Specifically: Step 3.1, randomly select the defect-free colored textured fabric images with superimposed Gaussian noise in Step 1 and put them into the U-shaped denoising autoencoder to obtain a reconstructed output image with the same dimension as the input image sample; Step 3.2, during the model training process, the defect-free color texture fabric image without superimposed Gaussian noise is used as the training target, and the loss function between the reconstructed output image and the training target is calculated , where the loss function is defined as in Equation (7): (7) Among them, is the structural similarity loss, is the multi-scale gradient magnitude similarity loss, is the Charbonnier loss; and are the loss weights of the structural similarity loss and the multi-scale gradient magnitude similarity loss, respectively; During the training process, the purpose is to minimize this loss function, and the training stops when the number of training times reaches the set maximum number of training times; Step 4, the trained U-shaped denoising convolutional autoencoder model in Step 3 reconstructs the test sample images, outputs the corresponding reconstructed images, and performs residual processing of double-threshold segmentation on the test sample images and the corresponding reconstructed images to obtain the detected defect areas.
2. A detection method for color difference and stain defects of colored textured fabrics according to claim 1, characterized in that, superimposing Gaussian noise on the defect-free colored textured fabric images in Step 1 is specifically as follows: the process of superimposing noise is shown in Equation (1): (1) In the formula, is the defect-free color texture fabric image after superimposing Gaussian noise, is the defect-free color texture fabric image, and g represents the level of the superimposed Gaussian noise, represents Gaussian noise that follows a normal distribution.
3. A detection method for color difference and stain defects of colored textured fabrics according to claim 2, characterized in that, The D1 stage in Step 2 includes a convolutional layer with a convolutional kernel size of 3×3 and a stride of 2 connected in sequence, a Swish activation function, and two MBConvBlocks with a channel expansion ratio of 1 and a depth convolutional kernel of 3×3; The D2 stage includes four MBConvBlocks with a channel expansion ratio of 6 and a depth convolutional kernel of 3×3 connected in sequence; The D3 stage consists of four sequentially connected MBConvBlocks with a channel expansion ratio of 6 and a depth convolution kernel of 5×5; the D4 stage consists of six sequentially connected MBConvBlocks with a channel expansion ratio of 6 and a depth convolution kernel of 3×3, and six sequentially connected MBConvBlocks with a channel expansion ratio of 6 and a depth convolution kernel of 5×5; the D5 stage consists of eight sequentially connected MBConvBlocks with a channel expansion ratio of 6 and a depth convolution kernel of 5×5, two sequentially connected MBConvBlocks with a channel expansion ratio of 6 and a depth convolution kernel of 3×3, a convolution layer with a kernel size of 1×1 and a stride of 1, and a Swish activation function; the outputs of the five stages correspond to feature maps with sizes of 128×128, 64×64, 32×32, 16×16, 8×8 and channel numbers of 24, 32, 56, 112, 160 respectively, and the output of the previous stage serves as the input of the next stage; The U1, U2, U3, and U4 stages all consist of a transposed convolution and a double convolutional layer connected in sequence. The U5 stage consists of a transposed convolution, a double convolutional layer, and an output layer connected in sequence; the output of the previous stage serves as the input of the next stage; the input of the U1 stage is the output of the encoder D5 stage; among them, the parameters of the 5 transposed convolutional layers are the same, all using ConvTranspose with a kernel of 2×2 and a stride of 2; the 5 double convolutional layers are all composed of a convolutional block with a kernel of 3×3, a stride of 1, and a padding of 1, a ReLU activation function, a convolutional block with a kernel of 3×3, a stride of 1, and a padding of 1, and a ReLU activation function connected in sequence; the output layer is a convolutional block with a kernel of 1×1 and a stride of 1.
4. A method for detecting color difference and stain defects of colored texture fabrics according to claim 3, characterized in that, The working processes of each stage of the decoder are as follows: The specific operation of the U1 stage is: The input of the transposed convolution is a feature map with a size of 8×8 and a channel number of 1792 output by the encoder D5 stage. The input of the double convolutional layer is a feature map with a size of 16×16 and a channel number of 624 obtained by concatenating the feature map with a size of 16×16 and a channel number of 512 output by the transposed convolution and the feature map with a size of 16×16 and a channel number of 112 output by the encoder D4 stage on the channel. The output is a feature map with a size of 16×16 and a channel number of 512; The specific operation of the U2 stage is: The input of the transposed convolution is the output of the U1 stage. The input of the double convolutional layer is a feature map with a size of 32×32 and a channel number of 312 obtained by concatenating the feature map with a size of 32×32 and a channel number of 256 output by the transposed convolution and the feature map with a size of 32×32 and a channel number of 56 output by the encoder D3 stage on the channel. The output is a feature map with a size of 32×32 and a channel number of 256; The specific operation of the U3 stage is: The input of the transposed convolution is the output of the U2 stage. The input of the double convolutional layer is a feature map with a size of 64×64 and 128 channels, which is obtained by concatenating the output of the transposed convolution and a feature map with a size of 64×64 and 32 channels from the output of the encoder D2 stage on the channel dimension, resulting in a feature map with a size of 64×64 and 160 channels. The output is a feature map with a size of 64×64 and 128 channels. The specific operations of the U4 stage are as follows: The input of the transposed convolution is the output of the U3 stage. The input of the double convolutional layer is a feature map with a size of 128×128 and 64 channels, which is obtained by concatenating the output of the transposed convolution and a feature map with a size of 128×128 and 24 channels from the output of the encoder D1 stage on the channel dimension, resulting in a feature map with a size of 128×128 and 88 channels. The output is a feature map with a size of 128×128 and 64 channels. The specific operations of the U5 stage are as follows: The input of the transposed convolution is the output of the U4 stage. The input of the double convolutional layer is a feature map with a size of 256×256 and 32 channels, which is obtained by concatenating the output of the transposed convolution and the original image with a size of 256×256 and 3 channels from the initial input of the model on the channel dimension, resulting in a feature map with a size of 256×256 and 35 channels. The feature map with a size of 256×256 and 32 channels output by the double convolutional layer is used as the input of the output layer, and finally a reconstructed image with a size of 256×256 and 3 channels is output.
5. A detection method for color texture fabric color difference and stain defects according to claim 4, characterized in that, In step 3.2, calculate according to the following formula: (2) wherein, is a constant selected for numerical stability, , represents a defect-free color texture fabric image, represents the reconstructed image corresponding to the defect-free color texture fabric image output by the model; The said is calculated according to the following formula: (3) Wherein, is the structural similarity value between the defect-free color texture fabric image and its corresponding reconstructed image; Calculate according to the following formula: (4) Among them, is the gradient amplitude similarity value between the defect-free color texture fabric image and the reconstructed image at different scales. l = 1 - 4 represent the original image of the defect-free color texture fabric image, and images at four different scales of 1 / 2, 1 / 4, and 1 / 8 respectively; represents the images of the defect-free color texture fabric image at four different scales, represents the images of the reconstructed images corresponding to the defect-free color texture fabric image output by the model at four different scales; Among them, It is calculated according to the following formula: (5) where s is a constant to ensure stability, and g() represents the gradient magnitude map of the image, defined as Equation (6): (6) In the formula, represents the gradient magnitude map of image M, and are the Prewitt filters of along the x and y directions, and * is the convolution operation.
6. A detection method for color texture fabric color difference and stain defects according to claim 5, characterized in that, The specific step 4 is as follows: Step 4.1, input the test sample image in step 1 into the trained U-shaped denoising convolutional autoencoder model in step 3, and output the corresponding reconstructed image; Step 4.2, perform Gaussian filtering on both the test sample image and its corresponding reconstructed image; Step 4.3, calculate the residual image between the test sample image and its corresponding reconstructed image after Gaussian filtering, and perform Gaussian filtering again to smooth the residual image, specifically according to the following formula: (9) wherein, are respectively the test sample image after Gaussian filtering and its corresponding reconstructed image, and G() represents performing Gaussian filtering processing, is the residual image after Gaussian filtering; Step 4.4, perform three-channel threshold segmentation on the Gaussian-filtered residual image to obtain a binary image, so as to eliminate randomly distributed and small-valued random noise. The threshold segmentation is performed using the adaptive threshold method, as shown in Equation (10): (10) Where: is the pixel value of the image, is the adaptive threshold, , are the mean and standard deviation of the image respectively, is the coefficient of the standard deviation during threshold segmentation; Step 4.5, perform grayscale conversion on the three-channel binary image to obtain a single-channel grayscale image. The grayscale conversion is performed as shown in Equation (11): (11) In the formula: is the grayscale image; are the pixel values of the binary image corresponding to the three different color channels of RGB respectively, and the pixel range of the grayscale image is from 0 to 255; Step 4.6, perform single-channel threshold segmentation on the grayscale image, and perform opening operation of erosion followed by dilation on the threshold-segmented binary image to obtain the detection result image; The opening operation is as shown in Equation (12): (12) In the formula: is the image after the opening operation, is the binary image after threshold segmentation, , are erosion and dilation operations respectively, and E is the structuring element; Step 4.7, analyze the values of each pixel in the most recently detected result image to determine whether there is a defective area. If there is no difference in the detected result image, that is, all pixel values in the image are 0, it means that the input yarn-dyed fabric has no defects. If there are two pixel values, 0 and 1, in the detected result image, it means that the input yarn-dyed fabric image has defects, and the defective area is the area where the pixel value is 1.