Image Processing-Based Fabric Defect Recognition Method and System
By constructing global and local texture features of the fabric, combining hierarchical clustering and autoencoders, and employing an adaptive region growing method, the accuracy problem in fabric defect identification is solved, achieving high-precision and robust defect detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NINGBO OUMEISHENG KNITTING CO LTD
- Filing Date
- 2026-04-10
- Publication Date
- 2026-06-30
AI Technical Summary
Existing technologies have poor accuracy in fabric defect identification, and are prone to missed detections and false detections, especially in complex and smooth areas of jacquard knitted fabrics.
By extracting global and local texture features of the fabric, regional feature vectors are constructed. Hierarchical clustering and convolutional autoencoders are used to identify fabric defects, and an adaptive region growing method is combined to identify defect regions.
It significantly improves the accuracy and robustness of fabric defect detection, can adapt to different fabric texture characteristics, and reduces false detections and missed detections.
Smart Images

Figure CN121998995B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of fabric defect recognition technology. In particular, it relates to a fabric defect recognition method and system based on image processing. Background Technology
[0002] With the rapid development of machine vision technology, automatic defect detection methods based on image processing are gradually being applied in the textile industry. However, in actual industrial scenarios, jacquard knitted fabrics exhibit significant texture heterogeneity. A single piece of fabric can simultaneously contain solid-color areas, jacquard areas, and mixed solid-color and jacquard areas, and defects can appear in any area with diverse forms. Furthermore, the natural texture fluctuations of normal fabrics and the characteristics of minor defects are relatively similar, making it difficult to effectively distinguish them using a single feature.
[0003] Existing technologies typically address these issues by using a fixed window, fixed analysis scale, and fixed model parameters to perform uniform detection on all fabrics and all regions. However, these methods have the following drawbacks: they cannot adapt to differences in texture complexity between different fabrics, resulting in poor model generalization ability; they cannot adapt to the texture characteristics of different regions within the same fabric, making it difficult to guarantee detection accuracy; they are prone to false detections in areas with complex textures, and easily miss subtle defects in areas with smooth textures.
[0004] Therefore, there is a need in this field for a fabric defect identification method and system based on image processing to solve the problems of poor defect identification accuracy in existing technologies, which easily leads to missed detections and false detections. Summary of the Invention
[0005] To address the technical problems of poor defect identification accuracy in the existing technology, which easily leads to missed detections and false detections, the present invention provides solutions in the following aspects.
[0006] In the first aspect, the fabric defect identification method based on image processing includes:
[0007] Normal images of different types of jacquard knitted fabrics are acquired and grayscale images are obtained by performing grayscale processing. Global texture features are extracted from the grayscale images, and adaptive magnification processing is performed on the grayscale images based on the global texture features to obtain preprocessed normal grayscale images.
[0008] Multiple window images are obtained by sliding sampling of a normal grayscale image using a window of uniform size. Multi-scale wavelet decomposition is performed on each window image to determine its optimal decomposition level. By combining global texture features and texture features corresponding to the optimal decomposition level, a regional feature vector for each window image is constructed. Hierarchical clustering is performed based on the regional feature vectors to obtain multiple clusters. A convolutional autoencoder is trained for each cluster, and the reconstruction error of each pixel after reconstruction of all window images in each cluster by the convolutional autoencoder is calculated to establish a benchmark library for reconstruction error distribution.
[0009] Images of the jacquard knitted fabric to be inspected are acquired. The images to be inspected are subjected to the same preprocessing and sliding sampling as normal images to obtain multiple inspection window images. The region feature vector of each inspection window image is constructed using the same construction method as the window images, and clusters are matched according to the region feature vectors. The inspection window images are input into the convolutional autoencoder of their matched clusters to obtain reconstruction error maps. Combined with the reconstruction error distribution benchmark library of clusters, defect regions in the inspection window images are identified and extracted by an adaptive region growing method.
[0010] Preferably, adaptive magnification processing of grayscale images based on global texture features includes: performing local binary mode encoding on the grayscale image to generate an encoded map; statistically analyzing the probability of each encoded value appearing in the encoded map, calculating the entropy value of the encoded map and normalizing it to obtain global texture features; presetting a maximum magnification ratio and a minimum magnification ratio, calculating the difference between the maximum magnification ratio and the minimum magnification ratio, calculating the product of the difference and the global texture features, and calculating the sum of the product and the minimum magnification ratio, rounding the sum down to obtain the upsampling ratio, and magnifying the grayscale image based on the upsampling ratio to obtain a normal grayscale image.
[0011] Preferably, performing multi-scale wavelet decomposition on each window image and determining its optimal decomposition layer number includes: performing continuous-scale orthogonal wavelet decomposition on the window image to obtain the low-frequency sub-band and multiple high-frequency sub-bands in multiple directions corresponding to each layer; calculating the rate of change of energy of the low-frequency sub-bands of two adjacent decomposition layers, and taking the decomposition layer whose rate of change is first less than a preset threshold as the optimal decomposition layer number; if all rates of change are greater than or equal to the preset threshold, then selecting the layer with the smallest difference between the rate of change and the preset threshold as the optimal decomposition layer number.
[0012] Preferably, constructing the region feature vector for each window image includes: calculating the ratio of the sum of the energy of the high-frequency subbands corresponding to the optimal decomposition level of the window image to the sum of the energy of all subbands, to obtain the region texture complexity; calculating the ratio of the energy of each high-frequency subband corresponding to the optimal decomposition level to the sum of the energy of all high-frequency subbands, to obtain the energy proportion of each high-frequency subband; the optimal decomposition level of the global texture features of the grayscale image to which the window image belongs, the region texture complexity of the window image, and the energy proportion of each high-frequency subband together constitute the region feature vector of the window image.
[0013] Preferably, hierarchical clustering based on region feature vectors includes: using the Euclidean distance between the region feature vectors of any two window images as a similarity measure, constructing a clustering tree using a bottom-up agglomerative hierarchical clustering algorithm; starting from the root node of the clustering tree, performing a top-down traversal; for the cluster corresponding to the currently traversed node, if the maximum Euclidean distance between the region feature vectors of all window images within the cluster is less than a preset value, stopping the splitting of the cluster; otherwise, continuing the downward traversal; and forming the final cluster set by all clusters corresponding to the nodes where splitting has stopped.
[0014] Preferably, establishing a reconstruction error distribution benchmark library includes: for each cluster in the final cluster set, inputting the window image within the cluster into the corresponding convolutional autoencoder to generate a reconstructed image corresponding to the window image; calculating the absolute difference of each pixel between each window image and its reconstructed image as the reconstruction error of that pixel; and statistically analyzing the mean and standard deviation of the reconstruction error of each pixel in all window images to serve as the reconstruction error distribution benchmark library for that cluster.
[0015] Preferably, identifying and extracting defect regions in the window image to be inspected using an adaptive region growing method includes: calculating the region texture complexity of the window image to be inspected, and calculating the number of seed points based on the region texture complexity; selecting seed points based on the reconstruction error of each pixel in the reconstruction error map of the window image to be inspected and the Euclidean distance between each pair of pixels; starting region growing in parallel from all seed points, for any neighboring pixel of each seed point, when the neighboring pixel meets the growth condition, the neighboring pixel is included in the defect region and used as a new seed point to continue expanding; stopping growth when no new neighboring pixel meets the growth condition or the area of the defect region exceeds the preset maximum growth area, thereby obtaining a defect region mask of the window image to be inspected.
[0016] Preferably, the growth condition is that the reconstruction error of a neighboring pixel is greater than or equal to the region growth threshold of that neighboring pixel. The calculation method for the region growth threshold of each pixel includes: calculating the local texture complexity of the pixel based on the energy of the pixel in the low-frequency subband and high-frequency subband corresponding to the optimal decomposition layer of the image to be inspected; adding the local texture complexity of the pixel to a preset benchmark coefficient to obtain the growth threshold coefficient; obtaining the mean and standard deviation of the reconstruction error of normal pixels at the corresponding position of the pixel from the reconstruction error distribution benchmark library of the cluster matched by the image to be inspected, and calculating the sum of the product of the standard deviation and the growth threshold coefficient and the mean to obtain the region growth threshold of the pixel.
[0017] Preferably, after obtaining the defect region mask of the window image to be inspected, the method further includes: for any pixel on the image to be inspected, as long as it is marked as a defect in any defect region mask of the window image to be inspected that covers the pixel, the pixel is marked as a defect in the final fusion result, and a fused defect mask is finally obtained; morphological opening operation is performed on the fused defect mask to remove isolated noise points, and then morphological closing operation is performed to fill the small holes in the defect region; connected component analysis is performed on the processed fused defect mask to obtain a continuous and complete defect region.
[0018] Secondly, an image processing-based fabric defect recognition system includes a processor and a memory, wherein the memory stores computer program instructions, and when the computer program instructions are executed by the processor, the above-mentioned image processing-based fabric defect recognition method is implemented.
[0019] The present invention has the following effects:
[0020] 1. This invention extracts global texture features that reflect the overall weaving style of the fabric and combines them with local texture features based on wavelet decomposition to construct regional feature vectors, giving each window image a unique identity fingerprint. Through hierarchical clustering, it can automatically divide different fabric types and different texture regions on the same fabric into different clusters, laying the foundation for subsequent partitioning modeling and solving the problem that traditional methods cannot adapt to the texture characteristics of various fabrics.
[0021] 2. This invention trains a convolutional autoencoder independently for each cluster and establishes a pixel-level reconstruction error distribution benchmark library, so that subsequent detection can use the normal standard of the cluster itself to measure the image to be detected that matches the cluster, avoiding misjudgment caused by using a uniform standard to measure all texture types.
[0022] 3. In the detection stage, this invention dynamically adjusts the region growth threshold of each pixel based on the local texture complexity of the image to be inspected, so that the judgment standard varies from point to point. The region growth threshold of the texture complex area is increased accordingly to avoid normal fluctuations being misjudged as defects. The region growth threshold of the texture smooth area is appropriately reduced to improve the sensitivity to minor defects. At the same time, the region growth threshold integrates the statistical regularity of the pixel position under normal conditions, so that the judgment not only conforms to historical standards, but also adapts to the current local texture changes, which significantly improves the accuracy and robustness of defect detection. Attached Figure Description
[0023] Figure 1 This is a flowchart of steps S1-S5 in the fabric defect identification method based on image processing according to an embodiment of the present invention.
[0024] Figure 2 This is a flowchart of steps S50-S53 in the fabric defect identification method based on image processing according to an embodiment of the present invention. Detailed Implementation
[0025] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are some embodiments of the present invention, but not all embodiments.
[0026] The specific embodiments of the present invention will now be described in detail with reference to the accompanying drawings.
[0027] Reference Figure 1 The fabric defect identification method based on image processing includes steps S1-S5, as follows:
[0028] S1: Collect normal images of different types of jacquard knitted fabrics, perform grayscale processing to obtain grayscale images; extract global texture features from the grayscale images, and perform adaptive magnification processing on the grayscale images based on the global texture features to obtain preprocessed normal grayscale images.
[0029] Industrial line scan cameras installed above the industrial fabric inspection production line capture normal images of different types of jacquard knitted fabrics, forming a normal image set. Different types of jacquard knitted fabrics refer to jacquard knitted fabrics with different weaving processes and jacquard patterns. The normal image set consists of images of jacquard knitted fabrics collected during the fabric inspection process on the industrial production line that have been verified to have no fabric defects. The purpose of introducing different types of jacquard knitted fabrics is to adapt to the common defect identification needs of industrial production lines when producing different types of jacquard knitted fabrics.
[0030] Using existing weighted grayscale algorithms, normal images are processed to convert three-channel color images into single-channel grayscale images.
[0031] For each grayscale image, LBP (Local Binary Pattern) encoding is performed on the grayscale image to generate an LBP encoded map. The LBP algorithm is a classic method for image texture analysis. Its basic principle is to take each pixel as the center, compare its grayscale relationship with neighboring pixels, and generate a binary code to represent the local texture structure.
[0032] The probability of each LBP value appearing in the LBP encoded image is statistically analyzed. The LBP histogram entropy is calculated using the Shannon entropy formula. The LBP histogram entropy is then normalized to obtain the global texture features. The larger the global texture features, the more dispersed the LBP encoding distribution, and the stronger the randomness of the image texture. This effectively distinguishes jacquard knitted fabrics with different weaving techniques and jacquard patterns.
[0033] The maximum and minimum magnification ratios are preset. The difference between the maximum and minimum magnification ratios is calculated. This difference is then multiplied by the global texture features, and the sum of this product and the minimum magnification ratio is calculated. This sum is rounded down to obtain the upsampling ratio. The grayscale image is then magnified based on this upsampling ratio to obtain a normal grayscale image. The specific formula is as follows:
[0034]
[0035] In the formula, Indicates the upsampling factor of a grayscale image; This indicates the preset minimum magnification, which can be set to a minimum of [value missing]. To ensure that grayscale images are not scaled down, This indicates the preset maximum magnification. and Adjustable based on needs; Represents the global texture features of a grayscale image.
[0036] Global texture features The larger the size, the finer the fabric texture, and the more necessary it is to enlarge the size to clearly capture the texture details; therefore, the upsampling magnification needs to be increased. The greater the need.
[0037] After all grayscale images undergo the above preprocessing, a normal grayscale image set is obtained.
[0038] By adaptively adjusting the upsampling rate based on the global texture features of the grayscale image, fabrics with fine textures can achieve higher resolution, while fabrics with coarse textures are prevented from being over-magnified. This provides a higher quality data foundation for subsequent processing steps and indirectly improves the overall defect detection accuracy.
[0039] S2: Multiple window images are obtained by sliding sampling of a normal grayscale image using a window of uniform size; multi-scale wavelet decomposition is performed on each window image and its optimal decomposition level is determined. The region feature vector of each window image is constructed by combining global texture features and texture features corresponding to the optimal decomposition level.
[0040] Multiple window images are obtained by sliding sampling of each normal grayscale image using a window of uniform size. The size of the window is determined according to the actual industrial inspection requirements. For example, the window size can be set to 10% of the smallest normal grayscale image in the set of normal grayscale images. The sliding step size can be set to 50% of the window size.
[0041] For each window image, calculate the range of decomposition layers based on the window size (e.g., layer, (representing the window size), perform continuous-scale orthogonal wavelet decomposition on each window image based on the decomposition layer range. The optional wavelet basis function is the db4 wavelet. Each layer corresponds to a low-frequency sub-band and three high-frequency sub-bands in three directions, namely the horizontal high-frequency sub-band (LH, Low-High), the vertical high-frequency sub-band (HL, High-Low), and the diagonal high-frequency sub-band (HH, High-High).
[0042] For each decomposition layer, the low-frequency subband and the high-frequency subbands in three directions corresponding to the window image are extracted, and the energy of the low-frequency subband and the high-frequency subbands in the three directions is calculated respectively. The low-frequency subband energy reflects the overall texture structure of the image, and the high-frequency subband energy reflects the texture details of the image. The rate of change of the low-frequency subband energy of each decomposition layer is calculated. The decomposition layer whose rate of change is first less than a preset threshold (which can be adjusted in the range of 0.2~0.5 according to the detection accuracy requirements, and is preferably 0.3 in this embodiment) is taken as the optimal decomposition layer. If the rate of change of the low-frequency subband energy of all decomposition layers is greater than or equal to the preset threshold, the decomposition layer with the smallest difference between the rate of change and the preset threshold is selected as the optimal decomposition layer. If multiple decomposition layers have the smallest difference between the rate of change and the preset threshold, the decomposition layer with the smallest difference is taken as the optimal decomposition layer.
[0043] The formula for calculating the rate of change of low-frequency subband energy for each decomposition level is as follows:
[0044]
[0045] In the formula, Indicates the first The rate of change of low-frequency subband energy for each decomposition layer; Indicates the first The low-frequency subband energy of each decomposition layer; Indicates the first The low-frequency subband energy of each decomposition layer. Starting from the second decomposition layer, the rate of change is checked layer by layer to see if it is less than a preset threshold.
[0046] The optimal decomposition layer determined by the above method can adaptively reflect the texture complexity of the window image. The smaller the optimal decomposition layer, the simpler the image texture (such as plain areas); the larger the optimal decomposition layer, the more complex the image texture (such as jacquard areas or mixed areas), providing a basis for subsequent region classification and defect detection.
[0047] The region texture complexity is obtained by calculating the ratio of the sum of the energy of the three high-frequency subbands corresponding to the optimal decomposition level to the sum of the energy of the three high-frequency subbands and the low-frequency subbands. The energy ratio of each high-frequency subband is obtained by calculating the ratio of the energy of each high-frequency subband to the sum of the energy of the three high-frequency subbands. The global texture features of the grayscale image to which the window image belongs, the optimal decomposition level of the window image, the region texture complexity, and the energy ratios of the three high-frequency subbands (the energy ratios of the horizontal high-frequency subbands, the vertical high-frequency subbands, and the diagonal high-frequency subbands) together constitute the region feature vector of the window image.
[0048] S3: Perform hierarchical clustering based on regional feature vectors to obtain multiple clusters; train a convolutional autoencoder for each cluster, and calculate the reconstruction error of each pixel after reconstruction of all window images in each cluster by the convolutional autoencoder, and establish a benchmark library for reconstruction error distribution.
[0049] After obtaining the region feature vectors of all window images for each normal grayscale image in the normal grayscale image set, a bottom-up agglomerated hierarchical clustering algorithm is used to construct a cluster tree, with the Euclidean distance between the region feature vectors of any two window images as the similarity measure. Starting from the root node of the cluster tree, a top-down traversal is performed. For the cluster corresponding to the currently traversed node, if the maximum Euclidean distance between the region feature vectors of all window images within that cluster is less than a preset value, the splitting of that cluster is stopped; otherwise, the traversal continues downwards. All clusters corresponding to nodes where splitting has stopped form the final cluster set. Each cluster corresponds to a "specific fabric and specific texture region," for example: solid color area of fabric A, jacquard area of fabric A, and jacquard area of fabric B.
[0050] The global texture features in the region feature vector reflect the overall weaving style of the fabric. Therefore, during clustering, the hierarchical clustering algorithm will keenly capture the difference brought about by the global texture features, thereby dividing fabrics with different weaving styles into two clusters and achieving fabric differentiation.
[0051] For each cluster in the final cluster set, a convolutional autoencoder is trained using all window images within that cluster as training samples and minimizing the reconstruction error as the training objective. The specific training process is existing technology and will not be elaborated here.
[0052] For each cluster that has been trained, the window images within the cluster are input into the corresponding convolutional autoencoder to generate the reconstructed image corresponding to the window image; the absolute difference of each pixel between each window image and its reconstructed image is calculated as the reconstruction error of that pixel; the mean and standard deviation of the reconstruction error of each pixel in all window images are calculated as the reconstruction error distribution benchmark library for that cluster.
[0053] Different clusters correspond to different texture types (such as solid color areas, jacquard areas, and mixed areas), and their reconstruction error statistical patterns differ significantly. For example, the reconstruction error of solid color area clusters is generally small and stable, and their reconstruction error distribution benchmark library shows a small mean and standard deviation. The reconstruction error of jacquard area clusters may be larger and fluctuate, and their reconstruction error distribution benchmark library shows a larger mean and standard deviation. The reconstruction error distribution benchmark library of mixed area clusters has characteristics between the two. Establishing an independent reconstruction error distribution benchmark library for each cluster allows subsequent detection to use the normal standards of that cluster to evaluate images matched to that cluster, avoiding misjudgments caused by using a uniform standard to evaluate all texture types.
[0054] S4: Acquire images of the jacquard knitted fabric to be inspected, perform the same preprocessing and sliding sampling as normal images on the images to be inspected to obtain multiple window images to be inspected; construct the region feature vector of each window image to be inspected using the same construction method as the window images, and match clusters based on the region feature vectors.
[0055] Images of the jacquard knitted fabric to be inspected are acquired using a line scan camera on the industrial fabric inspection production line. The images are preprocessed to obtain grayscale images. Multiple window images are obtained by sliding sampling using a window of uniform size. The regional feature vector of each window image is obtained. The Euclidean distance between the regional feature vector of the window image and the central feature vector of each cluster in the final cluster set is calculated. The cluster corresponding to the smallest Euclidean distance is selected as the matching cluster of the window image.
[0056] The process of obtaining the region feature vectors of the grayscale image to be inspected, the window image to be inspected, and the window image to be inspected is the same as the process of obtaining the region feature vectors of the normal grayscale image, the window image, and the window image mentioned above, and will not be repeated here.
[0057] S5: Input the image of the window to be inspected into the convolutional autoencoder of its matching cluster to obtain the reconstruction error map. Combine the reconstruction error distribution benchmark library of the cluster, and identify and extract the defect region in the image of the window to be inspected through the adaptive region growing method.
[0058] For each window image to be inspected, the window image is input into the convolutional autoencoder of the matching cluster, and the reconstructed image is output. The absolute difference between each pixel of the window image to be inspected and its reconstructed image is calculated as the reconstruction error of each pixel, and the reconstruction error map is obtained.
[0059] Reference Figure 2 The process of identifying and extracting defect regions in the image of the window to be inspected using an adaptive region growing method includes steps S50-S53, as follows:
[0060] S50: Obtain the regional texture complexity of the image to be inspected, and calculate the number of seed points based on the regional texture complexity; select seed points based on the reconstruction error of each pixel in the reconstruction error map of the image to be inspected and the Euclidean distance between each pair of pixels.
[0061] After obtaining the reconstruction error map of the window image to be inspected, several pixels need to be selected as the starting point (i.e., seed points) for region growth. In order to ensure that the seed points can effectively cover the potential defect area and avoid excessive aggregation of seed points, this invention dynamically determines the number of seed points according to the regional texture complexity of the window image to be inspected, and optimizes and filters the seed points according to the reconstruction error and spatial distance.
[0062] Obtain the region texture complexity of the window image to be inspected (using the same method as calculating the region texture complexity of the window image), and calculate the number of seed points based on this region texture complexity; arrange all pixels on the reconstruction error map in descending order of reconstruction error, select the same number of pixels as the number of seed points from the beginning of the queue as candidate seeds, calculate the Euclidean distance between any two candidate seeds, and when the Euclidean distance is less than the preset distance (which can be set according to the size of the window image to be inspected), remove the candidate seed with the smaller reconstruction error, and add the pixel with the largest reconstruction error from the remaining pixels in the queue as a candidate seed. Iterate the above process until the Euclidean distance between all candidate seeds is greater than or equal to the preset distance, and obtain various sub-points.
[0063] These seed points are located in areas with large reconstruction errors, pointing towards potential defect areas, and the seed points are kept at a sufficient distance from each other to avoid clustering in the same local area.
[0064] Calculating the number of seeds based on the texture complexity of the region includes: setting a preset number of base seed points, calculating the sum of 1 and the region's texture complexity, multiplying this sum by the number of base seed points, and rounding the product up to obtain the number of seed points. In this embodiment, the number of base seed points is 5. Regions with more complex textures (such as jacquard areas) require more seed points to ensure sufficient coverage of potential defects; regions with simpler textures (such as solid-color areas) require fewer seed points to avoid computational redundancy.
[0065] S51: Calculate the region growth threshold for each pixel in the image to be inspected.
[0066] Taking any pixel in the image to be inspected as the target pixel, the local texture complexity of the target pixel is calculated based on the energy of the low-frequency subband and three high-frequency subbands corresponding to the optimal decomposition level of the image to be inspected. The local texture complexity of the target pixel is then added to a preset benchmark coefficient (the benchmark coefficient can be 2, constraining the growth threshold coefficient to a normal range to avoid excessive fluctuations in the growth threshold coefficient leading to false detections or false negatives) to obtain the growth threshold coefficient. The mean and standard deviation of the reconstruction error of normal pixels at the corresponding position of the target pixel are obtained from the reconstruction error distribution benchmark library of the matching cluster. The product of the standard deviation and the growth threshold coefficient and the sum of the mean are calculated to obtain the region growth threshold of the target pixel. Similarly, the region growth threshold of all pixels in the image to be inspected can be obtained. The formula for calculating the region growth threshold of the target pixel is as follows:
[0067]
[0068] In the formula, This represents the region growth threshold for the target pixel; This represents the mean of the reconstruction error of the normal pixels at the corresponding position of the target pixel; This represents the preset baseline coefficient; Indicates the local texture complexity of the target pixel; It represents the standard deviation of the reconstruction error of the normal pixels at the corresponding position of the target pixel.
[0069] The method for calculating the local texture complexity of the target pixel includes: finding the position point of the target pixel in the low-frequency sub-band and three high-frequency sub-bands corresponding to the optimal decomposition level of the image to be inspected; for each sub-band of the low-frequency sub-band and the three high-frequency sub-bands, constructing a selection window of a preset size centered on the position point corresponding to the target pixel (e.g., ...). (Selection window of size), calculate the sum of squares of the pixel values of all pixels within the selection window to obtain the energy of the target pixel in each sub-band; calculate the ratio of the sum of the energy of the target pixel in the three high-frequency sub-bands to the sum of the energy in all sub-bands to obtain the local texture complexity of the target pixel.
[0070] S52: Start region growth in parallel from all seed points, and set growth conditions based on the region growth threshold. After growth stops, obtain the defect region mask of the window image to be inspected.
[0071] Centered on the seed point, a four-connected neighborhood is used as the growth unit, including adjacent pixels in the four directions: top, bottom, left, and right. The energy proportions of the horizontal and vertical high-frequency subbands of the image to which the target pixel belongs are calculated and normalized. The normalized value of the energy proportion of the horizontal high-frequency subband is used as the growth weight of the left and right neighborhoods, and the normalized value of the energy proportion of the vertical high-frequency subband is used as the growth weight of the top and bottom neighborhoods.
[0072] During the region growing process, when the growth weight of the left and right neighbors is greater than that of the growth weight of the top and bottom neighbors, growth is prioritized in the upward and downward directions, that is, the left and right neighbor pixels are checked first to see if they meet the growth conditions; when the growth weight of the top and bottom neighbors is greater than that of the left and right neighbors, growth is prioritized in the left and right directions; when the two are equal, the method of growing in all four directions at the same time is adopted.
[0073] Region growth begins in parallel from all seed points. Each seed point maintains a queue to be expanded. For any neighboring pixel of each seed point, if the neighboring pixel meets the growth condition, it is included in the defect region and added to the queue as a new seed point; otherwise, it is not included and growth in the direction to which the neighboring pixel belongs is stopped. The growth condition is that the reconstruction error of the neighboring pixel is greater than or equal to the region growth threshold of the neighboring pixel.
[0074] The region growth process stops when any of the following conditions are met: none of the seed points in the queue to be expanded have neighboring pixels that meet the growth conditions, indicating that they have grown to the edge of the normal texture region; or the area of the defect region exceeds the preset maximum growth area (e.g., 30% of the area of the window image to be inspected). This condition serves as a safety mechanism to prevent the region from growing indefinitely due to model failure or noise interference, thus misjudging large areas of normal regions as defects.
[0075] After growth stops, a defect region mask is obtained from the image to be inspected. The mask is a binary image with the same size as the image to be inspected, where: a pixel value of 1 represents a pixel identified as a defect; a pixel value of 0 represents a normal texture area.
[0076] By constructing an independent region growth threshold for each pixel in the image to be inspected, pixel-level fine-grained judgment is achieved. The region growth threshold for each pixel is dynamically adjusted based on its local texture complexity. The region growth threshold for complex texture regions is increased accordingly to avoid misjudging normal fluctuations as defects; the region growth threshold for smooth texture regions is appropriately decreased to improve the sensitivity to subtle defects. At the same time, the region growth threshold also incorporates the mean and standard deviation of the reconstruction error at that pixel location under normal conditions, so that the judgment criteria not only conform to the statistical regularity of that location, but also adapt to the current local texture changes. This improves the ability of the region growth process to distinguish between normal texture fluctuations and real defects, and significantly improves the accuracy and robustness of defect detection.
[0077] S53: Fusion and post-processing of the defect area masks of all the images to be inspected to obtain a continuous and complete defect area on the entire image to be inspected.
[0078] After obtaining the defect area masks of all the images to be inspected, the segmentation results of these independent images to be inspected need to be fused and post-processed to obtain a continuous and complete defect area on the entire image to be inspected.
[0079] Since the images to be inspected are obtained through sliding window sampling, there are overlapping areas between adjacent images. The same pixel may be covered by multiple images and assigned different judgment results in the defect region masks of different images (some images are judged as defects, and some are judged as normal). To ensure that no defects are missed, for any pixel in the image to be inspected, if it is marked as a defect in any defect region mask of the image to be inspected that covers the pixel, then the pixel is marked as a defect in the final fusion result, and the fused defect mask is finally obtained.
[0080] Morphological operations are performed on the fused defect mask. First, the opening operation of 3×3 structuring elements is used to remove isolated noise points, and then the closing operation of 3×3 structuring elements is used to fill the tiny holes in the defect area. Finally, the continuous and complete defect area is obtained through connected component analysis.
[0081] This application also discloses a fabric defect recognition system based on image processing. The system includes a processor and a memory. The memory stores computer program instructions. When the computer program instructions are executed by the processor, the fabric defect recognition method based on image processing according to the above embodiments of the present invention is implemented.
[0082] The system also includes other components well known to those skilled in the art, such as communication buses and communication interfaces, the settings and functions of which are known in the art and will not be described in detail here.
[0083] It should be noted that those skilled in the art can make various modifications and improvements without departing from the inventive concept, and these all fall within the scope of protection of this invention. Therefore, the scope of protection of this patent should be determined by the appended claims.
Claims
1. A fabric defect identification method based on image processing, characterized in that, include: Normal images of different types of jacquard knitted fabrics are acquired and grayscale images are obtained by performing grayscale processing. Global texture features are extracted from the grayscale images, and adaptive magnification processing is performed on the grayscale images based on the global texture features to obtain preprocessed normal grayscale images. Multiple window images are obtained by sliding sampling of a normal grayscale image using a window of uniform size. Multi-scale wavelet decomposition is performed on each window image to determine its optimal decomposition level. By combining global texture features and texture features corresponding to the optimal decomposition level, a regional feature vector for each window image is constructed. Hierarchical clustering is performed based on the regional feature vectors to obtain multiple clusters. A convolutional autoencoder is trained for each cluster, and the reconstruction error of each pixel after reconstruction of all window images in each cluster by the convolutional autoencoder is calculated to establish a benchmark library for reconstruction error distribution. Images of the jacquard knitted fabric to be inspected are acquired. The images to be inspected are subjected to the same preprocessing and sliding sampling as normal images to obtain multiple inspection window images. The region feature vector of each inspection window image is constructed using the same construction method as the window images, and clusters are matched based on the region feature vectors. The image of the window to be inspected is input into the convolutional autoencoder of its matching cluster to obtain the reconstruction error map. Combined with the reconstruction error distribution benchmark library of the cluster, the defect region in the image of the window to be inspected is identified and extracted by the adaptive region growing method.
2. The fabric defect identification method based on image processing according to claim 1, characterized in that, Adaptive upscaling of grayscale images based on global texture features includes: encoding the grayscale image using local binary mode to generate an encoded map; statistically analyzing the probability of each encoded value appearing in the encoded map, calculating the entropy value of the encoded map and normalizing it to obtain global texture features; presetting a maximum magnification ratio and a minimum magnification ratio, calculating the difference between the maximum and minimum magnification ratios, calculating the product of this difference and the global texture features, and calculating the sum of this product and the minimum magnification ratio, rounding down the sum to obtain the upsampling ratio, and upscaling the grayscale image based on the upsampling ratio to obtain a normal grayscale image.
3. The fabric defect identification method based on image processing according to claim 1, characterized in that, The process of performing multi-scale wavelet decomposition on each window image and determining its optimal number of decomposition layers includes: performing continuous-scale orthogonal wavelet decomposition on the window image to obtain the low-frequency sub-band and multiple high-frequency sub-bands in multiple directions corresponding to each layer; calculating the rate of change of energy of the low-frequency sub-bands of two adjacent decomposition layers, and taking the decomposition layer whose rate of change is first less than a preset threshold as the optimal number of decomposition layers; if all rates of change are greater than or equal to the preset threshold, then selecting the layer with the smallest difference between the rate of change and the preset threshold as the optimal number of decomposition layers.
4. The fabric defect identification method based on image processing according to claim 3, characterized in that, Constructing the region feature vector for each window image includes: calculating the ratio of the sum of the energy of the high-frequency subbands corresponding to the optimal decomposition level of the window image to the sum of the energy of all subbands, thus obtaining the region texture complexity; calculating the ratio of the energy of each high-frequency subband corresponding to the optimal decomposition level to the sum of the energy of all high-frequency subbands, thus obtaining the energy proportion of each high-frequency subband; the optimal decomposition level of the global texture features of the grayscale image to which the window image belongs, the region texture complexity of the window image, and the energy proportion of each high-frequency subband together constitute the region feature vector of the window image.
5. The fabric defect identification method based on image processing according to claim 1, characterized in that, Hierarchical clustering based on region feature vectors includes: using the Euclidean distance between the region feature vectors of any two window images as a similarity measure, constructing a clustering tree using a bottom-up agglomerative hierarchical clustering algorithm; starting from the root node of the clustering tree, performing a top-down traversal; for the cluster corresponding to the currently traversed node, if the maximum Euclidean distance between the region feature vectors of all window images within the cluster is less than a preset value, stopping the splitting of the cluster; otherwise, continuing the downward traversal; and forming the final cluster set by all clusters corresponding to the nodes where splitting has stopped.
6. The fabric defect identification method based on image processing according to claim 5, characterized in that, The establishment of a reconstruction error distribution benchmark library includes: for each cluster in the final cluster set, inputting the window image within the cluster into the corresponding convolutional autoencoder to generate the reconstruction image corresponding to the window image; calculating the absolute difference of each pixel between each window image and its reconstruction image as the reconstruction error of that pixel; and statistically analyzing the mean and standard deviation of the reconstruction error of each pixel in all window images to serve as the reconstruction error distribution benchmark library for that cluster.
7. The fabric defect identification method based on image processing according to claim 1, characterized in that, Identifying and extracting defect regions in an inspection window image using an adaptive region growing method includes: calculating the region texture complexity of the inspection window image and calculating the number of seed points based on this texture complexity; selecting seed points based on the reconstruction error of each pixel in the reconstruction error map of the inspection window image and the Euclidean distance between each pair of pixels; starting region growing in parallel from all seed points; for any neighboring pixel of each seed point, if the neighboring pixel meets the growth condition, the neighboring pixel is included in the defect region and used as a new seed point to continue expanding; stopping growth when no new neighboring pixels meet the growth condition or the area of the defect region exceeds the preset maximum growth area, thus obtaining a defect region mask of the inspection window image.
8. The fabric defect identification method based on image processing according to claim 7, characterized in that, The growth condition is that the reconstruction error of a neighboring pixel is greater than or equal to the region growth threshold of that neighboring pixel. The calculation method of the region growth threshold of each pixel includes: calculating the local texture complexity of the pixel based on the energy of the pixel in the low-frequency subband and high-frequency subband corresponding to the optimal decomposition layer of the image to be inspected; adding the local texture complexity of the pixel to a preset benchmark coefficient to obtain the growth threshold coefficient; obtaining the mean and standard deviation of the reconstruction error of the normal pixels at the corresponding position of the pixel from the reconstruction error distribution benchmark library of the cluster matched by the image to be inspected, and calculating the sum of the product of the standard deviation and the growth threshold coefficient and the mean to obtain the region growth threshold of the pixel.
9. The fabric defect identification method based on image processing according to claim 7, characterized in that, After obtaining the defect region mask of the window image to be inspected, the process further includes: for any pixel on the image to be inspected, if it is marked as a defect in any defect region mask of the window image to be inspected that covers the pixel, then the pixel is marked as a defect in the final fusion result, and the fused defect mask is finally obtained; morphological opening operation is performed on the fused defect mask to remove isolated noise points, and then morphological closing operation is performed to fill the small holes in the defect region; connected component analysis is performed on the processed fused defect mask to obtain a continuous and complete defect region.
10. A fabric defect recognition system based on image processing, characterized in that, include: A processor and a memory, the memory storing computer program instructions that, when executed by the processor, implement the fabric defect identification method based on image processing according to any one of claims 1-9.