A cloth defect image generation and data enhancement method
By constructing a statistical boundary set of real defect morphology and the optimal transmission distance, fabric defect images are generated and data is enhanced, solving the problem of virtual data deviating from real morphology and achieving high-precision data expansion and reduced false alarm rate.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- 泉州联兴发针织织造有限公司
- Filing Date
- 2026-06-09
- Publication Date
- 2026-07-10
AI Technical Summary
Traditional methods for generating and augmenting fabric defect images often fail to produce virtual data that deviates significantly from the actual physical form and objective statistical laws when dealing with complex and ever-changing industrial environments. This results in decreased defect recognition accuracy and increased false alarm rates.
By constructing a statistical boundary set of real defect morphology and introducing an optimal transmission distance, geometric space transformation and color space translation of virtual fabric defect generated images are performed. Images with compliant morphology are selected, and the second optimal transmission distance between the virtual distribution parameter set and the real distribution parameters is calculated to generate a data augmentation set of target fabric defect images.
It achieves dual rigorous filtering of virtual generated defect samples, ensuring that the generated target fabric defect image data enhancement set closely matches the real industrial physical laws in terms of shape and distribution, greatly expanding the total amount of data while improving defect detection accuracy and reducing false alarm rate.
Smart Images

Figure CN122368684A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image generation technology, and in particular to a method for generating and enhancing images based on fabric defects. Background Technology
[0002] The field of image generation technology covers the creation of synthetic visual digital images using computer algorithms. Its main purpose is to generate new image samples that conform to a specific visual distribution by analyzing and learning the feature distribution of given data.
[0003] Traditional fabric defect image generation and data augmentation methods refer to the process of generating specific images and augmenting data for fabric surface defect samples. This is used to increase the amount of basic fabric defect data and enrich the style of data features in actual industrial production scenarios.
[0004] Traditional methods for generating and augmenting fabric defect images can perform specific image generation and data augmentation on fabric surface defect samples to increase the quantity and richness of basic fabric defect data in actual industrial production scenarios. However, when dealing with complex and ever-changing industrial environments and performing high-intensity geometric transformations or random color shifts on the original images, the augmented virtual data suffers from severe deviations from the physical reality and objective statistical laws. This mechanical generation logic lacks effective constraints on underlying parameters, easily producing invalid defect samples with extreme stretching, edge distortion, or complete textural distortion. When these distorted images are directly imported into the dataset, the downstream defect recognition process extracts and absorbs a large number of erroneous feature representations, leading to decreased defect detection accuracy and increased false alarm rates in actual production line applications. Summary of the Invention
[0005] To achieve the above objectives, the present invention adopts the following technical solution: a method for generating and enhancing fabric defect images, comprising the following steps: S1: Collect original images of fabric with real physical defects, determine the set of real defect morphological parameters of the original fabric images, count the maximum and minimum values of each parameter in the set of real defect morphological parameters, and generate a set of real defect statistical boundaries. S2: Determine the true distribution parameter set of the original fabric image, and calculate the first optimal transmission distance and the average value of the first optimal transmission distance among the true distribution parameter sets associated with multiple sets of original fabric images; S3: Perform geometric space transformation and color space translation on the original fabric image to generate virtual fabric defect images. Filter the virtual fabric defect images with reference to the set of real defect statistical boundaries and combine them into shaped compliant images. S4: Determine the set of virtual distribution parameters for the virtual fabric defect generation image after screening in the morphologically compliant image; S5: Calculate the second optimal transmission distance between the virtual distribution parameter set and the corresponding real distribution parameter set, compare it with the average value of the first optimal transmission distance, expand the total data of the fabric defect image according to the comparison result, and generate a target fabric defect image data enhancement set.
[0006] As a further aspect of the present invention, the set of real defect morphology parameters includes the total number of fabric defect pixels, the maximum straight-line span of the defect, the horizontal tilt angle of the span, the variance of the edge coordinate distribution, and the weighted compensation grayscale difference of the defect. The first optimal transmission distance is specifically calculated by the set of real distribution parameters associated with multiple sets of original fabric images. The morphologically compliant images include virtual fabric defect generated images that do not exceed the corresponding maximum value and virtual fabric defect generated images that do not fall below the corresponding minimum value. The set of virtual distribution parameters includes virtual texture distribution vector, virtual structure distribution vector, virtual grayscale change histogram vector, and virtual appearance gradient direction vector. The target fabric defect image data enhancement set includes the selected virtual fabric defect generated images and multiple sets of original fabric images.
[0007] As a further aspect of the present invention, step S1 specifically comprises: S101: Acquire the original image with real defects, obtain the production line environment brightness parameters at the same time node as the original image acquisition, extract the total number of pixels in the defect area divided based on real defects in the original image, calculate the maximum straight-line span of the pixels at both ends of the defect area, measure the horizontal tilt angle corresponding to the maximum straight-line span, and at the same time calculate the distribution variance of the pixel coordinates of the defect edge corresponding to the defect area. S102: Determine the flawless background area, obtain the grayscale values of all pixels in the defective area and the grayscale values of all background pixels in the flawless background area, calculate the difference between the average grayscale value of pixels in the defective area and the average grayscale value of background pixels in the flawless background area, calculate the ratio of the production line environment brightness parameter to the preset standard brightness value, generate a dimensionless brightness compensation coefficient, multiply the dimensionless brightness compensation coefficient by the difference value to obtain the defect weighted compensation grayscale difference value; S103: Obtain the total number of pixels, the maximum straight-line span, the horizontal tilt angle, the distribution variance, and the defect weighted compensation grayscale difference, establish a set of real defect morphology parameters, extract the maximum and minimum values of each parameter in the set of real defect morphology parameters associated with multiple sets of original fabric images, and obtain a set of real defect statistical boundaries.
[0008] As a further aspect of the present invention, step S2 specifically comprises: S201: Calculate the gray-level co-occurrence matrix in the defect region of the original fabric image, extract the local gray-level contrast value, distribution uniformity value, distribution randomness value and spatial correlation value of the gray-level co-occurrence matrix, generate the defect texture distribution vector, calculate the local binary pattern value in the defect region, count the occurrence of all local binary pattern values and sort them in descending order to obtain the defect structure distribution vector. S202: Obtain the gray level value and gradient direction of each pixel in the defect area, calculate the number of times the gray level value of each pixel appears, arrange all the occurrences in ascending order, construct the gray level change histogram vector of the defect, divide the gradient direction into multiple gradient direction intervals, count the number of pixels in each gradient direction interval, arrange the interval pixel counts in interval order, and construct the gradient direction vector of the defect appearance. S203: Combining the defect texture distribution vector, the defect structure distribution vector, the defect grayscale change histogram vector, and the defect appearance gradient direction vector, establish a set of true distribution parameters, calculate the first optimal transmission distance between the true distribution parameter sets associated with multiple sets of original fabric images, and the average value of all first optimal transmission distances.
[0009] As a further aspect of the present invention, step S3 specifically comprises: S301: Perform geometric space transformation and color space translation on the original fabric image to generate a virtual fabric defect image. Divide the virtual defect area and the virtual flawless background area in the virtual fabric defect image. Extract the total number of virtual pixels in the virtual defect area. Calculate the virtual maximum straight-line span of the pixels at both ends of the virtual defect area. Measure the virtual horizontal tilt angle corresponding to the virtual maximum straight-line span. Extract the pixel coordinates of the virtual defect edge. Calculate the virtual distribution variance of the pixel coordinates of the virtual defect edge in the virtual defect area corresponding to the virtual defect. Obtain the virtual basic morphological features. S302: Obtain the grayscale values of all virtual pixels within the virtual defect area and the grayscale values of all virtual background pixels within the flawless background area, calculate the virtual defect grayscale difference between the average virtual pixel grayscale value within the virtual defect area and the average virtual background pixel grayscale value within the flawless background area, and obtain the full virtual defect features. S303: Compare the maximum and minimum values of each parameter in the virtual basic morphological features and the virtual defect full features respectively, remove the virtual cloth defect generated images that exceed the corresponding maximum value or are lower than the corresponding minimum value, and retain the remaining virtual cloth defect generated images to obtain morphologically compliant images.
[0010] As a further aspect of the present invention, step S4 specifically comprises: S401: For the virtual fabric defect generated image in the morphologically compliant image, extract the virtual gray-level co-occurrence matrix of the virtual defect region in the virtual fabric defect generated image, extract the virtual local gray-level contrast value, virtual distribution uniformity value, virtual distribution randomness value and virtual spatial correlation value in the virtual gray-level co-occurrence matrix and stitch them together to generate a virtual texture distribution vector, calculate the virtual local binary pattern value of the virtual defect region in the virtual fabric defect generated image, count the occurrence times of all virtual local binary pattern values and arrange them in descending order to construct a virtual structure distribution vector; S402: Extract the virtual pixel gray level value and virtual gradient direction of each virtual pixel in the virtual fabric defect region of the virtual fabric defect generated image, calculate the occurrence frequency of each virtual pixel gray level value and arrange them in ascending order, construct a virtual gray level change histogram vector, divide the virtual gradient direction into multiple virtual gradient direction intervals, count the number of virtual interval pixels in each virtual gradient direction interval and arrange them in interval order, and construct a virtual appearance gradient direction vector; S403: Concatenate the virtual texture distribution vector, the virtual structure distribution vector, the virtual grayscale change histogram vector, and the virtual appearance gradient direction vector to obtain a set of virtual distribution parameters.
[0011] As a further aspect of the present invention, step S5 specifically comprises: S501: Calculate the second optimal transmission distance between each parameter in the virtual distribution parameter set and the corresponding parameter in the real distribution parameter set; S502: Select virtual fabric defect images from morphologically compliant images where the second optimal transmission distance is less than the average value of the first optimal transmission distance, and use them as a candidate enhanced defect image set; S503: The candidate enhanced defect image set is appended and stitched to multiple sets of original fabric images to perform total data expansion processing, and a target fabric defect image data enhancement set is established.
[0012] Compared with the prior art, the advantages and positive effects of the present invention are as follows: In this invention, by constructing a statistical boundary set of real defect morphologies and introducing optimal transmission distance for objective feature comparison, a dual-rigor filtering of virtual generated defect samples is achieved, effectively controlling the quality of data augmentation and purifying the target augmentation dataset from the source. Specifically, this invention first deeply analyzes real fabric images, establishing upper and lower limits of physical morphology including image span, tilt angle, and distribution variance. Based on multi-dimensional feature vectors, the average value of the first optimal transmission distance within the real sample group is calculated as the data distribution benchmark. After generating virtual fabric defect images through spatial location mapping and color shift processing, this invention first uses the aforementioned morphological statistical boundaries to directly remove out-of-bounds defective pieces that clearly violate physical norms. Then, it further extracts the distribution parameters of compliant images, such as texture and structure, and calculates the second optimal transmission distance between these parameters and the real distribution parameters. Finally, based on the comparison between this distance value and the real distance benchmark, invalid samples with underlying feature distribution shifts are precisely screened out. This significantly expands the total amount of data while ensuring that the final generated target fabric defect image data augmentation set highly conforms to real industrial physical laws in terms of morphology and distribution. Attached Figure Description
[0013] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0014] Figure 1 This is a schematic diagram of the steps of the present invention; Figure 2 This is a detailed schematic diagram of S1 of the present invention; Figure 3 This is a detailed schematic diagram of S2 of the present invention; Figure 4 This is a detailed schematic diagram of S3 of the present invention; Figure 5 This is a detailed schematic diagram of S4 of the present invention; Figure 6 This is a detailed schematic diagram of S5 of the present invention. Detailed Implementation
[0015] The technical solution of the present invention will now be described with reference to the accompanying drawings.
[0016] Please see Figure 1 This invention provides a method for generating and augmenting fabric defect images, comprising the following steps: S1: Collect original images of fabric with real physical defects, determine the set of real defect morphological parameters of the original fabric images, count the maximum and minimum values of each parameter in the set of real defect morphological parameters, and generate a set of real defect statistical boundaries. S2: Determine the true distribution parameter set of the original fabric image, and calculate the first optimal transmission distance and the average value of the first optimal transmission distance among the true distribution parameter sets associated with multiple sets of original fabric images; S3: Perform geometric space transformation and color space translation on the original fabric image to generate virtual fabric defect images. Filter the virtual fabric defect images by referring to the statistical boundary set of real defects and combine them into a morphologically compliant image. S4: Determine the set of virtual distribution parameters for generating images of virtual fabric defects after screening in the morphologically compliant images; S5: Calculate the second optimal transmission distance between the virtual distribution parameter set and the corresponding real distribution parameter set, compare it with the average of the first optimal transmission distance, expand the total data of the fabric defect image based on the comparison result, and generate the target fabric defect image data augmentation set.
[0017] The set of real defect morphology parameters includes the total number of fabric defect pixels, the maximum straight-line span of the defect, the horizontal tilt angle of the span, the variance of the edge coordinate distribution, and the weighted compensation grayscale difference of the defect. The first optimal transmission distance is specifically calculated by the set of real distribution parameters associated with multiple sets of original fabric images. The morphologically compliant images include virtual fabric defect generated images that do not exceed the corresponding maximum value and virtual fabric defect generated images that do not fall below the corresponding minimum value. The set of virtual distribution parameters includes virtual texture distribution vector, virtual structure distribution vector, virtual grayscale change histogram vector, and virtual appearance gradient direction vector. The target fabric defect image data augmentation set includes the selected virtual fabric defect generated images and multiple sets of original fabric images.
[0018] Please see Figure 2 Step S1 is as follows: S101: Acquire the original image with real defects, obtain the production line environment brightness parameters at the same time node as the original image acquisition, extract the total number of pixels in the defect area divided based on real defects in the original image, calculate the maximum straight-line span of the pixels at both ends of the defect area, measure the horizontal tilt angle corresponding to the maximum straight-line span, and at the same time calculate the distribution variance of the pixel coordinates of the defect edge corresponding to the defect area. An image acquisition device positioned directly above the production line uses hardware-triggered pulse signals from the conveyor belt encoder to perform exposure, acquiring an 8-bit depth original fabric image matrix with a resolution of 2048 x 2048 pixels and containing three channels: red, green, and blue. At the same physical time point of image acquisition, a brightness acquisition component installed nearby performs photocurrent analog-to-digital conversion and voltage sampling to obtain the current production line ambient brightness parameters. When extracting the total number of pixels in the original image representing defect areas based on actual flaws, the original fabric image matrix is first converted into a two-dimensional single-channel grayscale matrix. A binarized dynamic thresholding operation is then called, marking pixels larger than a preset grayscale threshold constant as foreground states to form foreground connected components, and pixels smaller than or equal to the preset grayscale threshold constant as background states to form background regions. A nested loop logic is initiated to traverse all horizontal and vertical coordinate points of the two-dimensional single-channel grayscale matrix. An initial count variable with a value of 0 is established. When a pixel marked as foreground is scanned, this count variable is incremented by 1. After a complete traversal of all image pixels, the final accumulated value of the count variable is extracted as the total number of pixels in the defect area. To calculate the maximum straight-line span of the pixels at both ends of the defect area, all edge pixels on the boundary of the foreground connected region are traversed to extract their two-dimensional coordinate combinations. A nested double loop mechanism is used to pair any two edge pixels. For each pair of edge pixels, the horizontal coordinate value of the first pixel is extracted and subtracted from the horizontal coordinate value of the second pixel to obtain the horizontal coordinate deviation difference. Simultaneously, the vertical coordinate value of the first pixel is extracted and subtracted from the vertical coordinate value of the second pixel to obtain the vertical coordinate deviation difference. The horizontal coordinate deviation difference is multiplied by itself to obtain the squared horizontal coordinate deviation, and the vertical coordinate deviation difference is multiplied by itself to obtain the squared vertical coordinate deviation. The squared results of the horizontal and vertical coordinate deviations are added together to obtain the sum of squared distances. Finally, the square root operation is performed on the sum of squared distances to determine the straight-line distance between the two edge pixels. The set of all straight-line distance values obtained through the traversal operation is input into the quicksort logic. A recursive operation is performed, continuously selecting a reference value to divide the array into two sub-regions, until the array is sorted in ascending order. The largest value at the end of the array is extracted as the maximum straight-line span. When measuring the horizontal tilt angle corresponding to the maximum straight-line span, the difference between the vertical and horizontal coordinate deviations associated with the first and last pixels constituting the maximum straight-line span is extracted. The difference between the vertical and horizontal coordinate deviations is divided to calculate the tangent ratio. This tangent ratio is input into a pre-constructed arctangent trigonometric function mapping relationship, and the corresponding angle offset data is retrieved as the horizontal tilt angle.Simultaneously, when calculating the distribution variance of the pixel coordinates corresponding to the defect edge in the defect region, the horizontal and vertical coordinates of all pixels at the edge of the defect region are extracted. The average horizontal coordinate is obtained by summing all horizontal coordinates and dividing by the total number of edge pixels. Similarly, the average vertical coordinate is obtained by summing all vertical coordinates and dividing by the total number of edge pixels. For each edge pixel, the square of the difference between its horizontal coordinate and the average horizontal coordinate, and the square of the difference between its vertical coordinate and the average vertical coordinate, are calculated. All these squared deviations are summed and divided by the total number of edge pixels minus a correction denominator of 1 to finally obtain the distribution variance.
[0019] S102: Determine the flawless background area, obtain the grayscale values of all pixels in the defective area and the grayscale values of all background pixels in the flawless background area, calculate the difference between the average grayscale value of pixels in the defective area and the average grayscale value of background pixels in the flawless background area, calculate the ratio of the production line environment brightness parameter to the preset standard brightness value, generate a dimensionless brightness compensation coefficient, multiply the dimensionless brightness compensation coefficient by the difference value to obtain the defect weighted compensation grayscale difference value; In a two-dimensional single-channel grayscale matrix, for the outer boundary of the foreground connected region marked as the foreground state, a fixed distance of 50 pixels wide is extended outward in both the horizontal and vertical directions. The pixels included after the expansion are divided into a transition isolation region. Then, the set of coordinates of all pixels outside the boundary of the transition isolation region but not exceeding the original physical boundary of the image are extracted. The two-dimensional space contained in this coordinate set is established as the flawless background region. When obtaining the grayscale values of all pixels in the defective region and the grayscale values of all background pixels in the flawless background region, the grayscale values corresponding to each coordinate in the connected region are read sequentially according to coordinate addressing, and the grayscale values in the coordinate set of the background region are read simultaneously. When calculating the difference between the average pixel grayscale value in the defective region and the average background pixel grayscale value in the flawless background region, the grayscale values of all pixels in the connected region are added to obtain the total grayscale value of the connected region. The total grayscale value is divided by the total number of pixels extracted above to obtain the average pixel grayscale value in the defective region. Similarly, sum the grayscale values of all background pixels within the flawless background area and divide by the total number of pixels in the background area to obtain the average grayscale value of the background pixels within the flawless background area. Subtract the average grayscale value of the background pixels within the flawless background area from the average grayscale value of the defective area, and convert the absolute value of the result to obtain the original grayscale difference between the two. When calculating the ratio of the production line ambient brightness parameter to the preset standard brightness value, extract the actual production line ambient brightness parameter and retrieve the preset standard brightness value. This preset standard brightness value is set based on the optimal reference illuminance verification result required for clear imaging of fabric texture under standard test conditions and is fixed at 1000 lux. Divide the actual production line ambient brightness parameter by this preset standard brightness value to generate a dimensionless brightness compensation coefficient. When multiplying the dimensionless brightness compensation coefficient by the difference, extract the original grayscale difference calculated in the previous step and the generated dimensionless brightness compensation coefficient, and perform a direct multiplication operation to obtain the defect-weighted compensation grayscale difference value. This operational logic eliminates the influence of production line lighting attenuation or external stray light interference on the numerical offset of defect grayscale contrast characteristics by introducing an ambient light fluctuation compensation variable.
[0020] S103: Obtain the total number of pixels, maximum straight-line span, horizontal tilt angle, distribution variance and defect weighted compensation grayscale difference, establish a set of real defect morphology parameters, extract the maximum and minimum values of each parameter in the set of real defect morphology parameters associated with multiple sets of original fabric images, and obtain a set of real defect statistical boundaries. Following a fixed data extraction order, the five independently calculated parameters—total pixel count, maximum straight-line span, horizontal tilt angle, distribution variance, and defect-weighted compensation grayscale difference—are retrieved sequentially to establish a set of real defect morphology parameters in the form of a one-dimensional row vector. When extracting the maximum and minimum values of each parameter from multiple sets of fabric raw images associated with the real defect morphology parameter set, the aforementioned parameter acquisition process is repeated for 50 sets of fabric raw images containing different morphological defects collected over 30 consecutive production shifts. This process generates 50 independent one-dimensional row vector sets of real defect morphology parameters corresponding to these 50 sets of images. These 50 one-dimensional row vectors are then stacked vertically according to the order in which the data was generated, creating a two-dimensional feature matrix with 50 rows and 5 columns. For the data in the first column of the two-dimensional feature matrix representing the total number of pixels, a comparison process is established, and the value in the first column of the first row is simultaneously preset as the temporary maximum and temporary minimum value. Then, a row-by-row step-by-row loop is started, sequentially reading the total number of pixels from the second row to the 50th row and comparing it with the temporary maximum and temporary minimum values. When the newly read data is greater than the temporary maximum value, the temporary maximum value is updated to the newly read data; when the newly read data is less than the temporary minimum value, the temporary minimum value is updated to the newly read data. After traversing all 50 rows, the fixed temporary maximum and temporary minimum values are extracted as the result boundaries for corresponding items. Following this cyclical comparison operation process, the second column representing the maximum straight line span, the third column representing the horizontal tilt angle, the fourth column representing the distribution variance, and the fifth column representing the defect weighted compensation grayscale difference are sequentially traversed and compared. When obtaining the true defect statistical boundary set, the five sets of maximum values and five sets of minimum values obtained by comparing columns 1 to 5 are combined and matched. These five sets of upper and lower limit values are encapsulated into a key-value pair data structure to obtain the true defect statistical boundary set containing the complete physical range of the data distribution. This boundary set will serve as a hard benchmark for subsequent virtual data validity screening.
[0021] Please see Figure 3 Step S2 is as follows: S201: Calculate the gray-level co-occurrence matrix in the defect region of the original fabric image, extract the local gray-level contrast value, distribution uniformity value, distribution randomness value and spatial correlation value of the gray-level co-occurrence matrix, generate the defect texture distribution vector, calculate the local binary pattern value in the defect region, count the occurrence of all local binary pattern values and sort them in descending order to obtain the defect structure distribution vector. Within the two-dimensional single-channel grayscale matrix of the defect region, spatial adjacency parameters with directionality and step size are defined, using a horizontal offset of 1 pixel to the right as the adjacency rule. A two-dimensional all-zero statistical matrix of dimension 256x256 with all elements set to 0 is initialized. Each reference pixel coordinate within the defect region is iterated through to obtain its corresponding reference grayscale value. Then, based on the adjacency rule, its right-hand horizontally adjacent pixel is obtained, and its corresponding adjacent grayscale value is read. The reference grayscale value is used as the row index of the two-dimensional statistical matrix, and the adjacent grayscale values are used as column indexes. The element value at the intersection of the corresponding row and column in the statistical matrix is incremented by 1. After traversing all pixel pairs within the defect region, each element value in the statistical matrix is divided by the total frequency of the pixel pairs involved in the statistics, performing a normalized division operation to obtain the normalized grayscale co-occurrence matrix. When extracting local gray-level contrast values from the gray-level co-occurrence matrix, for each element in the matrix, the difference between its row index and column index is calculated. This difference is then multiplied by itself to obtain the squared difference. The squared difference is then multiplied by the current element's value, and finally, all the multiplications are summed to obtain the local gray-level contrast value. When extracting distribution uniformity values, the squared value of each element in the matrix is multiplied by itself, and then all the squared results are summed to obtain the distribution uniformity value. When extracting distribution randomness values, the natural logarithm of each element's value is calculated. This logarithm is multiplied by the current element's value to obtain the local product. All the local product values are summed, and the negative value of the result is used to obtain the distribution randomness value. When extracting spatial correlation values, the marginal mean and marginal standard deviation of the matrix rows are calculated separately. The spatial correlation value is obtained by subtracting the marginal mean from the row index of each element and multiplying it by the result of subtracting the marginal mean from the column index, then multiplying this by the current element's value, summing all the calculated results, and finally dividing by the product of the row and column marginal standard deviations. When generating the defect texture distribution vector, the local grayscale contrast values, distribution uniformity values, distribution randomness values, and spatial correlation values are concatenated and combined in the extraction order to generate a one-dimensional defect texture distribution vector with 4-dimensional length features. When calculating the local binary pattern values within the defect region, a central pixel is set, and the grayscale values of its eight adjacent pixels within a 3x3 square neighborhood are extracted. Starting from directly above the central pixel, the grayscale values of each adjacent pixel are compared with the central pixel's grayscale value in a clockwise direction. If the adjacent pixel's grayscale value is greater than or equal to the central pixel's grayscale value, the feature label result of that adjacent position is set to the number 1; otherwise, it is set to the number 0. The eight clockwise obtained markers, each consisting of 1 or 0, are arranged and merged in order to form an 8-bit binary sequence.Subsequently, the number system conversion operation is invoked, multiplying each digit of the 8-bit binary sequence by 2 raised to the corresponding weight power and summing the results to convert them into a decimal value. This decimal value is the local binary pattern value corresponding to the center pixel. When counting the occurrences of all local binary pattern values and sorting them in descending order, a one-dimensional all-zero counting array of length 256 is initialized. The calculated local binary pattern values are directly used as the address index of this counting array. Each time a corresponding value appears, the data at the corresponding address is incremented by 1. After processing all center pixels, the bubble sort comparison operation logic is invoked to perform pairwise comparisons and swap positions of the 256 frequency data in the counting array from largest to smallest, obtaining the defect structure distribution vector.
[0022] S202: Obtain the gray level value and gradient direction of each pixel in the defect area, calculate the number of times the gray level value of each pixel appears, arrange all the occurrences in ascending order, construct the gray level change histogram vector of the defect, divide the gradient direction into multiple gradient direction intervals, count the number of pixels in each gradient direction interval, arrange the interval pixel counts in interval order, and construct the gradient direction vector of the defect appearance. Reading the previously acquired grayscale values, the Sobel difference operator logic is used to process the gradient direction acquisition, establishing two 3x3 dimensional difference weight mask matrices for the horizontal and vertical directions, respectively. A 3x3 image neighborhood window is extracted centered on the current pixel. The grayscale values of the nine pixels within the neighborhood window are multiplied one by one with the corresponding nine weights in the horizontal difference weight mask matrix, and then accumulated to calculate the horizontal gradient response component. Similarly, the vertical gradient response component is obtained by multiplying one by one with the vertical difference weight mask matrix. The ratio of the vertical gradient response component to the horizontal gradient response component is extracted and input into the arctangent trigonometric function mapping operation to look up the gradient direction angle value from 0 to 360 degrees corresponding to the current pixel. When calculating the occurrence count of each pixel's grayscale value, an accumulator array with 256 address spaces covering the range of 0 to 255 is initialized. All pixels within the defect region are traversed, and their grayscale values are extracted and passed as address variables to the accumulator array, causing the data at the corresponding position to be incremented by 1. When arranging all occurrences in ascending order, a selection sorting data processing mechanism is executed on the 256 count values counted in the accumulator array to construct a defect grayscale change histogram vector containing 256 sequentially increasing elements. When dividing the gradient direction into multiple gradient direction intervals, the complete closed-loop angle range from 0 degrees to 360 degrees is divided into 8 consecutive numerical comparison intervals, each spanning 45 degrees. When counting the number of pixels within each gradient direction interval, an interval counter set with 8 data slots is established. The gradient direction angle value of each pixel, calculated previously, is loaded into the comparison logic. Multiple nested conditional judgment instructions are used to confirm the corresponding interval to which the current angle value falls. After determining its classification, an increment operation of 1 is performed on the corresponding counter data slot. After traversing all pixels in the defect area, the number of pixels in each interval is arranged in ascending order of angle. The count results from these 8 dimensions are merged to construct the defect appearance gradient direction vector.
[0023] S203: By combining the defect texture distribution vector, defect structure distribution vector, defect grayscale change histogram vector, and defect appearance gradient direction vector, a true distribution parameter set is established. The first optimal transmission distance between the true distribution parameter sets associated with multiple sets of original fabric images is calculated, as well as the average of all first optimal transmission distances. Calculating the first optimal transmission distance includes: performing extreme value normalization operations on the defect texture distribution vector, defect structure distribution vector, defect grayscale change histogram vector, and defect appearance gradient direction vector in multiple sets of true distribution parameter sets; calculating the Euclidean distances between the normalized defect texture distribution vectors, defect structure distribution vectors, defect grayscale change histogram vectors, and defect appearance gradient direction vectors; combining all corresponding Euclidean distances to generate a true distribution difference matrix; constructing the true joint probability matrix corresponding to the true distribution difference matrix; calculating the sum of the products of corresponding matrix elements of the true distribution difference matrix and the true joint probability matrix; and extracting the minimum value from the sum of all corresponding matrix element products to determine the first optimal transmission distance. Following the sequential connection order, a 4-dimensional defect texture distribution vector is first extracted. A 256-dimensional defect structure distribution vector is then concatenated at the end of this vector. Next, a 256-dimensional defect grayscale variation histogram vector is concatenated. Finally, an 8-dimensional defect appearance gradient direction vector is concatenated at the end, thus constructing a comprehensive one-dimensional vector set of true distribution parameters containing 524 elements. When calculating the first optimal transmission distance between multiple sets of fabric original images and the average of all first optimal transmission distances, distance metrics are performed on 50 sets of 524-dimensional true distribution parameters extracted from 50 different original images. When calculating the first optimal transmission distance, extreme value normalization is performed on each independent dimension vector group in the extracted sets of true distribution parameters. The specific operation involves extracting the absolute maximum and absolute minimum values from all sample values in a certain dimension. Then, for each sample value within that dimension, the absolute minimum value is subtracted to obtain the local deviation difference. The absolute maximum value is then subtracted from the absolute minimum value to obtain the span difference. The local deviation difference is divided by the span difference to obtain the normalized result, which is located between 0 and 1. When calculating the Euclidean distance between normalized sets of defect texture distribution vectors, defect structure distribution vectors, defect grayscale change histogram vectors, and defect appearance gradient direction vectors, for any two normalized vector objects, their corresponding values at the same position dimension are subtracted to obtain the difference. The square of the subtraction difference is then calculated. The squared results for all dimensions are summed. Finally, the square root of the sum is taken to obtain the scalar Euclidean distance value. When generating the true distribution difference matrix by combining all corresponding Euclidean distances, the four Euclidean distance values calculated at four different feature vector levels between the two original image sets are extracted and sequentially filled into a 4x4 two-dimensional grid to form the true distribution difference matrix. When constructing the true joint probability matrix corresponding to the true distribution difference matrix, a 4x4 non-negative numerical matrix with the same row and column structure as the difference matrix is initialized, and the sum of all row elements and column elements is constrained to satisfy a preset marginal probability distribution condition. When calculating the sum of the corresponding matrix element products of the true distribution difference matrix and the true joint probability matrix, the values at each position in the difference matrix are multiplied one by one with the corresponding values in the probability matrix, and the results of all corresponding product values are summed.When determining the first optimal transmission distance by extracting the minimum value from the sum of the products of all corresponding matrix elements, the Sinkhorn distance iteration mechanism is initiated to continuously change the combination of various numerical configuration parameters within the joint probability matrix. Each time it is changed, the sum of the corresponding matrix element products is recalculated and stored in the comparison record. This process continues until the summation result no longer decreases and convergence is achieved. The minimum global summation value appearing in the record is identified as the first optimal transmission distance. All different first optimal transmission distance values obtained by pairwise operations on 50 sets of image samples are summed, and then divided by the total number of pairwise groups to calculate the average value of all first optimal transmission distances.
[0024] Please see Figure 4 Step S3 is as follows: S301: Perform geometric space transformation and color space translation on the original fabric image to generate a virtual fabric defect image. Divide the virtual defect area and the virtual flawless background area in the virtual fabric defect image. Extract the total number of virtual pixels in the virtual defect area. Calculate the maximum virtual straight-line span of the pixels at both ends of the virtual defect area. Measure the virtual horizontal tilt angle corresponding to the maximum virtual straight-line span. Extract the pixel coordinates of the virtual defect edges. Calculate the virtual distribution variance of the pixel coordinates of the virtual defect edges corresponding to the virtual defect area to obtain the virtual basic morphological features. Performing geometric space transformation and color space translation on the original fabric image includes remapping the spatial positions of all pixel coordinates in the original fabric image according to a preset rotation angle and a preset scaling ratio, and summing and adjusting the color channel values of each pixel in the remapped original fabric image according to a preset color offset. When generating a virtual fabric defect image, the coordinates of all pixels in the original fabric image are extracted and remapped according to a preset rotation angle and a preset scaling ratio. The specific mapping process includes extracting the original horizontal and vertical coordinates of each pixel in the original image, retrieving a preset rotation angle of 15 degrees and a scaling ratio of 1.2. Through coordinate transformation mapping logic, the original horizontal coordinate is multiplied by the cosine trigonometric function of the rotation angle, and the result is subtracted from the original vertical coordinate multiplied by the sine trigonometric function of the rotation angle. The difference is then multiplied by the scaling ratio to calculate the new mapped horizontal coordinate. Similarly, the original horizontal coordinate is multiplied by the sine function, and the result is multiplied by the cosine function, and then multiplied by the scaling ratio to calculate the new mapped vertical coordinate. Since the calculated new mapped coordinates are non-integer positions containing decimals, a bilinear interpolation process is used to extract the grayscale values of the four adjacent original integer coordinate points. The weighted cross-multiplication of these four grayscale values with their deviation from the new coordinates is then summed to calculate the mapped pixel value for the new position. When adjusting the color channel values of each pixel in the original fabric image after spatial remapping according to a preset color offset, the red, green, and blue channel values contained within each newly mapped pixel are extracted and added to the preset color offset constant. If the calculated value of any channel after addition is greater than the maximum grayscale value of 255, a forced truncation operation is triggered to fix the channel value to 255; otherwise, the original added value is retained. After processing all pixels, the variant image generation process is finally completed. When dividing the virtual defect area and the virtual flawless background area in the virtual fabric defect generated image, the same binarization threshold comparison mechanism as before is used to extract the virtual foreground and background pixel connected component segmentation template. When extracting the total number of virtual pixels within the virtual defect area, the segmentation template is traversed row by row, and the pixel values that meet the marking features are incremented and accumulated. When calculating the virtual maximum straight-line span of the pixels at both ends of the virtual defect area, all coordinate pairs of the virtual connected boundary are combined, and the straight-line distance is calculated by taking the difference, squaring, accumulating, and then taking the square root, recording its maximum extreme point. When measuring the virtual horizontal tilt angle corresponding to the virtual maximum straight span, the angle is obtained by dividing the difference between the starting and ending coordinates of the aforementioned maximum extreme point by the inverse triangular mapping. When extracting the pixel coordinates of the virtual defect edges and calculating the virtual distribution variance of the pixel coordinates of the virtual defect edges corresponding to the virtual defect area, the horizontal and vertical mean values of all edge points are extracted. The sum of the squares of the absolute deviation differences of each point is calculated and divided by the denominator of the statistically included data. The resulting data from these re-measurements are then used to obtain the virtual basic morphological features.
[0025] S302: Obtain the grayscale values of all virtual pixels within the virtual defect area and the grayscale values of all virtual background pixels within the flawless background area, calculate the virtual defect grayscale difference between the average virtual pixel grayscale value within the virtual defect area and the average virtual background pixel grayscale value within the flawless background area, and obtain the full virtual defect features. Based on the two-dimensional array index table with virtual connected component identifiers generated in the previous operations, the grayscale pixel values of all coordinate points within the virtual defect region are extracted cyclically according to the spatial arrangement addressing order. Simultaneously, the addressing coordinates are redirected to the outside of the isolation area that has been expanded to a fixed width. The pixel grayscale values corresponding to all background points within the boundary of this region are obtained one by one. The two types of data streams are imported into different pre-initialized temporary queues. When calculating the virtual defect grayscale difference between the average virtual pixel grayscale value in the virtual defect region and the average virtual background pixel grayscale value in the flawless background region, all virtual pixel grayscale values within the connected components are read from the temporary queue, accumulated, and divided by the newly counted total number of virtual pixels to calculate the average virtual pixel grayscale value in the virtual defect region. Then, all virtual background pixel grayscale values are read and accumulated, and divided by the corresponding total number of background pixels to calculate the average virtual background pixel grayscale value in the flawless background region. The absolute deviation is calculated by subtracting the average virtual background pixel grayscale value from the average virtual pixel grayscale value within the virtual defect area and then taking the absolute value of the difference. This absolute deviation is then used as the virtual defect grayscale difference value. Thus, the complete virtual defect full-scale feature is independently obtained from this single calculated value as the primary data source.
[0026] S303: Compare the maximum and minimum values of each parameter in the virtual basic morphological features and the full set of virtual defect features respectively, remove the virtual cloth defect images that exceed the corresponding maximum value or are lower than the corresponding minimum value, and retain the remaining virtual cloth defect images to obtain morphologically compliant images; The system retrieves the established set of real defect statistical boundaries containing the boundary information of all real fabric sample intervals and initiates a step-by-step comparison and inspection process. For the generated virtual fabric defect image, firstly, it extracts the total number of virtual pixels and performs a size relationship judgment action with the maximum and minimum total number of pixels associated with the first item in the real boundary set. Next, it extracts the virtual maximum straight-line span value and performs a judgment action with the upper and lower limits of the real span, extracts the virtual horizontal tilt angle value and performs a judgment action with the upper and lower limits of the real angle, extracts the virtual distribution variance value and performs a judgment action with the upper and lower limits of the real variance, and finally extracts the full features of the virtual defect, namely the virtual defect grayscale difference value, and judges it with the upper and lower limit range of the real. When discarding virtual fabric defect images that exceed the corresponding maximum value or are lower than the corresponding minimum value, in this continuous 5-step multi-condition logical judgment sequence, if any value represented by a virtual parameter is higher than the corresponding upper limit maximum value in the real set, or if the value of the virtual parameter is lower than the corresponding real lower limit minimum value, a clear and recycle command for discarding the illegally generated image matrix is triggered. When generating images of remaining virtual cloth defects and obtaining morphologically compliant images, only if all five judgment steps described above are successfully completed without triggering any out-of-bounds warnings or discarding operations, will this generated 2D image data matrix, meeting all conditional specifications, be formally transferred from the temporary testing area to the target extended compliant image library address. This completes the closed-loop operation of obtaining morphologically compliant images. The execution node of this logic lies in determining whether the variant violates real physical limits through a hard comparison operation of boundary thresholds, thereby deciding whether to retain or discard it.
[0027] Please see Figure 5 Step S4 is as follows: S401: For virtual cloth defects in shaped compliant images, generate images by extracting the virtual gray-level co-occurrence matrix of the virtual defect region in the generated image. Extract the virtual local gray-level contrast value, virtual distribution uniformity value, virtual distribution randomness value, and virtual spatial correlation value from the virtual gray-level co-occurrence matrix and concatenate them to generate a virtual texture distribution vector. Calculate the virtual local binary pattern value of the virtual defect region in the generated image, count the occurrence frequency of all virtual local binary pattern values and arrange them in descending order to construct a virtual structure distribution vector. When extracting virtual fabric defects to generate a virtual gray-level co-occurrence matrix for virtual defect regions within an image, the rule is directly adopted by shifting the coordinates one pixel to the right horizontally. The joint frequency of the corresponding center position and its adjacent pixels within the virtual connected domain is statistically analyzed, and the normalized frequency results are substituted into the initial two-dimensional statistical matrix to construct the mapping relationship. When concatenating the virtual local gray-level contrast, virtual distribution uniformity, virtual distribution randomness, and virtual spatial correlation values extracted from the virtual gray-level co-occurrence matrix, the virtual local gray-level contrast is calculated based on the normalized statistical matrix using the sum of the squared differences. The virtual distribution uniformity is calculated using the sum of the squares of all elements. The virtual distribution randomness is obtained by multiplying by the natural logarithm and then adding and subtracting. The virtual spatial correlation is obtained by multiplying and adding the row and column margin deviations. Subsequently, in the array structure, the above four values are concatenated sequentially according to the previously extracted index order to form a virtual texture distribution vector. When calculating the virtual local binary pattern values of the virtual defect region within the virtual fabric defect generated image, a 3x3 sliding detection and comparison window is established for all independent center points within the feature boundary generated by the expanded image. Gray-level comparison operations are performed sequentially along a ring of adjacent points, outputting an 8-bit local binary sequence array composed of 0s or 1s. A hybrid conversion process of product and addition with power-law weights is performed to obtain the decimal integer label for each local region. When counting the occurrences of all virtual local binary pattern values and constructing a virtual structure distribution vector in descending order, a counting sequence covering the entire grayscale calibration range is established. The obtained decimal integer labels are used as position indices to fill the corresponding positions, and a counting step of incrementing by 1 is performed. After completing the statistics, bubble sort is used to sequentially swap adjacent data elements from largest to smallest, shifting and recombining them to construct and output a virtual structure distribution vector containing the full frequency performance characteristics.
[0028] S402: Extract the virtual pixel gray level value and virtual gradient direction of each virtual pixel in the virtual fabric defect region of the generated image. Calculate the occurrence frequency of each virtual pixel gray level value and arrange them in ascending order. Construct a virtual gray level change histogram vector. Divide the virtual gradient direction into multiple virtual gradient direction intervals. Count the number of virtual interval pixels in each virtual gradient direction interval and arrange them in interval order. Construct a virtual appearance gradient direction vector. The grayscale constant bound to each coordinate address within the corresponding foreground and background segmentation region of the augmented image is the virtual pixel grayscale value. For obtaining the virtual gradient direction, a 3x3 local convolution kernel with horizontal and vertical component filtering is used to perform cross-multiplication and sliding convolution calculations with the target pixel matrix. The ratio of the two convolution outputs is calculated, and then the inverse triangular transformation mapping structure is consulted to obtain the derivative direction towards polar coordinates, which is the virtual gradient direction. When calculating the occurrence frequency of each virtual pixel grayscale value and arranging them in ascending order to construct the virtual grayscale change histogram vector, the address index values from 0 to 255 are associated with an independent counting slot array. The grayscale level read from the global coordinates is used as a trigger condition to control the count value within the target slot to complete the self-incrementing action. After statistical closure, a min-heap sorting process with comparison and permutation functions is used to perform ascending shift and integration operations on the count value array to construct the virtual grayscale change histogram vector. The virtual gradient direction is divided into multiple virtual gradient direction intervals. When constructing the virtual appearance gradient direction vector by counting the number of virtual interval pixels in each virtual gradient direction interval and arranging them in interval order, eight range closed-loop isolation domain counting groups with an interval set at 45 degrees are constructed. When it is determined that the obtained virtual gradient direction angle is within the specific condition limit, the command to increase the step count value by 1 is executed in the cumulative slot corresponding to the reserved interval domain. After the statistics are completed, the total number of pieces placed in the eight slots is assembled in order from the head range to the tail range to construct the output virtual appearance gradient direction vector.
[0029] S403: Concatenate the virtual texture distribution vector, virtual structure distribution vector, virtual grayscale variation histogram vector, and virtual appearance gradient direction vector to obtain a set of virtual distribution parameters; A contiguous memory segment with 524 elements is allocated on the data bus. The virtual texture distribution vector with four parameter features, obtained earlier, is loaded into the first cell of this contiguous memory segment. Then, the cursor is shifted backward to sequentially write a virtual structure distribution vector composed of 256 statistical values into the subsequent cells of this contiguous memory segment. Following this, a virtual grayscale change histogram vector composed of 256 permutation count values is loaded into the contiguous memory segment. Finally, a virtual appearance gradient direction vector with eight slot count values is filled into the last cell of the remaining data segment. Through this one-dimensional linked list concatenation process, a one-dimensional feature array, i.e., a virtual distribution parameter set, is constructed to comprehensively represent the overall performance of the target virtual data. Through this single-dimensional parameter assembly operation, the system achieves full-domain aggregation mapping of spatially and color-heterogeneous data, establishing a benchmark for the feature dimensions of virtual generated data, laying the data format foundation for further comparison of data gaps.
[0030] Please see Figure 6Step S5 is as follows: S501: Calculate the second optimal transmission distance between each parameter in the virtual distribution parameter set and each parameter in the corresponding real distribution parameter set; the calculation of the second optimal transmission distance includes: calculating the vector distance between the virtual texture distribution vector and the defect texture distribution vector, the virtual structure distribution vector and the defect structure distribution vector, the virtual grayscale change histogram vector and the defect grayscale change histogram vector, and the virtual appearance gradient direction vector and the defect appearance gradient direction vector in the virtual distribution parameter set and the corresponding real distribution parameter set, and constructing a virtual parameter distance matrix based on all vector distances; calculating the sum of the products of the corresponding matrix elements of the virtual parameter distance matrix and the preset virtual joint probability distribution matrix, and extracting the minimum value of the sum of the products of all corresponding matrix elements to determine the second optimal transmission distance; For newly generated and successfully saved extended virtual fabric defect image samples in the process, vector feature comparison is performed. When calculating the vector distances between the virtual distribution parameter set and the corresponding real distribution parameter set, specifically between the virtual texture distribution vector and the defect texture distribution vector, between the virtual structure distribution vector and the defect structure distribution vector, between the virtual grayscale change histogram vector and the defect grayscale change histogram vector, and between the virtual appearance gradient direction vector and the defect appearance gradient direction vector, for two parameter vectors of the same type paired at each specific alignment position, the corresponding array elements are extracted. The difference is calculated by subtracting the subtrahend from the minuend, and the absolute value of this difference is converted. The absolute deviations calculated for all corresponding positions of the same type are then summed. This summation is directly used as the vector distance describing the mutual deviation. When constructing the virtual parameter distance matrix based on all vector distances, the four global vector distances obtained from the four comparison combinations are sequentially arranged and combined into a 4x4 two-dimensional virtual parameter distance matrix using a matrix initialization format with fixed row and column steps. When calculating the sum of the products of corresponding matrix elements of the virtual parameter distance matrix and the preset virtual joint probability distribution matrix, a virtual joint probability distribution matrix of the same 4x4 two-dimensional row and column size is generated. Using a double-nested loop addressing logic, the element at a specified intersection of the two matrices of the same size is located. The specific values stored in both matrices are directly extracted to perform a cross-multiplication. After multiplying all 16 positions and calculating the product, the 16 product results are concatenated and continuously added together to obtain the sum of a single scalar product. When extracting the minimum value from the sum of the products of all corresponding matrix elements to determine the second optimal transmission distance, the Sinkhorn iteration method is applied to change the allocation ratio of the probability matrix constraint weight parameter. Through repeated iterations of the corresponding matrix products and summation of the results, the sum of the results obtained from the old and new calculations is continuously compared until the sum of the scalar products calculated from multiple consecutive calculations no longer shows a decreasing trend. The comparison process ends, and the minimum lower bound value in the record is extracted and assigned to the final second optimal transmission distance.
[0031] S502: Select virtual fabric defect images from morphologically compliant images where the second optimal transmission distance is less than the average value of the first optimal transmission distance, and use them as a candidate enhanced defect image set; When the candidate enhancement defect image set is obtained, the average value of all first optimal transmission distances determined after preprocessing is read from the global variable region. The final calculated target comparison data, i.e., the second optimal transmission distance, is extracted. A size relationship comparison and verification mechanism is initiated. The core of the comparison operation provides a Boolean flag command based on whether the input value of the tested object exceeds the preset reference threshold. Through built-in numerical judgment logic, it is determined whether the second optimal transmission distance is less than the defined comparison average baseline. If the judgment result meets the condition of being less than the average baseline, a retention operation instruction is triggered to perform the operation, associating the compliant image with the data block containing the virtual fabric defect generated image, adding a valid acceptance label, and classifying it into the established candidate enhancement defect image set category. If the second optimal transmission distance of the generated image is greater than or equal to the judgment baseline, a low-level deletion instruction is dispatched to remove the invalid forged variant. The execution node of this calculation logic is to obtain the discrimination result by comparing the second optimal transmission distance with the global average threshold, thereby triggering subsequent operations in the background to archive valid variant images and delete invalid images. By introducing this objective screening process, it is ensured that only enhanced primitives that meet the lower limit of the principle of no distortion in distribution characteristics can be included in the subsequent process.
[0032] S503: Append the candidate enhanced defect image set to multiple sets of original fabric images and perform total data augmentation processing to establish a target fabric defect image data enhancement set; The core dataset file containing the previously collected and stored original fabric images is opened. Using the file append operation mode, following the first-in, first-out (FIFO) order of data inflow, each virtual two-dimensional image matrix data with qualified augmentation status that passed the verification in the previous stage and was placed in the candidate enhancement defect image set is continuously and sequentially inserted into the end queue segment of the original dataset. After continuously and iteratively executing this item-by-item end-to-end stacking and splicing operation command on all qualified candidate matrix sequences, the total physical quantity of the target image library specimens retained for subsequent model reading is expanded from a scarce and weak initial state to a rich and complete combination of variants. After confirming that the appending is complete, the write stream channel is closed, and the target fabric defect image data augmentation set is established. The effectiveness was verified using actual engineering training classification accuracy test data. The data showed that after the above-mentioned data expansion process and the establishment of an expanded set that eliminated distribution distortion terms by combining the first optimal transmission distance constraint logic, the model was fed into the subsequent network layer for training. Compared with the traditional unscreened direct incremental method, the verification accuracy reached 94.2%, the recognition accuracy was significantly improved by 6.2%, and the overall training convergence time of the model was shortened from the original 50 hours to 32.5 hours, reaching the gradient descent convergence state earlier. The model's computational efficiency and recognition accuracy achieved measurable improvements in both aspects at the practical engineering execution level.
[0033] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for generating and augmenting fabric defect images, characterized in that, Includes the following steps: S1: Collect original images of fabric with real physical defects, determine the set of real defect morphological parameters of the original fabric images, count the maximum and minimum values of each parameter in the set of real defect morphological parameters, and generate a set of real defect statistical boundaries. S2: Determine the true distribution parameter set of the original fabric image, and calculate the first optimal transmission distance and the average value of the first optimal transmission distance among the true distribution parameter sets associated with multiple sets of original fabric images; S3: Perform geometric space transformation and color space translation on the original fabric image to generate virtual fabric defect images. Filter the virtual fabric defect images with reference to the set of real defect statistical boundaries and combine them into shaped compliant images. S4: Determine the set of virtual distribution parameters for the virtual fabric defect generation image after screening in the morphologically compliant image; S5: Calculate the second optimal transmission distance between the virtual distribution parameter set and the corresponding real distribution parameter set, compare it with the average value of the first optimal transmission distance, expand the total data of the fabric defect image according to the comparison result, and generate a target fabric defect image data enhancement set.
2. The method for generating and enhancing fabric defect images according to claim 1, characterized in that, The set of real defect morphology parameters includes the total number of fabric defect pixels, the maximum straight-line span of the defect, the horizontal tilt angle of the span, the variance of the edge coordinate distribution, and the weighted compensation grayscale difference of the defect. The first optimal transmission distance is specifically calculated by the set of real distribution parameters associated with multiple sets of original fabric images. The morphologically compliant images include virtual fabric defect generated images that do not exceed the corresponding maximum value and virtual fabric defect generated images that do not fall below the corresponding minimum value. The set of virtual distribution parameters includes virtual texture distribution vector, virtual structure distribution vector, virtual grayscale change histogram vector, and virtual appearance gradient direction vector. The target fabric defect image data enhancement set includes the selected virtual fabric defect generated images and multiple sets of original fabric images.
3. The method for generating and enhancing fabric defect images according to claim 1, characterized in that, Step S1 is as follows: S101: Acquire the original image with real defects, obtain the production line environment brightness parameters at the same time node as the original image acquisition, extract the total number of pixels in the defect area divided based on real defects in the original image, calculate the maximum straight-line span of the pixels at both ends of the defect area, measure the horizontal tilt angle corresponding to the maximum straight-line span, and at the same time calculate the distribution variance of the pixel coordinates of the defect edge corresponding to the defect area. S102: Determine the flawless background area, obtain the grayscale values of all pixels in the defective area and the grayscale values of all background pixels in the flawless background area, calculate the difference between the average grayscale value of pixels in the defective area and the average grayscale value of background pixels in the flawless background area, calculate the ratio of the production line environment brightness parameter to the preset standard brightness value, generate a dimensionless brightness compensation coefficient, multiply the dimensionless brightness compensation coefficient by the difference value to obtain the defect weighted compensation grayscale difference value; S103: Obtain the total number of pixels, the maximum straight-line span, the horizontal tilt angle, the distribution variance, and the defect weighted compensation grayscale difference, establish a set of real defect morphology parameters, extract the maximum and minimum values of each parameter in the set of real defect morphology parameters associated with multiple sets of original fabric images, and obtain a set of real defect statistical boundaries.
4. The method for generating and augmenting fabric defect images according to claim 3, characterized in that, Step S2 is as follows: S201: Calculate the gray-level co-occurrence matrix in the defect region of the original fabric image, extract the local gray-level contrast value, distribution uniformity value, distribution randomness value and spatial correlation value of the gray-level co-occurrence matrix, generate the defect texture distribution vector, calculate the local binary pattern value in the defect region, count the occurrence of all local binary pattern values and sort them in descending order to obtain the defect structure distribution vector. S202: Obtain the gray level value and gradient direction of each pixel in the defect area, calculate the number of times the gray level value of each pixel appears, arrange all the occurrences in ascending order, construct the gray level change histogram vector of the defect, divide the gradient direction into multiple gradient direction intervals, count the number of pixels in each gradient direction interval, arrange the interval pixel counts in interval order, and construct the gradient direction vector of the defect appearance. S203: Combining the defect texture distribution vector, the defect structure distribution vector, the defect grayscale change histogram vector, and the defect appearance gradient direction vector, establish a set of true distribution parameters, calculate the first optimal transmission distance between the true distribution parameter sets associated with multiple sets of original fabric images, and the average value of all first optimal transmission distances.
5. The method for generating and enhancing fabric defect images according to claim 4, characterized in that, Step S3 is as follows: S301: Perform geometric space transformation and color space translation on the original fabric image to generate a virtual fabric defect image. Divide the virtual defect area and the virtual flawless background area in the virtual fabric defect image. Extract the total number of virtual pixels in the virtual defect area. Calculate the virtual maximum straight-line span of the pixels at both ends of the virtual defect area. Measure the virtual horizontal tilt angle corresponding to the virtual maximum straight-line span. Extract the pixel coordinates of the virtual defect edge. Calculate the virtual distribution variance of the pixel coordinates of the virtual defect edge in the virtual defect area corresponding to the virtual defect. Obtain the virtual basic morphological features. S302: Obtain the grayscale values of all virtual pixels within the virtual defect area and the grayscale values of all virtual background pixels within the flawless background area, calculate the virtual defect grayscale difference between the average virtual pixel grayscale value within the virtual defect area and the average virtual background pixel grayscale value within the flawless background area, and obtain the full virtual defect features. S303: Compare the maximum and minimum values of each parameter in the virtual basic morphological features and the virtual defect full features respectively, remove the virtual cloth defect generated images that exceed the corresponding maximum value or are lower than the corresponding minimum value, and retain the remaining virtual cloth defect generated images to obtain morphologically compliant images.
6. The method for generating and data augmenting fabric defect images according to claim 5, characterized in that, Step S4 is as follows: S401: For the virtual fabric defect generated image in the morphologically compliant image, extract the virtual gray-level co-occurrence matrix of the virtual defect region in the virtual fabric defect generated image, extract the virtual local gray-level contrast value, virtual distribution uniformity value, virtual distribution randomness value and virtual spatial correlation value in the virtual gray-level co-occurrence matrix and stitch them together to generate a virtual texture distribution vector, calculate the virtual local binary pattern value of the virtual defect region in the virtual fabric defect generated image, count the occurrence times of all virtual local binary pattern values and arrange them in descending order to construct a virtual structure distribution vector; S402: Extract the virtual pixel gray level value and virtual gradient direction of each virtual pixel in the virtual fabric defect region of the virtual fabric defect generated image, calculate the occurrence frequency of each virtual pixel gray level value and arrange them in ascending order, construct a virtual gray level change histogram vector, divide the virtual gradient direction into multiple virtual gradient direction intervals, count the number of virtual interval pixels in each virtual gradient direction interval and arrange them in interval order, and construct a virtual appearance gradient direction vector; S403: Concatenate the virtual texture distribution vector, the virtual structure distribution vector, the virtual grayscale change histogram vector, and the virtual appearance gradient direction vector to obtain a set of virtual distribution parameters.
7. The method for generating and enhancing fabric defect images according to claim 6, characterized in that, Step S5 is as follows: S501: Calculate the second optimal transmission distance between each parameter in the virtual distribution parameter set and the corresponding parameter in the real distribution parameter set; S502: Select virtual fabric defect images from morphologically compliant images where the second optimal transmission distance is less than the average value of the first optimal transmission distance, and use them as a candidate enhanced defect image set; S503: The candidate enhanced defect image set is appended and stitched to multiple sets of original fabric images to perform total data expansion processing, and a target fabric defect image data enhancement set is established.
8. The method for generating and enhancing fabric defect images according to claim 4, characterized in that, Calculating the first optimal transmission distance includes: Perform extreme value normalization operations on the defect texture distribution vector, defect structure distribution vector, defect grayscale change histogram vector, and defect appearance gradient direction vector in multiple sets of real distribution parameters; Calculate the Euclidean distances between the normalized sets of defect texture distribution vectors, defect structure distribution vectors, defect grayscale change histogram vectors, and defect appearance gradient direction vectors. The true distribution difference matrix is generated by combining all the corresponding Euclidean distances. Construct the true joint probability matrix corresponding to the true distribution difference matrix; Calculate the sum of the products of corresponding matrix elements of the true distribution difference matrix and the true joint probability matrix; The minimum value among the sum of the products of all corresponding matrix elements is used to determine the first optimal transmission distance.
9. The method for generating and data augmenting fabric defect images according to claim 5, characterized in that, The geometric space transformation and color space translation processing of the original fabric image includes remapping the spatial positions of all pixels in the original fabric image according to a preset rotation angle and a preset scaling ratio, and adjusting the color channel values of each pixel in the original fabric image after spatial remapping by summing and adjusting the values according to a preset color offset.
10. The method for generating and data augmenting fabric defect images according to claim 7, characterized in that, Calculating the second optimal transmission distance includes: Calculate the vector distances between the virtual distribution parameter set and the corresponding real distribution parameter set, specifically between the virtual texture distribution vector and the defect texture distribution vector, between the virtual structure distribution vector and the defect structure distribution vector, between the virtual grayscale change histogram vector and the defect grayscale change histogram vector, and between the virtual appearance gradient direction vector and the defect appearance gradient direction vector. Construct a virtual parameter distance matrix based on all vector distances. Calculate the sum of the products of corresponding matrix elements of the virtual parameter distance matrix and the preset virtual joint probability distribution matrix, and extract the minimum value among all the sums of the products of corresponding matrix elements to determine the second optimal transmission distance.