A machine vision-based textile defect detection method

By combining the ResNet50 and SPADE algorithms with the CFLOW-AD model, the problems of low efficiency and insufficient accuracy in traditional textile defect detection are solved, achieving efficient and accurate defect identification and localization, which is suitable for real-time detection.

CN121458715BActive Publication Date: 2026-04-14NANCHANG UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-01-05
Publication Date
2026-04-14

AI Technical Summary

Technical Problem

Traditional textile defect detection relies on human vision, which is inefficient and inaccurate, making it difficult to achieve large-scale and rapid detection. Existing machine vision technology cannot provide pixel-level positioning and lacks contextual information.

Method used

A ResNet50 deep convolutional neural network is used in conjunction with the SPADE algorithm for feature extraction and adaptive weighting, and the CFLOW-AD model is used for anomaly detection. The detection parameters are adjusted through a dynamic feedback mechanism to achieve accurate defect identification.

Benefits of technology

It improves the accuracy and robustness of textile defect detection, enabling efficient and accurate defect identification in complex backgrounds, and is suitable for real-time or near-real-time detection needs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121458715B_ABST
    Figure CN121458715B_ABST
Patent Text Reader

Abstract

The application discloses a kind of textile flaw detection methods based on machine vision, and the textile RGB image is obtained by image acquisition and preprocessing, and size adjustment, normalization operation is carried out, core detection process includes: feature extraction is carried out using ResNet50 network, and abnormal area recognition is realized in pixel level in combination with SPADE algorithm and k nearest neighbor, on this basis, using transfer learning strategy, specific textile flaw data set is fine-tuned and optimized, to build high-precision detection model, CFLOW-AD model is used for multi-scale feature extraction and the generation of abnormal score chart, accurately identify potential flaws, and integrated real-time feedback mechanism, system according to preliminary detection result, dynamically adjust detection parameter, and suspected area is re-detected, through TP, FP, ROC curve index carries out model evaluation, generates detailed flaw report, the method effectively improves the automation level and accuracy of textile flaw detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of visual inspection technology for textile defects, and more particularly to a method for detecting textile defects based on machine vision. Background Technology

[0002] Traditional textile defect detection mainly relies on manual visual inspection. This method is inefficient, easily affected by inspector fatigue and subjective judgment, resulting in low consistency and accuracy of test results. In addition, it has high labor costs and is difficult to meet the needs of large-scale and rapid testing, making it unsuitable for the needs of modern production.

[0003] In image processing and computer vision, anomaly detection is a crucial task, especially in scenarios such as industrial quality control and video surveillance. Currently, commonly used techniques in anomaly detection can be broadly categorized into three types: the first identifies anomalies through classification mechanisms; the second utilizes the reconstruction process to discover anomalies; and the third relies on the density distribution of data points for anomaly detection. The DifferNet network is a deep learning-based image feature density estimation method that introduces normalized flow into anomaly detection. However, because it only utilizes the final generated feature layer, it lacks important contextual and semantic information. Data augmentation methods address this deficiency, but it can only be used for image-level detection and cannot perform pixel-level localization. In contrast to DifferNet, the CS-Flow network introduces fully convolutional layers, utilizing multi-scale features to achieve better results in both detection and localization. The Fastflow network alternates between 3x3 and 1x1 convolutional kernels and can be integrated with different feature extractors (CNN, ViT) as embedding modules, improving the applicability of the network model. Traditional nearest neighbor (kNN) methods excel at anomaly detection in overall images, but they often fail to provide specific location information for anomalies within the image. The SPADE technique proposed by Cohen and Hoshen (2021) enhances sub-image anomaly detection through deep pyramid correspondence, effectively addressing this problem. This method achieves anomaly detection by aligning the anomalous image with a certain number of normal images, thus efficiently finding the specific location information of the anomaly within the image.

[0004] This invention aims to overcome the limitations of existing technologies by introducing advanced machine vision technology and deep learning algorithms, and to provide an efficient, accurate, and generalizable method for detecting defects in textiles. Summary of the Invention

[0005] A machine vision-based method for detecting textile defects includes the following steps;

[0006] S1. Acquire image data and perform preprocessing: Use a high-resolution industrial camera to capture RGB images of textiles, ensuring that the acquired images have sufficient clarity and detail for subsequent processing. The camera position, lighting, and shooting angle must be precisely adjusted to ensure image quality and consistency. Perform necessary preprocessing operations on these images: image cropping, scaling, and normalization, adjusting the image pixel values ​​to a uniform range (e.g., [0, 1]) for input into the neural network, adjusting the image size to match the network's input requirements, and possibly applying image smoothing or denoising to reduce unnecessary noise effects.

[0007] S2. Data Augmentation: After acquiring image data, data augmentation techniques such as rotation, scaling, cropping, color jittering, flipping, and mirroring are used to generate more training samples to prevent model overfitting and improve the model's generalization ability.

[0008] S3. Input image feature extraction and anomaly region identification: The processed image is input into the ResNet50 deep convolutional neural network. The network extracts deep features of the image through layers of convolution operations. Using the SPADE algorithm, the spatial features of the image are adaptively weighted to highlight areas in the image that may have defects. The k-nearest neighbor (KNN) algorithm is used to analyze these areas in detail to further determine the location and size of the anomaly regions.

[0009] S4. Model Training and Optimization: The transfer learning method is used to fine-tune the model on a specific textile defect dataset. The model is trained using a specific textile defect dataset, which includes various types of defects (such as holes, stains, color deviations, etc.). The hyperparameters are optimized using cross-validation to obtain a more accurate defect detection model.

[0010] S5. Applying the CFLOW-AD model for anomaly detection: The preprocessed image is input into the CFLOW-AD model. CFLOW-AD identifies subtle anomalous regions and sorts them according to their anomalous scores. The model generates an anomaly score for each pixel. Regions with high anomalous scores may indicate the presence of defects.

[0011] S6. Integrated Real-Time Feedback Mechanism: A dynamic feedback mechanism is incorporated into the detection process. The system automatically adjusts detection parameters—threshold and sensitivity—based on preliminary detection results to ensure stable performance under different environments. The defect detection threshold is adjusted in real-time based on the preliminary results. When a suspected defect is detected in an area, the system adjusts the detection sensitivity for a more precise re-examination. After the preliminary detection, the system resamples and performs detailed analysis on the suspected areas to ensure the accuracy of the detection results. This helps reduce the occurrence of missed and false detections.

[0012] S7. Evaluation and Post-processing: The model performance is evaluated using the main evaluation metrics of the defect detection algorithm (TP, FP, TN, FN, ROC curve), and the detection results are post-processed: denoising and connected component analysis. Based on the detection results, a detailed defect report is generated, which includes information such as the location, type, and size of each defect, to facilitate subsequent processing and quality control.

[0013] Furthermore, a machine vision-based method for detecting textile defects is proposed.

[0014] In step S3, the ResNet50 deep convolutional neural network extracts deep features of the image through layers of convolution operations. Using the SPADE algorithm, the spatial features of the image are adaptively weighted to highlight areas in the image that may have defects. The specific steps are as follows:

[0015] S31: Input the image into ResNet50 and extract key features from the image. The features are used to compare the similarity of different images and perform pixel-level alignment. The Backbone layer is the core part of feature extraction, which can efficiently extract discriminative feature representations from the input image.

[0016] S32: The first step of the SPADE algorithm is to perform k-nearest neighbor search on the target image. Based on global features at the image level, it uses Euclidean distance as a metric, as shown in the following formula:

[0017] Where d(y) represents the average squared distance between the target image y and its k nearest neighbor images. These are features of the target image. It is the feature set of the K nearest neighbor normal images of the target image. yes The feature vector of a certain nearest neighbor image, that is, the feature of a certain positive sample image;

[0018] S33: The second step of the SPADE algorithm is pixel-level anomaly region localization. In this step, a feature pyramid matching strategy is implemented. It extracts feature information from various stages of the ResNet architecture to construct a hierarchical feature representation, i.e., a feature pyramid. This representation intelligently integrates detailed local features and overall global information of the image. Specifically, for each pixel location p in the target image, the algorithm extracts multi-scale features at that location and compares them with a pre-determined feature set G of the K nearest neighbor normal images. By calculating the average distance between the target pixel features and the features in set G, SPADE can effectively identify anomaly regions lacking corresponding normal features, thereby achieving accurate anomaly localization. The anomaly score calculation formula is as follows: , This represents the anomaly score at a pixel location p in the target image y. It is the multi-scale feature vector extracted from the target image y at pixel position p. In the feature space, with The feature set corresponding to pixel position p among the k most similar normal images.

[0019] Furthermore, a machine vision-based method for detecting textile defects is proposed.

[0020] In specific step S31, the core of ResNet50 is the Backbone layer, which extracts key features from the image. The Backbone layer consists of five main parts, each composed of a series of convolutional blocks, progressively abstracting and extracting image features. The initial stage of the Backbone layer is stage 0. The input image first passes through a convolutional layer with an input size of 3x224x224 pixels. A batch normalization layer is introduced to normalize the features, which helps accelerate the network's training process and improve generalization ability. A ReLU activation function is applied to the output of the BN layer to introduce non-linearity and enhance the model's expressive power. A max pooling layer reduces the spatial size of the feature map to 56x56 pixels while retaining 64 output channels, optimizing the feature representation. Following the initial stage 0, the backbone of the network consists of four consecutive stages from stage 1 to stage 2. The four components all adopt the Bottleneck (BTNK) modular design. The Bottleneck module is designed in two forms: one is the BTNK2 variant with the same number of input and output channels; the other is the BTNK1 variant with different numbers of input and output channels.

[0021] BTNK1 has four variable parameters: C, W, C1, and S.

[0022] C: refers to the number of channels in the input feature map, which is the scale of the input feature map in the depth direction;

[0023] W: This refers to the spatial dimension of the input feature map, namely the horizontal width and vertical height of the feature map, and its unit of measurement is pixels;

[0024] C1: Represents the number of feature maps output by the first 1x1 convolutional layer, which is the number of output channels. This value is usually a multiple of the number of input channels.

[0025] S: represents the stride used in a 3x3 convolutional layer to control the reduction in spatial resolution of the output feature map. When the stride S equals 1, the spatial size of the output feature map is the same as that of the input feature map, which means that no downsampling strategy is adopted.

[0026] In the Bottleneck structure, when the number of output channels is inconsistent with the number of input channels, we call it the BTNK1 case. Assume that the shape of the input feature map is (C, W, W) and defined as x. The left side consists of three consecutive convolutional operation units, each followed by batch normalization (BN) and ReLU activation function. This sequence can be regarded as a composite function. On the right side of this composite function, there is a separate convolutional layer whose output is added to the original input x and activated by ReLU, finally producing the output of the BTNK1 module. The feature map size of the output is (C1*4, W / S, W / S).

[0027] BTNK2: has two parameters, C and W;

[0028] C: Same as the definition in BTNK1;

[0029] W: Also represents the size of the input feature map. BTNK2 is defined when the number of output channels of the Bottleneck module is equal to the number of input channels, given an input y of shape (C, W, W).

[0030] The three convolutional units on the left (each followed by batch normalization and ReLU activation) are considered as a single function. The result of this function is accumulated with the original input x and processed by the ReLU activation function to generate the output of the BTNK2 module. The dimensions of its output feature map remain unchanged, i.e., (C, W, W). From this BTNK structure, we can see that the network's characteristic is that it skips some layers and directly adds them to the output. This is also a major feature of the ResNet network. In stage 0, an image data of (3,224,224) is received and passed sequentially through a convolutional layer with 64 7*7 convolutional kernels and a stride of 2, a BN layer, a ReLU activation function, and a max pooling layer, finally obtaining an output of (64,56,56). The subsequent stages 1 to 4 have similar functions: receiving the output from the upper layer, passing it through a BTNK1 structure, and then through several BTNK2 structures to obtain the output, which is then passed to the next layer. The final output has a feature shape of (2048,7,7).

[0031] Furthermore, a machine vision-based method for detecting textile defects is proposed.

[0032] In step S5, the preprocessed image is input into the CFLOW-AD model.

[0033] The CFLOW-AD model, as shown below, is a structure for anomaly detection and localization. It consists of an encoder and multiple parallel decoders. The model's workflow is as follows: The input image is preprocessed to conform to the specifications used during model training. The preprocessed image is then input into the pre-trained encoder to extract multi-scale features. Pyramid pooling is used to capture feature maps of different scales from the encoder's output. The captured feature maps are then fed into the CFLOW decoder, and likelihood estimation is performed on the feature maps at each scale in conjunction with location encoding information. The likelihood estimation results are upsampled to the original resolution of the input image and aggregated to generate an anomaly score map. A threshold is set based on the anomaly score map, and anomaly detection is performed. The exact location of the anomaly is determined by analyzing high-score regions. The detection results are then post-processed and interpreted, and reported to the user in a visual manner. This process achieves efficient anomaly detection and accurate anomaly localization for images.

[0034] Furthermore, a machine vision-based method for detecting textile defects is proposed.

[0035] In step S6, a dynamic feedback mechanism is added to the detection process. The system automatically adjusts the detection parameters, such as threshold and sensitivity, based on the preliminary detection results, as follows;

[0036] S61. Preliminary Detection and Result Generation: The system first uses a preset "initial threshold" to perform preliminary detection on the image, generating the first batch of potential defect areas; and sets the threshold: determining that a pixel is considered a defect only when its abnormal score reaches 50%; sensitivity: affecting the system's attention to subtle abnormalities;

[0037] S62. Analyze preliminary results and identify problems: The system will analyze the number, size, and distribution characteristics of these initially detected defective areas;

[0038] S63. Dynamic parameter adjustment: When there are too many false alarms: the system automatically raises the detection threshold, requiring a higher abnormal score to be identified as a defect;

[0039] Reduce sensitivity: Strong post-processing noise reduction ignores overly subtle signals that may be noise;

[0040] When there is a risk of missed detection: Lower the threshold: The system automatically lowers the detection threshold to capture more areas with slightly lower anomaly scores that may still be defective;

[0041] Improve sensitivity: Perform more detailed analysis on suspected areas, and pay more attention to the detailed information in multi-scale features;

[0042] S64. Re-evaluation and Output: The system uses the adjusted parameters to perform secondary detection and refinement on the image. This process is iterated until the detection results reach the best balance: false positives and false negatives are within acceptable ranges, and finally a more accurate defect report is generated.

[0043] Furthermore, a machine vision-based method for detecting textile defects is proposed.

[0044] In specific step S62, the system will analyze the number, size, and distribution characteristics of these initially detected defective areas, as follows;

[0045] S621. Too many false alarms: A large number of very small, scattered areas that do not conform to typical defect characteristics were detected. When the total number of detected defects far exceeds the normal level, it indicates that the initial threshold may be too low and the system is too sensitive.

[0046] S622. Risk of missed detection: The number of detected defects is unusually low, and some areas with known defects are not identified. This indicates that the initial threshold may be too high and the system is not sensitive enough.

[0047] The beneficial effects of this invention are as follows: By utilizing deep learning technology and the SPADE algorithm, abnormal regions in textile images are effectively identified, improving the accuracy and robustness of detection. Using a pre-trained model, this method can extract multi-level features from images, enhancing the ability to identify abnormal regions. When detecting textile defects, it can better identify abnormal regions, maintaining high accuracy even against complex image backgrounds. An end-to-end detection process is adopted, eliminating the need for separately training different classifiers or pre-processing and post-processing of the dataset. The network structure is simple to design, with fast inference speed, making it suitable for real-time or near real-time detection requirements. Attached Figure Description

[0048] Figure 1 This is a flowchart of a machine vision-based textile defect detection method;

[0049] Figure 2 Here is a diagram of the ResNet50 network structure;

[0050] Figure 3 Here is a flowchart of the CFLOW-AD model structure; Detailed Implementation Example 1

[0051] A machine vision-based method for detecting textile defects includes the following steps;

[0052] S1. Acquire image data and perform preprocessing: Use a high-resolution industrial camera to capture RGB images of the textiles, ensuring that the acquired images have sufficient sharpness and detail for subsequent processing. The camera position, lighting, and shooting angle must be precisely adjusted to ensure image quality and consistency. Necessary preprocessing operations are then performed on these images: image cropping, scaling, and normalization to adjust image pixel values ​​to a uniform range (e.g., [0, 1]) for input into the neural network; image size adjustment to ensure it matches the network's input requirements; and possibly image smoothing or denoising to reduce unnecessary noise.

[0053] S2. Data Augmentation: After acquiring image data, data augmentation techniques such as rotation, scaling, cropping, color jittering, flipping, and mirroring are used to generate more training samples to prevent model overfitting and improve the model's generalization ability.

[0054] S3. Feature extraction and anomaly region identification from the input image: The processed image is input into a ResNet50 deep convolutional neural network. The ResNet50 network structure diagram is shown below. Figure 2 As shown, the network extracts deep features of the image through layers of convolution operations. Using the SPADE algorithm, it adaptively weights the spatial features of the image to highlight areas in the image that may have defects. The k-nearest neighbor (KNN) algorithm is then used to analyze these areas in detail to further determine the location and size of the abnormal areas.

[0055] S4. Model Training and Optimization: The transfer learning method is used to fine-tune the model on a specific textile defect dataset. The model is trained using a specific textile defect dataset, which includes various types of defects (such as holes, stains, color deviations, etc.). The hyperparameters are optimized using cross-validation to obtain a more accurate defect detection model.

[0056] S5. Applying the CFLOW-AD model for anomaly detection: The preprocessed image is input into the CFLOW-AD model. CFLOW-AD identifies subtle anomalous regions and sorts them according to their anomalous scores. The model generates an anomaly score for each pixel. Regions with high anomalous scores may indicate the presence of defects.

[0057] S6. Integrated Real-Time Feedback Mechanism: A dynamic feedback mechanism is added during the detection process. The system automatically adjusts the detection parameters, such as threshold and sensitivity, based on the preliminary detection results to ensure stable performance under different environments. The defect detection threshold is adjusted in real time based on the preliminary detection results. When a suspected defect is detected in an area, the system adjusts the detection sensitivity for a more accurate re-examination. After the preliminary detection, the system will resample and analyze the suspected area in detail to ensure the accuracy of the detection results. This helps to reduce the occurrence of missed detections and false detections.

[0058] S7. Evaluation and Post-processing: The model performance is evaluated using the main evaluation metrics of the defect detection algorithm (TP, FP, TN, FN, ROC curve), and the detection results are post-processed: denoising and connected component analysis. Based on the detection results, a detailed defect report is generated, which includes information such as the location, type, and size of each defect, to facilitate subsequent processing and quality control.

[0059] Furthermore, a machine vision-based method for detecting textile defects is proposed.

[0060] In step S3, the ResNet50 deep convolutional neural network extracts deep features of the image through layers of convolution operations. Using the SPADE algorithm, the spatial features of the image are adaptively weighted to highlight areas in the image that may have defects. The specific steps are as follows:

[0061] S31: Input the image into ResNet50 and extract key features from the image. The features are used to compare the similarity of different images and perform pixel-level alignment. The Backbone layer is the core part of feature extraction, which can efficiently extract discriminative feature representations from the input image.

[0062] S32: The first step of the SPADE algorithm is to perform k-nearest neighbor retrieval on the target image. Based on global features at the image level, it uses Euclidean distance as a metric, as shown in the following formula.

[0063] Where d(y) represents the average squared distance between the target image y and its k nearest neighbor images. These are features of the target image. It is the feature set of the K nearest neighbor normal images of the target image. yes The feature vector of a certain nearest neighbor image, that is, the feature of a certain positive sample image;

[0064] S33: The second step of the SPADE algorithm is pixel-level anomaly region localization. In this step, a feature pyramid matching strategy is implemented. It extracts feature information from various stages of the ResNet architecture to construct a hierarchical feature representation, i.e., a feature pyramid. This representation intelligently integrates detailed local features and overall global information of the image. Specifically, for each pixel location p in the target image, the algorithm extracts multi-scale features at that location and compares them with a pre-determined feature set G of the K nearest neighbor normal images. By calculating the average distance between the target pixel features and the features in set G, SPADE can effectively identify anomaly regions lacking corresponding normal features, thereby achieving accurate anomaly localization. The anomaly score calculation formula is as follows: , This represents the anomaly score at a pixel location p in the target image y. It is the multi-scale feature vector extracted from the target image y at pixel position p. In the feature space, with The feature set corresponding to pixel position p among the k most similar normal images.

[0065] Furthermore, a machine vision-based method for detecting textile defects is proposed.

[0066] In specific step S31, the core of ResNet50 is the Backbone layer. The Backbone layer extracts key features from the image. It consists of five main parts, each composed of a series of convolutional blocks, progressively abstracting and extracting image features. The initial stage of the Backbone layer is stage 0. The input image first passes through a convolutional layer with an input size of 3x224x224 pixels. A batch normalization layer is introduced to normalize the features, which helps accelerate the network's training process and improve generalization ability. A ReLU activation function is applied to the output of the BN layer to introduce non-linearity and enhance the model's expressive power. A max-pooling layer reduces the spatial size of the feature map to 56x56 pixels while retaining 64 output channels, optimizing the feature representation. Following the initial stage 0, the backbone of the network consists of four consecutive stages, from stage 1 to stage 2. The four stages all adopt the Bottleneck (BTNK) structure. The Bottleneck module is designed in two forms: one is the BTNK2 variant with the same number of input and output channels; the other is the BTNK1 variant with different numbers of input and output channels.

[0067] BTNK1 has four variable parameters: C, W, C1, and S.

[0068] C: refers to the number of channels in the input feature map, which is the scale of the input feature map in the depth direction;

[0069] W: This refers to the spatial dimension of the input feature map, namely the horizontal width and vertical height of the feature map, and its unit of measurement is pixels;

[0070] C1: Represents the number of feature maps output by the first 1x1 convolutional layer, which is the number of output channels. This value is usually a multiple of the number of input channels.

[0071] S: represents the stride used in a 3x3 convolutional layer to control the reduction in spatial resolution of the output feature map. When the stride S equals 1, the spatial size of the output feature map is the same as that of the input feature map, which means that no downsampling strategy is adopted.

[0072] In the Bottleneck structure, when the number of output channels is inconsistent with the number of input channels, we call it the BTNK1 case. Assume that the shape of the input feature map is (C, W, W) and defined as x. The left side consists of three consecutive convolutional operation units, each followed by batch normalization (BN) and ReLU activation function. This sequence can be regarded as a composite function. On the right side of this composite function, there is a separate convolutional layer whose output is added to the original input x and activated by ReLU, finally producing the output of the BTNK1 module. The feature map size of the output is (C1*4, W / S, W / S).

[0073] BTNK2: has two parameters, C and W;

[0074] C: Same as the definition in BTNK1;

[0075] W: Also represents the size of the input feature map. BTNK2 is defined when the number of output channels of the Bottleneck module is equal to the number of input channels, given an input y of shape (C, W, W).

[0076] The three convolutional units on the left (each followed by batch normalization and ReLU activation) are considered as a single function. The result of this function is accumulated with the original input x and processed by the ReLU activation function to generate the output of the BTNK2 module. The dimensions of its output feature map remain unchanged, i.e., (C, W, W). From this BTNK structure, we can see that the network's characteristic is that it skips some layers and directly adds them to the output. This is also a major feature of the ResNet network. In stage 0, an image data of (3,224,224) is received and passed sequentially through a convolutional layer with 64 7*7 convolutional kernels and a stride of 2, a BN layer, a ReLU activation function, and a max pooling layer, finally obtaining an output of (64,56,56). The subsequent stages 1 to 4 have similar functions: receiving the output from the upper layer, passing it through a BTNK1 structure, and then through several BTNK2 structures to obtain the output, which is then passed to the next layer. The final output has a feature shape of (2048,7,7).

[0077] Furthermore, a machine vision-based method for detecting textile defects is proposed.

[0078] In step S5, the preprocessed image is input into the CFLOW-AD model.

[0079] The CFLOW-AD model is shown below, and the flowchart is as follows. Figure 3 As shown, this model is a structure for anomaly detection and localization, consisting of an encoder and multiple parallel decoders. The model's workflow is as follows: The input image is preprocessed to conform to the specifications used during model training. The preprocessed image is then input into the pre-trained encoder to extract multi-scale features. Pyramid pooling is used to capture feature maps of different scales from the encoder's output. These captured feature maps are then fed into the CFLOW decoder, and likelihood estimation is performed on the feature maps at each scale in conjunction with location encoding information. The likelihood estimation results are upsampled to the original resolution of the input image and aggregated to generate an anomaly score map. A threshold is set based on the anomaly score map, and anomaly detection is performed. The exact location of the anomaly is determined by analyzing high-score regions. The detection results are then post-processed and interpreted, and reported to the user in a visual manner. This process achieves efficient anomaly detection and accurate anomaly localization for images.

[0080] Furthermore, a machine vision-based method for detecting textile defects is proposed.

[0081] In step S6, a dynamic feedback mechanism is added to the detection process. The system automatically adjusts the detection parameters, such as threshold and sensitivity, based on the preliminary detection results, as follows;

[0082] S61. Preliminary Detection and Result Generation: The system first uses a preset "initial threshold" to perform preliminary detection on the image, generating the first batch of potential defect areas; and sets the threshold: determining that a pixel is considered a defect only when its abnormal score reaches 50%; sensitivity: affecting the system's attention to subtle abnormalities;

[0083] S62. Analyze preliminary results and identify problems: The system will analyze the number, size, and distribution characteristics of these initially detected defective areas;

[0084] S63. Dynamic parameter adjustment: When there are too many false alarms: the system automatically raises the detection threshold, requiring a higher abnormal score to be identified as a defect;

[0085] Reduce sensitivity: Strong post-processing noise reduction ignores overly subtle signals that may be noise;

[0086] When there is a risk of missed detection: Lower the threshold: The system automatically lowers the detection threshold to capture more areas with slightly lower anomaly scores that may still be defective;

[0087] Improve sensitivity: Perform more detailed analysis on suspected areas, and pay more attention to the detailed information in multi-scale features;

[0088] S64. Re-evaluation and Output: The system uses the adjusted parameters to perform secondary detection and refinement on the image. This process is iterated until the detection results reach the best balance: false positives and false negatives are within acceptable ranges, and finally a more accurate defect report is generated.

[0089] Furthermore, a machine vision-based method for detecting textile defects is proposed.

[0090] In specific step S62, the system will analyze the number, size, and distribution characteristics of these initially detected defective areas, as follows;

[0091] S621. Too many false alarms: A large number of very small, scattered areas that do not conform to typical defect characteristics were detected. When the total number of detected defects far exceeds the normal level, it indicates that the initial threshold may be too low and the system is too sensitive.

[0092] S622. Risk of missed detection: The number of detected defects is unusually low, and some areas with known defects are not identified. This indicates that the initial threshold may be too high and the system is not sensitive enough.

[0093] Example 2

[0094] A large textile factory wants to automate defect detection on its high-speed fabric weaving production line to replace traditional manual visual inspection. The line produces approximately 60 meters (1.5 meters) of pure cotton plain weave fabric per minute. The system is required to identify common defects such as holes, oil stains, and color differences in real time, with a detection accuracy of no less than 95% and a false negative rate of less than 2%. The specific steps are as follows:

[0095] S1. Image Data Acquisition and Preprocessing: Two high-resolution industrial cameras (4096×3072 resolution, 30fps) are installed directly above the production line, along with a ring LED light source to ensure uniform and shadow-free illumination. The cameras are perpendicular to the fabric surface, with a shooting distance of 50cm. Synchronization triggers are used to link with the conveyor belt speed to avoid motion blur. The acquired RGB images are first cropped to the effective area (removing invalid edge areas), then uniformly scaled to 512×512 pixels, and the pixel values ​​are normalized to the [0,1] range. A Gaussian filter (σ=1.0) is applied for slight smoothing to suppress sensor noise while preserving texture details.

[0096] S2. Data Augmentation: Based on 5000 labeled defect images accumulated from the factory's history (including 1800 images of holes, 1500 images of oil stains, 1200 images of color differences, and 500 normal samples), an offline + online augmentation strategy was adopted: Offline augmentation: The original dataset was rotated by ±15°, horizontally / vertically flipped, randomly cropped (preserving 80% of the central area), and HSV color jittered (H±10, S±0.2, V±0.2); During training, random scaling (0.9–1.1 times) and brightness adjustment were dynamically applied, ultimately generating approximately 20,000 training samples, which were divided into training, validation, and test sets in an 8:1:1 ratio;

[0097] S3. Feature Extraction and Abnormal Region Identification: The preprocessed image is input into the ResNet50 backbone network to extract the feature map (size 14×14×1024) of the fourth stage (res4). The SPADE module is introduced to adaptively weight the feature channels according to the local texture complexity to enhance the response of defective regions. In the feature space, the KNN (k=5) algorithm is used to calculate the distance between each pixel and the normal sample feature library. Regions with a distance exceeding the threshold are marked as "potential anomalies".

[0098] S4. Model Training and Optimization: A transfer learning strategy was adopted: the first three stages of ResNet50 were frozen, and only the last two stages and the SPADE module were fine-tuned. Focal Loss was used as the loss function to alleviate the class imbalance problem.

[0099] S5. Applying the CFLOW-AD model for anomaly detection: Combining the trained feature extractor with CFLOW-AD: CFLOW-AD uses multi-scale features to construct a conditional flow model and learns the pixel-level distribution of normal fabric; it generates a pixel-by-pixel anomaly score map for the input image, and areas with a score >0.75 are judged as defects;

[0100] S6. Integrated Real-Time Feedback Mechanism: The system is deployed on edge computing devices with a processing latency of <80ms / frame. When the area ratio of abnormal regions output by CFLOW-AD is >0.1% but <1%, the system automatically lowers the detection threshold (from 0.75 to 0.65) and triggers local high-definition re-encoding (by controlling the camera to fine-tune the focus through a servo motor). When a suspected defect is detected in the same position in three consecutive frames, the region is locked, and a secondary analysis process is initiated (combining texture direction filtering and morphological closing operations) to reduce false alarms.

[0101] S7. Evaluation and Follow-up: During the two-week trial run, the system's detection accuracy was 97.1%, the false negative rate was 1.4%, and the false alarm rate was 2.8%. Follow-up processing phase:

[0102] The abnormal score map is binarized (threshold 0.7); combined with the fabric coordinate system, the defect location is mapped back to physical space (accuracy ±2mm), and the system automatically generates a PDF quality inspection report, including: defect type (e.g. "oil stain - round, diameter 4.2mm"), location (XX meters from the fabric, lateral offset YY cm), and severity level (based on area and type weighted score).

Claims

1. A method for detecting textile defects based on machine vision, characterized in that, Includes the following steps: S1. Acquire image data and perform preprocessing: Use a high-resolution industrial camera to capture RGB images of textiles. The position, lighting and shooting angle of the camera need to be adjusted. Perform preprocessing operations on these images: image cropping, scaling and normalization, adjust the image pixel values ​​to a uniform range: [0, 1], adjust the image size to match the input requirements of the network, and apply image smoothing and noise reduction to reduce the impact of noise. S2. Data Augmentation: After acquiring image data, data augmentation techniques such as rotation, scaling, cropping, color jittering, flipping, and mirroring are used to generate training samples; S3. Input image feature extraction and anomaly region identification: The processed image is input into the ResNet50 deep convolutional neural network. The network extracts deep features of the image through layers of convolution operations. Using the SPADE algorithm, the spatial features of the image are adaptively weighted to highlight areas in the image that may have defects. The k-nearest neighbor (KNN) algorithm is used to analyze these areas to further determine the location and size of the anomaly regions. S4. Model Training and Optimization: The transfer learning method is used to fine-tune the model on a specific textile defect dataset, and the model is trained using the specific textile defect dataset. The defect dataset includes the following types of defects: holes, stains, and color deviations. The hyperparameters are optimized using the cross-validation method to obtain the defect detection model. S5. Applying the CFLOW-AD model for anomaly detection: The preprocessed image is input into the CFLOW-AD model. CFLOW-AD identifies subtle anomalous regions and sorts them according to their anomalous scores. The model generates an anomaly score for each pixel, and regions with high anomalous scores indicate the presence of defects. S6. Integrated Real-time Feedback Mechanism: A dynamic feedback mechanism is added during the detection process. The system automatically adjusts the detection parameters, such as threshold and sensitivity, based on the preliminary detection results. The threshold for defect detection is adjusted in real time based on the preliminary detection results. When a suspected defect is detected in an area, the system adjusts the detection sensitivity for re-examination. After the preliminary detection, the system resamples and performs detailed analysis on the suspected area. S7. Evaluation and Post-processing: The main evaluation metrics of the defect detection algorithm are TP, FP, TN, FN, and ROC curves to evaluate the model performance. The detection results are then processed by denoising and connected component analysis. Based on the detection results, a detailed defect report is generated, which includes the location, type, and size information of each defect for subsequent processing and quality control.

2. The textile defect detection method based on machine vision as described in claim 1, characterized in that: In step S3, the ResNet50 deep convolutional neural network extracts deep features of the image through layers of convolution operations. Using the SPADE algorithm, the spatial features of the image are adaptively weighted to highlight areas in the image that may have defects. The specific steps are as follows: S31: Input the image into ResNet50. The core of ResNet50 is the Backbone layer, which extracts key features from the image. These features are used to compare the similarity of different images and perform pixel-level alignment. S32: The first step of the SPADE algorithm is to perform k-nearest neighbor search on the target image. Based on global features at the image level, it uses the Euclidean distance metric and the following formula: Where d(y) represents the average squared distance between the target image y and its k nearest neighbor images. These are features of the target image. It is the feature set of the k nearest neighbor normal images of the target image. yes The feature vector of a certain nearest neighbor image, that is, the feature of a certain positive sample image; S33: The second step of the SPADE algorithm is pixel-level anomaly region localization. A feature pyramid matching strategy is implemented, extracting feature information from various stages of the ResNet architecture to construct a hierarchical feature representation, i.e., a feature pyramid. For each pixel location p in the target image, multi-scale features are extracted and compared with a pre-determined feature set G of the k nearest neighbor normal images. By calculating the average distance between the target pixel features and the features in set G, SPADE identifies anomaly regions lacking corresponding normal features, achieving accurate anomaly localization. The anomaly score calculation formula is as follows: , This represents the anomaly score at a pixel location p in the target image y. It is the multi-scale feature vector extracted from the target image y at pixel position p. In the feature space, with The feature set corresponding to pixel position p among the k most similar normal images.

3. The textile defect detection method based on machine vision as described in claim 2, characterized in that: In specific step S31, the core of ResNet50 is the Backbone layer, which extracts key features from the image. The Backbone layer consists of five main parts, each composed of a series of convolutional blocks, progressively abstracting and extracting image features. The initial stage of the Backbone layer is stage 0. The input image first passes through a convolutional layer with an input size of 3x224x224 pixels. A batch normalization layer is introduced to normalize the features, accelerating the network's training process and improving generalization ability. A ReLU activation function is applied to the output of the BN layer to introduce non-linearity and enhance the model's expressive power. A max pooling layer reduces the spatial size of the feature map to 56x56 pixels while retaining 64 output channels, optimizing the feature representation. Following the initial stage 0, the backbone of the network consists of four consecutive stages, from stage 1 to stage 2. The system consists of four parts, all of which use the Bottleneck (BTNK) structure. The Bottleneck module is designed in two forms: one is the BTNK2 variant with the same number of input and output channels; the other is the BTNK1 variant with different numbers of input and output channels.

4. The textile defect detection method based on machine vision as described in claim 1, characterized in that: In step S5, the preprocessed image is input into the CFLOW-AD model. The CFLOW-AD model, as shown below, preprocesses the input image to conform to the specifications used during model training. The preprocessed image is then input into a pre-trained encoder to extract multi-scale features. Pyramid pooling is used to capture feature maps of different scales from the encoder's output. These captured feature maps are fed into the CFLOW decoder, and likelihood estimation is performed on each scale feature map in conjunction with location encoding information. The likelihood estimation results are upsampled to the original resolution of the input image and aggregated to generate an anomaly score map. A threshold is set based on the anomaly score map to perform anomaly detection. The exact location of the anomaly is determined by analyzing high-score regions. The detection results are then post-processed and interpreted, and reported to the user in a visual manner.

Citation Information

Patent Citations

  • Method for automatically detecting and classifying textile flaws based on pattern recognition and image processing

    CN102879401A

  • High-capacity controllable carrier-free image steganography method

    CN113947512A