A method and system for detecting defects in a blended fabric

CN123015507APending Publication Date: 2026-10-30四川亚缇纺织科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611303393.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-26
Publication Date
2026-10-30

AI Technical Summary

Technical Problem

[0004]因此,现有技术无法实现疵点的精确识别

Benefits of technology

(1)本发明通过提取纤维光泽分布和编织密度差异,并经归一化、加权融合及卷积映射得到混纺纹理特征图。由于融合特征能够同时反映纤维反射差异和织物结构变化,解决了单一灰度特征难以区分正常纹理与疵点纹理的问题,提高了复杂背景下疵点特征的辨识能力。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123015507A_ABST
    Figure CN123015507A_ABST
Patent Text Reader

Abstract

The present application relates to the technical fields of blended detection, and discloses a kind of defect detection method and system for blended fabric, method includes obtaining blended fabric original image, carries out blended texture feature extraction to blended fabric original image, obtains blended texture feature map;According to blended texture feature map, interlaced edge contour is extracted, and initial edge contour is obtained;According to initial edge contour, grey gradient mutation is extracted, and defect pixel set is obtained, and according to defect pixel set, circumscribed rectangle region is cut, and candidate defect region is obtained;According to candidate defect region, connected texture background is removed, and denoising defect feature map is obtained;According to denoising defect feature map, connected boundary sequence is extracted, and initial defect contour is obtained, and according to initial defect contour, contour closure filling repair is carried out, and closed defect contour is obtained;According to closed defect contour, area vector feature is packaged, and defect geometric feature set is obtained.The present application can realize the accurate identification of defect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of blended fabric inspection technology, and in particular to a method and system for detecting defects in blended fabrics. Background Technology

[0002] Currently, differences in fiber luster, variations in weave density, and uneven dye absorption in cotton-polyester blended fabrics collectively create a mixed-color texture background, causing defect edges to intertwine with the normal texture. Taking dark oil stains on light-colored fabrics as an example, the diffuse reflection of cotton fibers and the specular reflection of polyester create a gradual transition zone, making it difficult for detection systems to peel off the true boundaries of defects pixel by pixel, resulting in significant deviations in area calculations. Furthermore, the identified irregular defect areas lack an effective pathway to be converted into vectorized coordinate data, making them unusable by downstream systems. There is a pressing need to utilize industrial vision inspection methods to achieve precise segmentation of defect outlines and generate geometrically controllable vector graphics to meet the urgent requirements of automated quality assessment.

[0003] In one existing technique, images of cotton-polyester blended fabric are first acquired using a linear scan camera. The grayscale images are then Gaussian smoothed and subjected to adaptive thresholding to obtain candidate defect regions. Morphological opening and closing operations are then used to eliminate isolated noise, followed by edge extraction and contour tracing using the Canny operator to generate closed boundaries composed of pixel coordinates. Because the algorithm relies on global thresholding, when encountering gradient transition areas formed by the superposition of diffuse and specular reflections from fibers, the extracted contours oscillate repeatedly at the texture intersections, leading to inaccurate boundary stripping. Finally, the system directly calculates the area on the pixel mask and outputs it as a raster point set, failing to generate geometrically controllable vector graphics. Existing techniques, due to their reliance on global thresholding, oscillate at the boundaries of gradient regions caused by differences in fiber gloss, and output contours in raster form.

[0004] Therefore, existing technologies cannot achieve accurate identification of defects. Summary of the Invention

[0005] This invention provides a method and system for detecting defects in blended fabrics, so as to achieve accurate identification of defects.

[0006] In a first aspect, to solve the above-mentioned technical problems, the present invention provides a method for detecting defects in blended fabrics, comprising: Obtain the original image of the blended fabric, and extract the blended texture features from the original image of the blended fabric to obtain the blended texture feature map; Based on the blended texture feature map, the interlaced edge contour is extracted to obtain the initial edge contour; Based on the initial edge contour, grayscale gradient abrupt change is extracted to obtain a set of defective pixels, and the bounding rectangle region is cropped based on the set of defective pixels to obtain a candidate defective region. Based on the candidate defect regions, connected texture background removal is performed to obtain a denoised defect feature map; Based on the denoised defect feature map, connected boundary sequence extraction is performed to obtain an initial defect contour, and contour closure filling repair is performed based on the initial defect contour to obtain a closed defect contour. Based on the closed defect contour, area vector features are encapsulated to obtain a set of defect geometric features.

[0007] In a second aspect, the present invention provides a defect detection system for blended fabrics, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method described above.

[0008] Thirdly, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described above.

[0009] Compared with the prior art, the present invention has the following beneficial effects: (1) This invention extracts the fiber gloss distribution and weaving density differences, and obtains the blended texture feature map through normalization, weighted fusion and convolution mapping. Since the fused features can simultaneously reflect the fiber reflection differences and fabric structure changes, it solves the problem that single grayscale features are difficult to distinguish between normal textures and defect textures, and improves the ability to identify defect features in complex backgrounds.

[0010] (2) This invention extracts edge contours through gradient calculation, nonmaximum suppression, and connected component screening, and then removes normal fabric backgrounds by combining local contrast, grayscale gradient, and texture similarity. Since multi-level screening can suppress repeated edges and exclude normal textures such as warp and weft yarns, it solves the problem of edge oscillation and false detection that the global threshold is prone to in the gradient area, and realizes accurate positioning and effective purification of defect areas.

[0011] (3) This invention repairs the defect contour by boundary tracking, interpolation of breakpoints within allowed distances, checking for disconnected breakpoints, and morphological closing operations constrained by region size. It also combines scan line filling, area conversion, curvature extraction, and path fitting to generate defect geometric features. Since contour repair can improve boundary integrity and vector fitting can convert grid contours into callable geometric data, it solves the problems of area calculation deviation and the difficulty in directly using detection results in downstream systems, thus realizing accurate calculation of defect area and vectorized output of contour. Attached Figure Description

[0012] Figure 1 This is a schematic flowchart of a defect detection method for blended fabrics provided in the first embodiment of the present invention. Detailed Implementation

[0013] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0014] Reference Figure 1 The first embodiment of the present invention provides a method for defect detection in blended fabrics, comprising the following steps: S11, Obtain the original image of the blended fabric, and extract the blended texture features from the original image of the blended fabric to obtain the blended texture feature map; S12, extract the interwoven edge contour based on the blended texture feature map to obtain the initial edge contour; S13, perform grayscale gradient abrupt change extraction based on the initial edge contour to obtain a set of defective pixels, and perform bounding rectangle region cropping based on the set of defective pixels to obtain candidate defective regions; S14, perform connected texture background removal based on the candidate defect regions to obtain a denoised defect feature map; S15, based on the denoised defect feature map, the connected boundary sequence is extracted to obtain the initial defect contour, and based on the initial defect contour, the contour closure and filling repair is performed to obtain the closed defect contour. S16, perform area vector feature encapsulation based on the closed defect contour to obtain a set of defect geometric features.

[0015] In step S11, an original image of the blended fabric is acquired, and the blended texture features are extracted from the original image of the blended fabric to obtain a blended texture feature map, including: The grayscale value of each pixel in the original image of the blended fabric is marked with a local window to obtain the fiber gloss distribution matrix; The density difference gradient matrix is ​​obtained by performing horizontal and vertical gray-level difference on adjacent pixels in the original image of the blended fabric. The fiber gloss distribution matrix and the density difference gradient matrix are normalized by dividing by the maximum value of the matrix to obtain the gloss normalized matrix and the density normalized matrix, respectively. After weighting the gloss normalization matrix and the density normalization matrix respectively, the weighted results are added element by element to obtain the gloss density fusion matrix. The gloss density fusion matrix is ​​input into a pre-constructed convolutional neural network for convolutional pooling mapping to obtain the blended texture feature map.

[0016] Specifically, the original image of the blended fabric is acquired by an industrial camera under fixed light source, fixed focal length, fixed exposure time, and fixed conveying speed. The industrial camera acquires images according to the frame rate set in the equipment's technical parameters and records a millisecond-level acquisition timestamp for each image. This timestamp is only used to recall images according to the order of acquisition and does not participate in the defect calculation of a single image. When the image uses 8-bit grayscale encoding, the effective range of pixel values ​​is 0 to 255; if the read value exceeds this range or the image size is inconsistent with the camera's set resolution, the image is discarded and re-acquired. When the original image of the blended fabric is a color image, the red channel value is multiplied by 0.299, the green channel value by 0.587, and the blue channel value by 0.114, and the three products are added together to obtain the grayscale value; when the original image of the blended fabric is a grayscale image, the grayscale value is directly read and written into the grayscale matrix according to the pixel row and column coordinates. A 5×5 local window is established for each pixel in the grayscale matrix, with boundary pixels mirrored. The mean of the 25 grayscale values ​​within the window is calculated, and the mean is subtracted from the current pixel's grayscale value to obtain the local highlight difference. The highlight determination threshold is determined by at least 30 defect-free blended fabric sample images. All local highlight differences are sorted from smallest to largest, and the 90th percentile value is taken as the highlight determination threshold. Positions with local highlight differences greater than the highlight determination threshold are assigned a value of 1, and other positions are assigned a value of 0, thus obtaining the fiber gloss distribution matrix.

[0017] For each pixel in the grayscale matrix, the current pixel's grayscale value, the grayscale value of its right-hand neighbor, and the grayscale value of its bottom neighbor are read. The absolute values ​​of these differences are then calculated, and the horizontal and vertical differences are summed to obtain the density difference gradient value for that pixel. For boundary pixels, adjacent pixels are used to replace pixels in the missing direction for calculation. All density difference gradient values ​​are written into the density difference gradient matrix according to their coordinates. The fiber gloss distribution matrix and the density difference gradient matrix are traversed, and their maximum values ​​are read. When the maximum value is greater than 0, each element in the matrix is ​​divided by this maximum value to obtain the gloss normalization matrix and the density normalization matrix, respectively. When the maximum value is 0, all values ​​in the corresponding normalization matrix are assigned to 0. The sum of the gloss weight and the density weight is 1. The weights are determined from no fewer than 30 historical blended fabric images with manually marked defect areas. Gloss weights are selected sequentially in intervals of 0.1 to 0.9, and the corresponding density weights are obtained by subtracting the gloss weights from 1. A historical gloss-density fusion matrix is ​​generated using each set of weights, and these matrices are input into a convolutional neural network with the same structure to complete training and validation as described below. The intersection-union ratio (IU) of the output response region of the validation sample and the manually marked defect region is calculated. The weight combination with the largest average IU is taken as the final weight, and the network parameters corresponding to this weight combination are saved as the parameters of the pre-constructed convolutional neural network. The gloss normalization matrix is ​​multiplied by the gloss weights, the density normalization matrix is ​​multiplied by the density weights, and the two results at the same coordinates are added together to obtain the gloss-density fusion matrix.

[0018] The pre-built convolutional neural network was trained before use. The training data came from historical blended fabric images with manually labeled defect areas under the same acquisition conditions. 2000 image blocks were cropped to 64×64 pixels, with 1000 positive samples and 1000 negative samples. The center pixel of the positive sample was located within the manually labeled defect area and labeled with a value of 1. The negative samples were taken from image locations without manually labeled defect areas and labeled with a value of 0. A corresponding 64×64 pixel mask was simultaneously cropped from each image block. Pixels within the manually labeled defect area were labeled with a value of 1, and other pixels were labeled with a value of 0. The sample set was divided into a training sample set and a validation sample set at an 8:2 ratio. The convolutional neural network included an input layer, a first convolutional layer, a first pooling layer, a second convolutional layer, a second pooling layer, an output mapping layer, and a binary classification output node. The first convolutional layer had 8 3×3 convolutional kernels, and the second convolutional layer had 16 3×3 convolutional kernels. Both layers had a stride of 1 and were padded with 0s at the boundaries. Both pooling layers used 2×2 max pooling with a stride of 2. The output mapping layer uses a 1×1 convolutional kernel to fuse 16 channels, obtaining a single-channel texture response matrix. The outputs of the first and second convolutional layers are processed using the ReLU activation function, and the output of the output mapping layer is mapped to the range of 0 to 1 using the Sigmoid function, thus obtaining the single-channel texture response matrix. The 64×64 pixel mask is subjected to two consecutive 2×2 max pooling operations to obtain a 16×16 supervision mask, and the binary cross-entropy loss is calculated pixel-by-pixel based on the single-channel texture response matrix and the supervision mask. During training, the single-channel texture response matrix is ​​further processed by global average pooling and binary classification output nodes to obtain the output probability. The classification cross-entropy loss is calculated based on the sample labels, and the pixel-level binary cross-entropy loss is added to the classification cross-entropy loss to obtain the total loss. The initial values ​​of the convolutional kernel coefficients are set to random numbers with a mean of 0 and a variance of 0.01, and the initial value of the bias is set to 0. The Adam optimizer is used to update the convolutional kernel coefficients and bias values ​​with a learning rate of 0.001. Each batch of input consists of 32 samples, and training is conducted for a maximum of 50 epochs. Training stops when the total loss of the validation sample set does not decrease for 5 consecutive epochs. After each epoch, the single-channel texture response matrix of the validation samples is restored to 64×64 pixels. Pixels with a response value not less than 0.5 are used as the output response region, and the intersection-over-union (IoU) ratio of the output response region and the corresponding manually labeled defect region is calculated. Before the total loss of the validation sample set decreases for 5 consecutive epochs, the network parameters with the largest average IoU ratio are saved. In use, the gloss density fusion matrix is ​​sequentially input into the first convolutional layer, the first pooling layer, the second convolutional layer, the second pooling layer, and the output mapping layer to obtain the single-channel texture response matrix. The matrix is ​​then restored to the number of rows and columns of the original image of the blended fabric using nearest neighbor interpolation to obtain the blended fabric texture feature map.

[0019] In step S12, the interwoven edge contour is extracted based on the blended texture feature map to obtain the initial edge contour, including: The gradient matrix of the interwoven region is obtained by summing the absolute values ​​of the gray-level differences between adjacent pixels in the horizontal and vertical directions in the blended texture feature map. Non-maximum suppression is applied to the gradient matrix of the interlacing region along the local gradient direction to obtain the edge response matrix; Eight-neighbor merging is performed on spatially adjacent edge points with foreground pixel values ​​in the edge response matrix to obtain candidate connected components. Connectivity components are filtered based on the aspect ratio of the circumscribed rectangles of the candidate connected components and the variance of the gray-level distribution to obtain a set of fuzzy boundary features. The initial edge contour is obtained by performing global curve mapping on the local coordinate points corresponding to the boundary fuzzy feature set.

[0020] Specifically, the blended texture feature map originates from step S11, with each pixel value serving as a grayscale texture response value in the differential calculation. For each pixel in the blended texture feature map, the current pixel value, the value of the adjacent pixel to the right, and the value of the adjacent pixel below are read, subtracted from each, and the absolute value is taken. Then, the horizontal grayscale difference and the vertical grayscale difference are added together to obtain the gradient value of the interlacing region, which is written into the gradient matrix of the interlacing region according to coordinates. The rightmost column, the bottom row, and the bottom right corner pixels are replaced by adjacent boundary pixels to participate in the calculation. When performing non-maximum suppression, the local gradient direction is determined based on the original horizontal difference, the original vertical difference, and their absolute values. When the absolute value of the horizontal grayscale difference is not less than twice the absolute value of the vertical grayscale difference, it is determined to be the horizontal direction; when the absolute value of the vertical grayscale difference is not less than twice the absolute value of the horizontal grayscale difference, it is determined to be the vertical direction; in other cases, the direction is determined as upper left to lower right or upper right to lower left according to the positive and negative relationship of the two original differences. The gradient value of the interleaving region of the current pixel is compared with the gradient values ​​of the interleaving regions of the two adjacent pixels in the same direction. If the current value is less than either of the adjacent values, it is assigned a value of 0 in the edge response matrix; if the current value is not less than the two adjacent values, the current interleaving region gradient value is retained, and the edge response matrix is ​​obtained.

[0021] The foreground determination threshold is determined by at least 30 historical blended fabric images that have undergone defect detection and acceptance. The historical edge position is obtained by extending the boundary coordinates of the historical defect area outward by one pixel. After performing gradient calculation and non-maximum suppression on the historical images, the response values ​​of the historical edge positions in the edge response matrix are extracted. All response values ​​are sorted from smallest to largest, and the 25th percentile value is taken as the foreground determination threshold. Pixels in the edge response matrix whose pixel values ​​are not less than the foreground determination threshold are determined as foreground edge points, and they are merged from left to right and from top to bottom according to the eight-neighbor relationship to obtain the candidate connected components. For each candidate connected component, the minimum row coordinate, maximum row coordinate, minimum column coordinate, and maximum column coordinate are read, and the width, height, and aspect ratio of the bounding rectangle are calculated. Then, all pixel values ​​of the candidate connected component in the blended texture feature map are read, and the gray-level mean and gray-level distribution variance are calculated. The lower and upper limits of aspect ratio and the gray-level distribution variance screening threshold are determined by the connected components of the actual interlacing edges from no less than 30 historical images of blended fabrics. The 10th and 90th percentile values ​​of the aspect ratio are used as the screening interval, and the 25th percentile value of the gray-level distribution variance is used as the screening threshold. Candidate connected components that meet the aspect ratio interval and have a gray-level distribution variance not less than the screening threshold are written into the boundary fuzzy feature set. For each candidate connected component in the boundary fuzzy feature set, the upper left corner of its circumscribed rectangle is used as the local coordinate origin. The local coordinate points are added back to the global row coordinates and global column coordinates, and then the edge points are tracked and connected in the order of eight neighbors to obtain the initial edge contour.

[0022] In step S13, grayscale gradient abrupt change is extracted based on the initial edge contour to obtain a set of defective pixels, and the bounding rectangle region is cropped based on the set of defective pixels to obtain candidate defective regions, including: A sliding window extreme value difference is performed on the pixel region covered by the initial edge contour to obtain the local contrast matrix corresponding to each center pixel; The corresponding pixel regions in the local contrast matrix where the contrast response value of each pixel is greater than the preset grayscale response threshold are segmented to obtain texture abrupt change regions. For each pixel in the texture abrupt change region, solve for the horizontal and vertical partial derivatives respectively, and take the square root of the sum of the squares of the two partial derivatives to obtain the pixel grayscale gradient; The corresponding pixels whose grayscale gradient is greater than the preset grayscale gradient threshold are filtered out to obtain the defect pixel set.

[0023] Specifically, the initial edge contour originates from step S12 and is composed of contour coordinate points arranged in sequence. Centered on each contour coordinate point, its own pixels and eight neighboring pixels are written into a contour overlay mask. Pixels with a value of 1 in the contour overlay mask constitute the pixel region covered by the initial edge contour. For each central pixel in this pixel region, a 5×5 sliding window is established in the grayscale matrix corresponding to the original image of the blended fabric, with boundary pixels mirrored. The side length of the sliding window is determined by at least 30 historical flawless blended fabric sample images. The number of pixels with consecutive horizontal grayscale changes of the same sign within the initial edge contour overlay region is counted, and the 50th percentile value is taken as the normal texture width pixel count after sorting all the numbers. When this value is not less than 5, the window side length is 5; when it is less than 5, the window side length is 3. In this embodiment, the sliding window side length is 5, and the window radius is 2. All grayscale values ​​within the window are read, and the maximum grayscale value is subtracted from the minimum grayscale value to obtain the contrast response value of the central pixel, which is then written into the local contrast matrix according to its coordinates.

[0024] The grayscale response threshold is determined by at least 30 historical flawless blended fabric sample images. For each sample image, the historical initial edge contour is obtained according to steps S11 and S12, and the historical local contrast response value is calculated using the aforementioned sliding window extreme difference method. All response values ​​are sorted from smallest to largest, and the 95th percentile value is taken as the grayscale response threshold. Pixels in the local contrast matrix whose contrast response value is greater than the grayscale response threshold are written into a texture mutation mask to obtain the texture mutation region. For each pixel in the texture mutation region, the grayscale values ​​of the left, right, top, and bottom adjacent pixels are read; the horizontal partial derivative is obtained by subtracting the left grayscale value from the right grayscale value and dividing by 2; the vertical partial derivative is obtained by subtracting the top grayscale value from the bottom grayscale value and dividing by 2; boundary pixels use the current pixel grayscale value to replace the missing direction pixels in the calculation. The square root of the sum of the squared horizontal and vertical partial derivative values ​​is taken to obtain the pixel grayscale gradient. The grayscale gradient threshold is determined by at least 30 historical flawless blended fabric sample images. Historical pixel grayscale gradients are calculated for pixels within historical texture abrupt change regions. All historical pixel grayscale gradients are sorted from smallest to largest, and the 95th percentile value is used as the grayscale gradient threshold. Pixels with grayscale gradients greater than the grayscale gradient threshold are written into the defect pixel set. The defect pixel set is merged into defect pixel subsets according to the eight-neighbor relationship. The bounding rectangle boundary of each defect pixel subset is calculated, and the rectangle is expanded outward by 2 pixels according to the window radius. When the image exceeds the image boundary, the image boundary is used as the reference, and the candidate defect region is obtained by cropping. When the defect pixel set is empty, the candidate defect region is an empty region.

[0025] In step S14, connected texture background removal is performed based on the candidate defect regions to obtain a denoised defect feature map, including: Local binary mode encoding is performed on each pixel in the candidate defect region to obtain a pixel texture vector; The pixel similarity matrix is ​​obtained by performing Manhattan distance normalization and inverse transformation based on the pixel texture vectors corresponding to adjacent pixels. Based on the adjacency relationships in the pixel similarity matrix where the similarity is greater than the mean of the region similarity, eight-neighborhood connectivity merging is performed to obtain a set of connected components; The area aspect ratio of each connected component in the connected component set is calculated by the number of pixels, the length of the principal axis, and the length of the secondary axis to obtain the morphological feature vector; Based on the normal texture feature range pre-established from the defect-free blended fabric sample, the morphological feature vector is range-matched, and the pixels corresponding to the successfully matched connected components are removed from the candidate defect region to obtain the denoised defect feature map.

[0026] Specifically, the candidate defect region originates from step S13 and includes one or more rectangular image regions. Each rectangular image region stores global row coordinates, global column coordinates, grayscale value, contrast response value, and pixel grayscale gradient. Each rectangular image region is processed separately, and no adjacency relationship is established between different rectangular image regions. A 3×3 local window is established for each pixel in the candidate defect region, with a window radius of 1, and the boundary pixels are mirrored. The grayscale values ​​of the eight adjacent pixels of the current pixel are compared with the grayscale value of the current pixel. If the grayscale value of an adjacent pixel is not less than the grayscale value of the current pixel, it is encoded as 1; if it is less than the grayscale value of the current pixel, it is encoded as 0. The adjacent pixels are arranged in the order of top, top right, right, bottom right, bottom, bottom left, left, and top left to obtain an 8-bit pixel texture vector. The pixel texture vectors of two adjacent pixels are subtracted bit by bit and the absolute value is taken. The eight absolute values ​​are added together to obtain the Manhattan distance. This distance is divided by 8 to obtain the normalized distance. The normalized distance is then subtracted from 1 to obtain the similarity. Each pixel within the rectangular image region is assigned a unique index in row and column order. The pixel similarity matrix adopts the form of a sparse adjacency matrix, where the row index represents the center pixel and the column index represents the adjacent pixels. Each stored element is recorded as an adjacency record unit with the center pixel coordinates, adjacent pixel coordinates, and similarity. Pixel pairs that do not form an eight-neighbor relationship are not written into the pixel similarity matrix.

[0027] For each rectangular image region, the similarity of all adjacent record units in the pixel similarity matrix is ​​read, summed, and divided by the number of similarities to obtain the mean region similarity. The center pixel with a similarity greater than the mean region similarity in the adjacent record unit is determined to have a valid adjacency relationship with its neighboring pixels, and these pixels are grouped into the connected component set according to the eight-neighbor relationship. Individual pixels that do not form a valid adjacency relationship with other pixels are treated as single-pixel connected components. For each connected component, the number of pixels is counted, and the maximum column coordinate, minimum column coordinate, maximum row coordinate, and minimum row coordinate are read to calculate the bounding width and bounding height. The larger of these two values ​​is taken as the principal axis length, and the smaller value as the secondary axis length. The number of pixels is divided by the product of the principal axis length and the secondary axis length to obtain the area fill ratio. The principal axis length is divided by the secondary axis length to obtain the principal-secondary axis length ratio. The morphological feature vector is composed of the number of pixels, principal axis length, secondary axis length, area fill ratio, and principal-secondary axis length ratio. When the number of similarities is 0, the mean region similarity is recorded as 0, and the corresponding pixel is treated as a single-pixel connected component.

[0028] The normal texture feature range is pre-established from no fewer than 30 defect-free blended fabric sample images. For each sample image, the initial edge contour of the defect-free area is obtained according to steps S11 and S12. The bounding rectangle of the connected contour of the initial edge contour of the defect-free area is used as the historical normal texture region. Then, according to the local binary mode encoding, similarity conversion, eight-neighbor connectivity merging, and area aspect ratio calculation in this step, the historical morphological feature vector is obtained. The number of pixels, principal axis length, secondary axis length, area fill ratio, and principal-secondary axis length ratio in the historical morphological feature vector are sorted respectively, and the 5th percentile and 95th percentile values ​​are taken as the corresponding lower and upper limits to form the normal texture feature range. The morphological feature vector of the current connected component is compared with the normal texture feature range item by item. When all five values ​​are within the corresponding range, the range is determined to be successfully matched, and the corresponding pixel of the connected component is removed from the candidate defect region; when any value exceeds the corresponding range, the range is determined to be unmatched, and the corresponding pixel of the connected component is retained. Pixels are retained and written into the denoising matrix using global coordinates, while pixels that are discarded are assigned a value of 0. When multiple rectangular image regions have overlapping pixels, a pixel is written into the denoising matrix as long as it is retained in any rectangular image region. The denoising matrix is ​​then converted into a single-channel image to obtain the denoised defect feature map.

[0029] In step S15, connected boundary sequence extraction is performed based on the denoised defect feature map to obtain an initial defect contour, and contour closure and filling repair is performed based on the initial defect contour to obtain a closed defect contour, including: From the denoised defect feature map, select non-zero pixels with gray values ​​greater than the preset background gray value to obtain a set of denoised defect pixels; Based on the eight-neighbor position relationship of adjacent pixels in the denoised defect pixel set, connected component labeling is performed to obtain the defect connected region; Moiré neighborhood tracking is performed on the outermost pixels of the defective connected region to obtain an initial boundary pixel sequence arranged in order; When the Chebyshev distance between adjacent coordinates in the initial boundary pixel sequence is greater than the preset pixel breakpoint distance but not greater than the allowable repair distance, linear interpolation is performed on the coordinates on both sides of the breakpoint; when the Chebyshev distance is greater than the allowable repair distance, the coordinates on both sides of the breakpoint are retained and recorded as unconnected breakpoints, thus obtaining a closed boundary pixel set. The initial defect contour is obtained by extracting the edge contour line based on the closed boundary pixel set.

[0030] Chain code statistics are performed on the contour pixels of the initial defect contour to obtain the perimeter value; The area is obtained by solving Green's formula based on the coordinates of the contour nodes of the initial defect contour; Multiply the area of ​​the outline by the shape normalization constant and then divide by the square of the perimeter value to obtain the closure value. When the closure value is less than the preset closure threshold, morphological closure operation is performed on the initial defect contour to obtain the repaired contour image. When the closure value is not less than the closure threshold, the initial defect contour is determined as the repair contour image, and the boundary pixels are sorted according to the repair contour image to obtain the closed defect contour.

[0031] Specifically, the denoised defect feature map originates from step S14, and its row and column numbers are consistent with the original image of the blended fabric. The background grayscale is determined to be 0 based on the initial pixel value of the denoising matrix in step S14. The denoised defect feature map is traversed, and non-zero pixels with grayscale values ​​greater than 0 are written into the denoised defect pixel set; when no non-zero pixels exist, both the initial defect contour and the closed defect contour are empty contours. Eight-neighbor connected component labeling is performed based on the denoised defect pixel set, and a labeling matrix is ​​established. Unlabeled pixels are traversed from left to right and from top to bottom, and pixels that are adjacent to its eight neighbors and belong to the denoised defect pixel set are assigned the same connected component number to obtain the defect connected region. For each defect connected region, if there are background pixels or positions outside the image boundary among the eight neighboring positions of the current pixel, then the pixel is determined to be the outermost pixel. The outermost pixel with the smallest row coordinate and the smallest column coordinate is selected as the starting pixel for Moore neighborhood tracking. The next outermost pixel is searched in a cyclical order of top, top right, right, bottom right, bottom, bottom left, left and top left until the starting pixel is returned or no new pixel can be added, thus obtaining the initial boundary pixel sequence.

[0032] The pixel breakpoint distance is set to 1 based on the eight-neighbor continuity relationship. The allowable repair distance is determined by at least 30 historical blended fabric images with manually annotated defect outlines. The coordinates on both sides of the manually annotated breakpoints belonging to the same outline are read, the Chebyshev distance is calculated and sorted from smallest to largest, and the 90th percentile value is taken as the allowable repair distance. For adjacent coordinates in the initial boundary pixel sequence, as well as the last coordinate and the first coordinate, the absolute values ​​of the row coordinate difference and column coordinate difference are calculated respectively, and the larger one is taken as the Chebyshev distance; when the Chebyshev distance is greater than 1, this set of coordinates is determined as the coordinates on both sides of the breakpoint. When the Chebyshev distance is greater than 1 and not greater than the allowable repair distance, the larger value of the absolute values ​​of the row coordinate difference and column coordinate difference is used as the interpolation step number. The row coordinate difference and column coordinate difference are divided by the interpolation step number to obtain the single-step increment, and then gradually accumulated and the nearest integer coordinate is taken to obtain the supplementary pixel coordinates, which are then inserted between the coordinates on both sides of the breakpoint. When the Chebyshev distance is greater than the allowable repair distance, the coordinates on both sides of the breakpoint are retained without interpolation and recorded as unconnected breakpoints. The original boundary pixel coordinates, supplementary pixel coordinates within the allowable range, and the unconnected breakpoint records are associated and saved to obtain the closed boundary pixel set; this closed boundary pixel set is the boundary data set for subsequent contour closure and filling repair processing, including connected boundary pixel coordinates and unconnected breakpoint records. Adjacent coordinates that do not belong to unconnected breakpoints are connected according to their coordinate order to obtain the initial defect contour. Regions with fewer than 3 coordinates do not generate contours.

[0033] When performing chain code statistics on the contour pixels of the initial defect contour, the difference in row and column coordinates between two adjacent connected contour pixels is read. The step size is recorded as 1 when horizontally or vertically adjacent, and as 1.414 when diagonally adjacent. All step sizes are added together to obtain the perimeter value. When calculating the Green's formula area based on the contour node coordinates of the initial defect contour, the column coordinates are used as the horizontal coordinates, and the row coordinates as the vertical coordinates. The cross-product difference between adjacent nodes and between the last and first nodes is calculated according to the arrangement order of the contour nodes. All cross-product differences are accumulated, the absolute value is taken, and divided by 2 to obtain the Green's formula area solution. When the initial defect contour has no unconnected breakpoints, the Green's formula area solution result is determined as the contour area; when unconnected breakpoints exist, since the initial defect contour does not form an effective closed region, the effective value of the Green's formula area solution result is determined as 0, and the contour area is obtained. The shape normalization constant is taken as 4 multiplied by pi, where pi is 3.14159, and the shape normalization constant is 12.56636. Regardless of whether the initial defect contour has unconnected breaks, the contour area is multiplied by 12.56636 and then divided by the square of the perimeter value to obtain the closure value. When the perimeter value is 0, the closure value is recorded as 0. When unconnected breaks exist, the contour area is 0, and the closure value calculated above is 0; when no unconnected breaks exist, the closure value is calculated based on the contour area and perimeter value.

[0034] The closure threshold is determined by at least 30 historical blended fabric images that have undergone defect inspection and acceptance and have no unconnected breaks. The closure value of each historical closed defect contour is calculated, and the minimum value is read from all closure values ​​greater than 0. Half of this minimum value is taken as the closure threshold. The closure threshold, which is greater than 0 and less than the closure value of the historical closed defect contours, is used to distinguish between unclosed contours with a closure value of 0 and closed contours with positive closure values. When the closure value is less than the closure threshold, the initial defect contour is written into a binary image. If unconnected breaks exist, the maximum Chebyshev distance in the unconnected break record is read, and the smallest odd number greater than the maximum Chebyshev distance is taken as the side length of the square structural element. If no unconnected breaks exist, the side length of the square structural element is set to 3. When the side length of the square structuring element is not greater than the shorter side length of the bounding rectangle of the corresponding candidate defect region, a morphological closing operation of dilation followed by erosion is performed to obtain a repaired contour image. When the side length of the square structuring element is greater than the shorter side length, the initial defect contour is marked as unrepairable, and the closed defect contour is not generated. When the closure value is not less than the closure threshold, the initial defect contour is rasterized into a repaired contour image. For contours for which repaired contour images have been generated, foreground pixels with eight-neighborhood positions with the background are selected from the repaired contour images and sorted according to the Moore neighborhood tracking order to obtain the closed defect contour.

[0035] In step S16, area vector features are encapsulated based on the closed defect contour to obtain a set of defect geometric features, including: The closed defect contour is filled with a scanline polygon to obtain a set of foreground pixel coordinates; The area calculation value is obtained by multiplying the number of elements in the foreground pixel coordinate set with the physical area of ​​a single pixel read from the camera calibration parameters. Discrete curvature is calculated based on the vector angle formed by the coordinates of adjacent edge pixels in the closed defect contour to obtain the contour curvature sequence. The edge pixel coordinates corresponding to the local maxima of curvature are selected from the contour curvature sequence to obtain an initial candidate point set. Based on the initial candidate point set, polygon inflection point path fitting is performed to obtain vector graphics data. Then, based on the area calculation value and the vector graphics data, geometric attributes are encapsulated to obtain the defect geometric feature set.

[0036] Specifically, the closed defect contour originates from step S15 and includes the contour number, edge pixel row coordinates, edge pixel column coordinates, and edge pixel arrangement order. Scanline polygon filling is performed on each contour number. The minimum and maximum row coordinates of the contour are read, and each row between them is taken as a scanline. For any scanline, the coordinates of two adjacent edge pixels in the contour, as well as the adjacent edge formed by the last coordinate and the first coordinate, are read. When adjacent edges cross the scanline, the intersection column coordinates are calculated; horizontal edges are not included in the intersection count, and the same vertex is counted only once. The intersection column coordinates on the same scanline are sorted from smallest to largest, and filling intervals are formed by the first and second intersections, the third and fourth intersections, etc. The integer column coordinates within the interval are combined with the scanline row coordinates to obtain the foreground pixel coordinates. This process is performed on all scanlines to obtain the foreground pixel coordinate set; duplicate coordinates are only retained once.

[0037] The physical area of ​​a single pixel is read from the camera calibration parameters. These parameters are established before detection and include the physical spacing of horizontal grid points on the calibration board, the physical spacing of vertical grid points on the calibration board, the average horizontal pixel distance, the average vertical pixel distance, the horizontal physical length of a single pixel, the vertical physical length of a single pixel, and the physical area of ​​a single pixel. During establishment, a planar calibration board with recorded grid point physical spacing is placed on an imaging plane consistent with the blended fabric to be tested. Images of the calibration board are acquired using the same camera, focal length, imaging distance, resolution, and light source conditions as in the detection process. The coordinates of adjacent grid point pixels are read, and the average horizontal and vertical pixel distances are calculated. The horizontal physical spacing of the grid points is divided by the average horizontal pixel distance to obtain the horizontal physical length of a single pixel; the vertical physical spacing of the grid points is divided by the average vertical pixel distance to obtain the vertical physical length of a single pixel; the two are multiplied to obtain the physical area of ​​a single pixel. The number of elements in the foreground pixel coordinate set is counted and multiplied by the physical area of ​​the single pixel to obtain the calculated area value.

[0038] When calculating the discrete curvature based on the vector angle formed by the coordinates of adjacent edge pixels in the closed defect contour, the preceding and following coordinates are read for each edge pixel coordinate, with the first and last coordinates connected in a closed loop. The forward vector is obtained by subtracting the current coordinate from the preceding coordinate, and the backward vector is obtained by subtracting the current coordinate from the following coordinate. The inner product of the two vectors, the length of the forward vector, and the length of the backward vector are calculated. The inner product is then divided by the product of the two vector lengths to obtain the cosine value of the angle. A cosine value greater than 1 is taken as 1, and a cosine value less than -1 is taken as -1. The vector angle is calculated based on the cosine value, and the vector angle is subtracted from pi (3.14159) to obtain the discrete curvature value. When the length of the forward or backward vector is 0, the discrete curvature value is recorded as 0. The discrete curvature values ​​of all edge pixel coordinates are recorded sequentially to obtain the contour curvature sequence.

[0039] The curvature filtering threshold and the minimum spacing between candidate points are determined by at least 30 historical defect contours that have been manually annotated. The 50th, 60th, 70th, and 80th percentile values ​​of the non-zero discrete curvature values ​​in each historical defect contour are used as candidate values ​​for the curvature filtering threshold, and the 2nd, 3rd, 4th, and 5th pixels are used as candidate values ​​for the minimum spacing between candidate points. Candidate points are filtered group by group to form historical vector paths. The average shortest distance between the historical vector path and the corresponding edge points of the manually annotated vector contour is calculated. The combination with the smallest average shortest distance is taken as the curvature filtering threshold and the minimum spacing between candidate points. When the current discrete curvature value is not less than the adjacent values ​​and not less than the curvature filtering threshold, the corresponding edge pixel coordinates are taken as candidate points. When multiple consecutive coordinates have the same local maximum, the coordinates of the middle position of the continuous interval are taken. When the pixel spacing between two candidate points along the contour is less than the minimum spacing between candidate points, the candidate point with the larger discrete curvature value is retained. When the discrete curvature values ​​are the same, the candidate point ranked first is retained, thus obtaining the initial candidate point set. The initial candidate point set is sorted according to the edge pixel arrangement order in the closed defect contour. When the number of initial candidate points under the same contour number is less than 3, edge pixel coordinates corresponding to the extreme row coordinates or extreme column coordinates of the contour that do not coincide with existing points are added until the number is not less than 3. Collinearity judgment is performed on three consecutive initial candidate points. If the cross product of the row and column differences of two adjacent line segments is the same, the intermediate point is deleted. This process is repeated until no collinear intermediate points exist. After deleting collinear points, the number of remaining initial candidate points is checked again. If the number is less than 3, edge pixel coordinates that have the largest straight-line distance from the two existing points and are not collinear are added from the closed defect contour until the number reaches 3. If no non-collinear edge pixel coordinates are found after traversing all edge pixels of the closed defect contour, the point addition is stopped, and the case where all edge pixel coordinates are collinear is handled. When all edge pixel coordinates are collinear, vector graphics data is not generated. The path inflection point pixel coordinate sequence, the path inflection point physical coordinate sequence, and the line segment connection order are all recorded as empty sequences, and the path closure mark is recorded as 0. If there are initial candidate points that are ultimately retained, these initial candidate points are reordered, and adjacent points are connected sequentially, with the last point connected to the first point, to obtain closed path data in pixel coordinate form. If closed path data in pixel coordinate form exists, the single-pixel horizontal physical length and single-pixel vertical physical length are read from the camera calibration parameters. The column coordinates of the inflection points are multiplied by the single-pixel horizontal physical length, and the row coordinates of the inflection points are multiplied by the single-pixel vertical physical length to obtain the vector graphic data in physical coordinate form, and the path closure marker is recorded as 1. Finally, the contour number, foreground pixel count, single-pixel physical area, area calculation value, path inflection point pixel coordinate sequence, path inflection point physical coordinate sequence, line segment connection order, and path closure marker are encapsulated to obtain the defect geometric feature set.

[0040] The second embodiment of the present invention provides a defect detection system for blended fabrics, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method described above.

[0041] It should be noted that the defect detection system for blended fabrics provided in this embodiment of the invention is used to execute all the process steps of the defect detection method for blended fabrics in the above embodiment. The working principles and beneficial effects of the two are one-to-one, so they will not be described again.

[0042] It should be noted that the system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.

[0043] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. In particular, it should be noted that any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention for those skilled in the art.

Claims

1. A method for detecting defects in blended fabrics, characterized in that, include: Obtain the original image of the blended fabric, and extract the blended texture features from the original image of the blended fabric to obtain the blended texture feature map; Based on the blended texture feature map, the interlaced edge contour is extracted to obtain the initial edge contour; Based on the initial edge contour, grayscale gradient abrupt change is extracted to obtain a set of defective pixels, and the bounding rectangle region is cropped based on the set of defective pixels to obtain a candidate defective region. Based on the candidate defect regions, connected texture background removal is performed to obtain a denoised defect feature map; Based on the denoised defect feature map, connected boundary sequence extraction is performed to obtain an initial defect contour, and contour closure filling repair is performed based on the initial defect contour to obtain a closed defect contour. Based on the closed defect contour, area vector features are encapsulated to obtain a set of defect geometric features.

2. The defect detection method for blended fabrics according to claim 1, characterized in that, The step of extracting blended texture features from the original image of the blended fabric to obtain a blended texture feature map includes: The grayscale value of each pixel in the original image of the blended fabric is marked with a local window to obtain the fiber gloss distribution matrix; The density difference gradient matrix is ​​obtained by performing horizontal and vertical gray-level difference on adjacent pixels in the original image of the blended fabric. The fiber gloss distribution matrix and the density difference gradient matrix are normalized by dividing by the maximum value of the matrix to obtain the gloss normalized matrix and the density normalized matrix, respectively. After weighting the gloss normalization matrix and the density normalization matrix respectively, the weighted results are added element by element to obtain the gloss density fusion matrix. The gloss density fusion matrix is ​​input into a pre-constructed convolutional neural network for convolutional pooling mapping to obtain the blended texture feature map.

3. The defect detection method for blended fabrics according to claim 1, characterized in that, The step of extracting the interwoven edge contour based on the blended texture feature map to obtain the initial edge contour includes: The gradient matrix of the interwoven region is obtained by summing the absolute values ​​of the gray-level differences between adjacent pixels in the horizontal and vertical directions in the blended texture feature map. Non-maximum suppression is applied to the gradient matrix of the interlacing region along the local gradient direction to obtain the edge response matrix; Eight-neighbor merging is performed on spatially adjacent edge points with foreground pixel values ​​in the edge response matrix to obtain candidate connected components. Connectivity components are filtered based on the aspect ratio of the circumscribed rectangles of the candidate connected components and the variance of the gray-level distribution to obtain a set of fuzzy boundary features. The initial edge contour is obtained by performing global curve mapping on the local coordinate points corresponding to the boundary fuzzy feature set.

4. The defect detection method for blended fabrics according to claim 1, characterized in that, The step of extracting grayscale gradient abrupt changes based on the initial edge contour to obtain a set of defective pixels includes: A sliding window extreme value difference is performed on the pixel region covered by the initial edge contour to obtain the local contrast matrix corresponding to each center pixel; The corresponding pixel regions in the local contrast matrix where the contrast response value of each pixel is greater than the preset grayscale response threshold are segmented to obtain texture abrupt change regions. For each pixel in the texture abrupt change region, solve for the horizontal and vertical partial derivatives respectively, and take the square root of the sum of the squares of the two partial derivatives to obtain the pixel grayscale gradient; The corresponding pixels whose grayscale gradient is greater than the preset grayscale gradient threshold are filtered out to obtain the defect pixel set.

5. The defect detection method for blended fabrics according to claim 1, characterized in that, The step of removing connected texture backgrounds based on the candidate defect regions to obtain a denoised defect feature map includes: Local binary mode encoding is performed on each pixel in the candidate defect region to obtain a pixel texture vector; The pixel similarity matrix is ​​obtained by performing Manhattan distance normalization and inverse transformation based on the pixel texture vectors corresponding to adjacent pixels. Based on the adjacency relationships in the pixel similarity matrix where the similarity is greater than the mean of the region similarity, eight-neighborhood connectivity merging is performed to obtain a set of connected components; The area aspect ratio of each connected component in the connected component set is calculated by the number of pixels, the length of the principal axis, and the length of the secondary axis to obtain the morphological feature vector; Based on the normal texture feature range pre-established from the defect-free blended fabric sample, the morphological feature vector is range-matched, and the pixels corresponding to the successfully matched connected components are removed from the candidate defect region to obtain the denoised defect feature map.

6. The defect detection method for blended fabrics according to claim 1, characterized in that, The step of extracting connected boundary sequences based on the denoised defect feature map to obtain the initial defect contour includes: From the denoised defect feature map, non-zero pixels with gray values ​​greater than the preset background gray value are selected to obtain a set of denoised defect pixels; Based on the eight-neighbor position relationship of adjacent pixels in the denoised defect pixel set, connected component labeling is performed to obtain the defect connected region; Moiré neighborhood tracking is performed on the outermost pixels of the defective connected region to obtain an initial boundary pixel sequence arranged in order; When the Chebyshev distance between adjacent coordinates in the initial boundary pixel sequence is greater than the preset pixel breakpoint distance but not greater than the allowable repair distance, linear interpolation is performed on the coordinates on both sides of the breakpoint; when the Chebyshev distance is greater than the allowable repair distance, the coordinates on both sides of the breakpoint are retained and recorded as unconnected breakpoints, thus obtaining a closed boundary pixel set. The initial defect contour is obtained by extracting the edge contour line based on the closed boundary pixel set.

7. The defect detection method for blended fabrics according to claim 1, characterized in that, The step of closing and filling the contour based on the initial defect contour to obtain a closed defect contour includes: Chain code statistics are performed on the contour pixels of the initial defect contour to obtain the perimeter value; The area is obtained by solving Green's formula based on the coordinates of the contour nodes of the initial defect contour; Multiply the area of ​​the outline by the shape normalization constant and then divide by the square of the perimeter value to obtain the closure value. When the closure value is less than the preset closure threshold, morphological closure operation is performed on the initial defect contour to obtain the repaired contour image; When the closure value is not less than the closure threshold, the initial defect contour is determined as the repair contour image, and the boundary pixels are sorted according to the repair contour image to obtain the closed defect contour.

8. The defect detection method for blended fabrics according to claim 1, characterized in that, The step of encapsulating the area vector features based on the closed defect contour to obtain a set of defect geometric features includes: The closed defect contour is filled with a scanline polygon to obtain a set of foreground pixel coordinates; The area calculation value is obtained by multiplying the number of elements in the foreground pixel coordinate set with the physical area of ​​a single pixel read from the camera calibration parameters. Discrete curvature is calculated based on the vector angle formed by the coordinates of adjacent edge pixels in the closed defect contour to obtain the contour curvature sequence. The edge pixel coordinates corresponding to the local maxima of curvature are selected from the contour curvature sequence to obtain an initial candidate point set. Based on the initial candidate point set, polygon inflection point path fitting is performed to obtain vector graphics data. Then, based on the area calculation value and the vector graphics data, geometric attributes are encapsulated to obtain the defect geometric feature set.

9. A defect detection system for blended fabrics, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the method according to any one of claims 1 to 8.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method described in any one of claims 1 to 8.