An image defect sample generation method, system, computer device, and medium
The method addresses the challenge of spatial scale variations in fabric defect detection by annotating and transforming defect regions based on aspect ratios and areas, generating diverse samples to improve model accuracy.
Patent Information
- Application Number
- CN202210936687.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-05
- Publication Date
- 2025-07-15
- Estimated Expiration
- 2042-08-05
AI Technical Summary
When generating cloth defect detection data samples, the prior art cannot effectively deal with the targets with large spatial scale differences, resulting in limited distribution of the generated sample morphology and cannot meet the needs of model training.
By annotating the grey defect dataset, the aspect ratio and area of the target box are calculated, the target box is classified, and the scaling factor is set according to the preset aspect ratio and area, the defect images in the target box are transformed to generate image defect samples of multiple scales and forms.
It expands the morphological distribution of the data generation space, improves the detection accuracy of downstream models, and can generate more diverse defect samples to meet the needs of model training.
Smart Images

Figure CN115345841B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image generation, and more specifically, to an image defect sample generation method, system, computer device, and medium. Background Art
[0002] Due to the ability to automatically extract image features, deep neural networks have gradually replaced the traditional visual feature extraction methods of manually making features in computer vision fields such as image recognition and object detection, and are also increasingly widely used in the field of industrial quality inspection. Cloth defect detection is an important task in the textile industry. With the promotion of the national strategy of digital industrial upgrading, the replacement of manual inspection with automated greige cloth defect detection has become a trend, and deep learning has also become an important method for industrial visual defect detection.
[0003] The main processes of greige cloth defect detection based on deep learning methods include data collection, data annotation and processing, model training, compression, optimization, and model deployment. There are many forms of greige cloth defect categories in actual production scenarios. However, the frequency of defect occurrence is low and the collection of defect data is difficult. Therefore, generating sufficient defect image data using a small number of image samples for each category has become an important link in the implementation process. Currently, the data generation method for greige cloth defect object detection is image-level generation, such as color generation by adjusting the brightness and contrast of images, or optical geometric transformations such as image flipping, affine transformation, and perspective transformation.
[0004] However, for cloth defect detection, there may often be targets with large differences in spatial scales in the image. For example, some edge breakage and bar defects have particularly large areas, while some dot-like defects such as foreign objects woven in and flying flowers have very small areas. In addition, warp defects such as broken warp and double warp, and weft defects such as double weft and thick weft also have the characteristic of large aspect ratio differences. Only using the global generation method at the image level to process these targets with huge spatial scale differences, the morphological distribution of the generated samples is very limited and is not enough for the quantity of samples required for model training. Summary of the Invention
[0005] Aiming at the deficiencies of the existing technology, the purpose of the present invention is to provide an image defect sample generation method, system, computer device, and medium, which has the advantage of being able to generate a large number of samples for cloth defect detection.
[0006] The above technical objective of the present invention is achieved through the following technical solutions: An image defect sample generation method includes:
[0007] Annotating a pre-collected greige cloth defect data set to obtain a number of target boxes with defective images;
[0008] Calculate the aspect ratios and areas of all target bounding boxes;
[0009] Classify each target bounding box according to a preset aspect ratio, a preset area, and the aspect ratios and areas of each target bounding box;
[0010] Determine the scaling factors for all classified target bounding boxes;
[0011] Transform each target bounding box corresponding to each classification according to the scaling factor corresponding to each classification to obtain a number of image defect samples.
[0012] Optionally, the labeling of the pre-collected fabric defect dataset to obtain a number of target bounding boxes with defective images includes:
[0013] Perform polygon bounding box labeling on various defects of all images in the pre-collected fabric defect dataset to obtain a number of polygon bounding boxes;
[0014] Determine the center point coordinate values of each polygon bounding box according to the number of polygon bounding boxes;
[0015] Generate a minimum rectangular bounding box for accommodating the corresponding polygon bounding box at any rotation angle according to each center point coordinate value to obtain a number of target bounding boxes with defective images.
[0016] Optionally, the calculation of the aspect ratios and areas of all target bounding boxes includes:
[0017] Obtain the width values and height values of all target bounding boxes;
[0018] Calculate the aspect ratio and area of the corresponding target bounding box according to the width value and height value of each target bounding box.
[0019] Optionally, the classification of each target bounding box according to a preset aspect ratio, a preset area, and the aspect ratios and areas of each target bounding box includes:
[0020] Compare the aspect ratio of each target bounding box with the preset aspect ratio, and classify the target bounding box with an aspect ratio greater than 5:1 as a weft dimension target bounding box; classify the target bounding box with an aspect ratio less than 1:5 as a radial dimension target bounding box;
[0021] For the target bounding boxes with aspect ratios between 1:5 and 5:1, compare the area of each target bounding box with the preset area, classify those with an area greater than 1000 as large-size target bounding boxes, and classify those with an area less than 1000 as small-size target bounding boxes.
[0022] Optionally, the transformation of each target bounding box corresponding to each classification according to the scaling factor corresponding to each classification to obtain a number of image defect samples includes:
[0023] Calculate the enhanced heat values corresponding to each target box for each classification according to each scaling factor;
[0024] Draw the corresponding enhanced heat map according to each enhanced heat value;
[0025] Perform optical transformation on the images within the corresponding target boxes according to each enhanced heat map to obtain a number of image defect samples.
[0026] Optionally, the step of transforming each target box corresponding to each classification according to the scaling factor corresponding to each classification to obtain a number of image defect samples includes:
[0027] Perform horizontal flipping, vertical flipping and affine transformation on all target boxes to obtain a number of first defect samples;
[0028] Perform horizontal translation and replication on the radial scale target boxes to obtain a number of second defect samples;
[0029] Perform vertical translation and replication on the latitudinal scale target boxes to obtain a number of third defect samples;
[0030] Perform moving and replication on the small scale target boxes to obtain a number of fourth defect samples;
[0031] Enlarge the small scale target boxes, and the magnification factor ranges from 1.0 to the scaling factor corresponding to the small scale target boxes, to obtain a number of fifth defect samples;
[0032] Obtain a number of image defect samples according to the number of first defect samples, second defect samples, third defect samples, fourth defect samples, and fifth defect samples.
[0033] Optionally, the step of transforming each target box corresponding to each classification according to the scaling factor corresponding to each classification to obtain a number of image defect samples further includes:
[0034] Intercept the defective images within each target box;
[0035] Attach all defective images to the good product pictures respectively to obtain a number of image defect samples.
[0036] An image defect sample generation system includes:
[0037] A defect annotation module, configured to annotate a pre-collected fabric defect data set to obtain a number of target boxes with defective images;
[0038] A width and height calculation module, configured to calculate the aspect ratio and area of all target boxes;
[0039] A target box classification module, configured to classify each target box according to a preset aspect ratio, a preset area, and the aspect ratio and area of each target box;
[0040] A scaling determination module, configured to determine the scaling factors of all classified target bounding boxes;
[0041] A sample generation module, configured to transform each target bounding box corresponding to each classification according to the scaling factor corresponding to each classification, to obtain a plurality of image defect samples.
[0042] A computer device, comprising a memory and a processor, where the memory stores a computer program, and when the processor executes the computer program, the steps of the above method are implemented.
[0043] A computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the above method are implemented.
[0044] In summary, the present invention has the following beneficial effects: All the parts containing defects in the defective fabric images in the fabric defect dataset are labeled, and target bounding boxes containing the defective images are generated. Then, the aspect ratios and areas of all the target bounding boxes are calculated to determine the scale classification of the corresponding target bounding boxes, and corresponding scaling factors are set according to the scale classification of each target bounding box. Then, the defective images within the corresponding target bounding boxes are transformed according to the scaling factors. Since only the defective images within the target bounding boxes are transformed, it is possible to further expand the morphological distribution of the data generation space on the basis of the original image level generation, thereby improving the accuracy of the downstream training model. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] Figure 1 is a flowchart of the present invention;
[0046] Figure 2 is a structural block diagram when the present invention is assembled;
[0047] Figure 3 is an internal structural diagram of the computer device in an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0048] In order to make the objectives, features, and advantages of the present invention more obvious and understandable, the following detailed description of the specific embodiments of the present invention is provided with reference to the accompanying drawings. Several embodiments of the present invention are shown in the accompanying drawings. However, the present invention can be implemented in many different forms and is not limited to the embodiments described herein.
[0049] In the present invention, unless otherwise clearly defined and limited, terms such as "installation", "connection", "linkage", "fixation" shall be understood in a broad sense. For example, it may be a fixed connection, a detachable connection, or an integral connection; it may be a mechanical connection or an electrical connection; it may be a direct connection or an indirect connection through an intermediate medium, and it may be the communication inside two components. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances. The terms "first" and "second" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. Thus, the features defined with "first" and "second" may explicitly or implicitly include one or more of such features.
[0050] In the present invention, unless otherwise clearly defined and limited, the first feature being "above" or "below" the second feature may include the direct contact between the first and second features, or may include the situation where the first and second features are not in direct contact but in contact through additional features therebetween. Moreover, the first feature being "above", "over" and "on the top of" the second feature includes that the first feature is directly above and obliquely above the second feature, or merely indicates that the horizontal height of the first feature is higher than that of the second feature. The first feature being "under", "beneath" and "under the bottom of" the second feature includes that the first feature is directly below and obliquely below the second feature, or merely indicates that the horizontal height of the first feature is lower than that of the second feature. The terms "vertical", "horizontal", "left", "right", "above", "below" and similar expressions are only for the purpose of illustration, rather than indicating or implying that the indicated device or element must have a specific orientation, be constructed and operated in a specific orientation, and thus cannot be understood as a limitation to the present invention.
[0051] The present invention will be described in detail below with reference to the accompanying drawings and embodiments.
[0052] The present invention provides an image defect sample generation method, as Figure 1 shown, including:
[0053] Step 100: Label the pre-collected grey cloth defect data set to obtain a number of target boxes with defective images;
[0054] Step 200: Calculate the aspect ratios and areas of all the target boxes;
[0055] Step 300: Classify each target box according to the preset aspect ratio, preset area, and the aspect ratios and areas of each target box;
[0056] Step 400: Determine the scaling factors of all the classified target boxes;
[0057] Step 500: Transform each target box corresponding to each category according to the scaling factor corresponding to each category to obtain a number of image defect samples.
[0058] In practical applications, a number of defective greige fabric pictures are stored in the greige fabric defect dataset; mark the defective parts in all the greige fabric defect images in the greige fabric defect dataset, and generate target boxes containing the defective images. Then, calculate the aspect ratios and areas of all the target boxes to determine the scale classification of the corresponding target boxes, set the corresponding scaling factors according to the scale classification of each target box, and then transform the defective images in each target box corresponding to each category according to the scaling factor. Since only the defective images in the target boxes are transformed, it is possible to further expand the morphological distribution of the data generation space on the basis of the original image level, thereby improving the accuracy of the downstream training model.
[0059] Further, the marking of the pre-collected greige fabric defect dataset to obtain a number of target boxes with defective images includes:
[0060] Perform polygon box marking on various defects in all the images in the pre-collected greige fabric defect dataset to obtain a number of polygon boxes;
[0061] Determine the center point coordinate values of each polygon box according to the number of polygon boxes;
[0062] Generate the smallest rectangular box for accommodating the corresponding polygon box at any rotation angle according to each center point coordinate value through geometric morphology to obtain a number of target boxes with defective images.
[0063] In practical applications, use a marking tool to perform polygon box marking on various defects in all the images in the greige fabric defect dataset. The polygon box needs to fit the corresponding defect boundary, take the center point of the corresponding polygon box, establish a coordinate system with the vertex of the image as the coordinate origin and the pixel point as the unit, and obtain the corresponding center point coordinate value. Then, use geometric morphology to find the smallest rectangular box that can accommodate any rotation of the corresponding polygon box, which is the target box with the defective image.
[0064] Optionally, the calculation of the aspect ratios and areas of all the target boxes includes:
[0065] Obtain the width values and height values of all the target boxes;
[0066] Calculate the aspect ratios and areas of the corresponding target boxes according to the width values and height values of each target box.
[0067] In practical applications, when obtaining the corresponding target box, the width value and height value of the target box can be determined through the coordinate system, and then the aspect ratio and area of the corresponding target box can be calculated.
[0068] Optionally, classifying each target frame according to a preset aspect ratio and a preset area and the aspect ratio and area of each target frame includes:
[0069] The aspect ratio of each target frame is compared with the preset aspect ratio, and the target frame with an aspect ratio greater than 5:1 is classified as a latitudinal size target frame; the target frame with an aspect ratio less than 1:5 is classified as a radial size target frame;
[0070] For target frames with aspect ratios between 1:5 and 5:1, the area of each target frame is compared with the preset area, and those with an area greater than 1000 are classified as large-size target frames, and those with an area less than 1000 are classified as small-size target frames.
[0071] In practical applications, in cloth defect detection, due to the large difference in aspect ratio between warp defects such as broken warp and double warp and weft defects such as double weft and coarse weft, it is necessary to process the defects with large aspect ratio and small aspect ratio separately. In this embodiment, the target frame with aspect ratio greater than 5:1 is defined as the weft size target frame, and the target frame with aspect ratio less than 1:5 is defined as the radial size target frame; and for targets with larger areas such as broken edges and broken fenders, those with an area greater than 1000 are defined as large size target frames; and the areas of some point defects such as foreign bodies woven into and flying flowers are often very small, so those with an area less than 1000 are defined as small size target frames. Among them, the scaling factor for the large-scale target frame is set to 0.8; the scaling factor for the small-scale target frame is set to 1.2; and the scaling factors for the radial scale target frame and the weft scale target frame are set to 1.0.
[0072] Furthermore, each target frame corresponding to each category is transformed according to the scaling factor corresponding to each category to obtain several image defect samples:
[0073] Calculate the enhanced thermal value corresponding to each target box corresponding to each classification according to each scaling factor;
[0074] According to each enhanced thermal value, a corresponding enhanced thermal map is obtained;
[0075] According to the enhanced thermal map, the images in all target boxes are optically transformed to obtain several image defect samples.
[0076] In practical applications,
[0077] Among them, W, H are the width and height of the image, w and h are the width and height of the target box, and x c and c are the coordinates of the center point of the target box. For a given image, W and H are fixed values. For a given target box, w, h, xc, yc are inherent attributes and are also fixed values.
[0078] After the scaling factor r is determined, given the coordinate values x and y of a pixel point in the image, the enhanced heat value α(x, y) of the pixel point can be calculated based on the above two formulas; then, according to the enhanced heat values of each pixel point within the target box, the enhanced heat map corresponding to the target box is drawn; and the degree of optical transformation of the image within the target box is controlled according to the enhanced heat map; the higher the enhanced heat value of a pixel point, the higher the numerical value of its optical transformation. After passing through the Gaussian enhanced heat map, the pixels at the boundary of the target box can be balanced, and the overall is more balanced. Among them, the generation transformation at the target box level bbox_value(x, y):
[0079] bbox_value(x, y) = transform_value(x, y) * α(x, y) + ori_value(x, y) * (1 - α(x, y)); for a certain pixel point with coordinate values x and y, its original pixel value is denoted as ori_value(x, y), and the transformed pixel value is denoted as transform_value(x, y). The optical transformation of the target box includes: color transformation, brightness adjustment, contrast adjustment, histogram equalization, sharpening, etc.
[0080] Furthermore, transforming each target box corresponding to each category according to the scaling factor corresponding to each category to obtain a number of image defect samples, including:
[0081] Performing horizontal flipping, vertical flipping, and affine transformation on all target boxes to obtain a number of first defect samples;
[0082] Performing horizontal translation and replication on the radial scale target box to obtain a number of second defect samples;
[0083] Performing vertical translation and replication on the latitudinal scale target box to obtain a number of third defect samples;
[0084] Performing moving and replication on the small-scale target box to obtain a number of fourth defect samples;
[0085] Enlarging the small-scale target box, with the magnification factor ranging from 1.0 to the scaling factor, to obtain a number of fifth defect samples;
[0086] Obtaining a number of image defect samples according to the number of first defect samples, second defect samples, third defect samples, fourth defect samples, and fifth defect samples.
[0087] In practical applications, spatial geometric transformations can also be performed according to the types of each target box. First, all types of target boxes can be horizontally flipped, vertically flipped, and affinely transformed to copy or rotate each defect feature. For the radial scale target box, due to its large radial scale, performing horizontal translation and copying on it can increase the number of radial defects. For the latitudinal scale target box, due to its large latitudinal scale, performing vertical translation and copying on it can increase the number of latitudinal defects. For the small-scale target box, magnifying and translating and copying it can increase the number of small-scale defects, and the magnification factor is 1.0 - 1.2.
[0088] Further, the step of transforming each target box corresponding to each classification according to the scaling factor corresponding to each classification to obtain a number of image defect samples further includes:
[0089] Cropping the defect images within each target box;
[0090] Fitting all the defect images with the good product pictures respectively to obtain a number of image defect samples.
[0091] In practical applications, the images of the defect areas are cropped out, and some good product samples are randomly selected. The defect images are fitted with the good product pictures, and the boundary fusion uses the methods of transparent image area fusion and redundant image fusion; this can further increase the number of defect samples.
[0092] As Figure 2 shown, the present invention also provides an image defect sample generation system, including:
[0093] A defect annotation module 10, configured to annotate a pre-collected fabric defect data set to obtain a number of target boxes with defect images;
[0094] A width and height calculation module 20, configured to calculate the aspect ratio and area of all target boxes;
[0095] A target box classification module 30, configured to classify each target box according to a preset aspect ratio, a preset area, and the aspect ratio and area of each target box;
[0096] A scaling determination module 40, configured to determine the scaling factors of all classified target boxes;
[0097] A sample generation module 50, configured to transform each target box corresponding to each classification according to the scaling factor corresponding to each classification to obtain a number of image defect samples.
[0098] Further, the defect annotation module 10 includes:
[0099] A boundary annotation unit for performing polygon frame annotation on various types of defects in all images in a pre-collected greige fabric defect dataset to obtain a number of polygon frames;
[0100] A center positioning unit for determining the center point coordinate values of each polygon frame according to a number of polygon frames;
[0101] A rectangle selection unit for generating, according to each center point coordinate value, a minimum rectangle frame for accommodating the corresponding polygon frame at any rotation angle through geometric morphology to obtain a number of target frames with defective images.
[0102] Further, the width-height calculation module 20 includes:
[0103] A width-height acquisition unit for acquiring the width values and height values of all target frames;
[0104] A width-height calculation unit for calculating the width-height ratio and area of the corresponding target frame according to the width value and height value of each target frame.
[0105] Further, the sample generation module 50 includes:
[0106] A Gaussian calculation unit for calculating the enhanced heat values corresponding to each target frame of each classification according to each scaling factor;
[0107] A heat map drawing unit for drawing the corresponding enhanced heat map according to each enhanced heat value;
[0108] An optical transformation unit for performing optical transformation on the images within all target frames according to the enhanced heat map to obtain a number of image defect samples.
[0109] Further, the sample generation module 50 further includes:
[0110] A flip transformation unit for performing horizontal flipping, vertical flipping and affine transformation on all target frames to obtain a number of first defect samples;
[0111] A radial translation unit for performing horizontal translation and replication on the radial scale target frames to obtain a number of second defect samples;
[0112] A weft translation unit for performing vertical translation and replication on the weft scale target frames to obtain a number of third defect samples;
[0113] A moving replication unit for performing moving replication on the small scale target frames to obtain a number of fourth defect samples;
[0114] A scale amplification unit for amplifying the small scale target frames, and the amplification factor is from 1.0 to the scaling factor, to obtain a number of fifth defect samples;
[0115] A sample integration unit for obtaining a number of image defect samples based on a number of first defect samples, second defect samples, third defect samples, fourth defect samples, and fifth defect samples.
[0116] Further, the sample generation module 50 further includes:
[0117] A defect extraction unit for intercepting defect images within each target box;
[0118] A defect fitting unit for fitting all defect images with good product pictures respectively to obtain a number of image defect samples.
[0119] For the specific limitations of an image defect sample generation system, reference can be made to the limitations of an image defect sample generation method in the above text, which will not be elaborated here. Each module of the above image defect sample generation system can be implemented in whole or in part by software, hardware, and their combination. The above modules can be embedded in the processor of a computer device in hardware form or be independent of it, or be stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to the above modules.
[0120] In one embodiment, a computer device is provided. The computer device can be a server, and its internal structure diagram can be as Figure 3 shown. The computer device includes a processor, a memory, a network interface, and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. When the computer program is executed by the processor, it implements an image defect sample generation method.
[0121] Those skilled in the art can understand that Figure 3 the structure shown in
[0122] In one embodiment, a computer device is provided, including a memory and a processor. A computer program is stored in the memory. When the processor executes the computer program, the following steps are implemented: including:
[0123] Label a pre-collected fabric defect data set to obtain a number of target boxes with defect images;
[0124] Calculate the aspect ratios and areas of all target bounding boxes;
[0125] Classify each target bounding box according to a preset aspect ratio, a preset area, and the aspect ratios and areas of the respective target bounding boxes;
[0126] Determine the scaling factors for all the classified target bounding boxes;
[0127] Transform each target bounding box corresponding to each classification according to the scaling factor corresponding to the classification to obtain a number of image defect samples.
[0128] In one embodiment, the annotating the pre-collected greige fabric defect data set to obtain a number of target bounding boxes with defective images includes:
[0129] Perform polygon bounding box annotation on various defects of all images in the pre-collected greige fabric defect data set to obtain a number of polygon bounding boxes;
[0130] Determine the center point coordinate values of each polygon bounding box according to the number of polygon bounding boxes;
[0131] Generate a minimum rectangular bounding box for accommodating the corresponding polygon bounding box at any rotation angle according to each center point coordinate value to obtain a number of target bounding boxes with defective images.
[0132] In one embodiment, the calculating the aspect ratios and areas of all target bounding boxes includes:
[0133] Obtain the width values and height values of all target bounding boxes;
[0134] Calculate the aspect ratio and area of the corresponding target bounding box according to the width value and height value of each target bounding box.
[0135] In one embodiment, the classifying each target bounding box according to a preset aspect ratio, a preset area, and the aspect ratios and areas of the respective target bounding boxes includes:
[0136] Compare the aspect ratio of each target bounding box with the preset aspect ratio, and classify the target bounding box with an aspect ratio greater than 5:1 as a weft dimension target bounding box; classify the target bounding box with an aspect ratio less than 1:5 as a radial dimension target bounding box;
[0137] For the target bounding boxes with aspect ratios between 1:5 and 5:1, compare the area of each target bounding box with the preset area, and classify those with an area greater than 1000 as large-size target bounding boxes and those with an area less than 1000 as small-size target bounding boxes.
[0138] In one embodiment, the transforming each target bounding box corresponding to each classification according to the scaling factor corresponding to the classification to obtain a number of image defect samples includes:
[0139] Calculate the enhanced heat values corresponding to each target box for each classification according to each scaling factor;
[0140] Draw the corresponding enhanced heat map according to each enhanced heat value;
[0141] Perform optical transformation on the images within all target boxes according to the enhanced heat map to obtain a number of image defect samples.
[0142] In one embodiment, the transformation of each target box corresponding to each classification according to the scaling factor corresponding to each classification to obtain a number of image defect samples includes:
[0143] Perform horizontal flipping, vertical flipping, and affine transformation on all target boxes to obtain a number of first defect samples;
[0144] Perform horizontal translation and replication on the radial scale target boxes to obtain a number of second defect samples;
[0145] Perform vertical translation and replication on the latitudinal scale target boxes to obtain a number of third defect samples;
[0146] Perform moving and replication on the small-scale target boxes to obtain a number of fourth defect samples;
[0147] Enlarge the small-scale target boxes, and the magnification factor is from 1.0 to the scaling factor, to obtain a number of fifth defect samples;
[0148] Obtain a number of image defect samples according to the number of first defect samples, second defect samples, third defect samples, fourth defect samples, and fifth defect samples.
[0149] In one embodiment, the transformation of each target box corresponding to each classification according to the scaling factor corresponding to each classification to obtain a number of image defect samples further includes:
[0150] Intercept the defective images within each target box;
[0151] Attach all defective images to the good product pictures respectively to obtain a number of image defect samples.
[0152] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to a memory, storage, database, or other medium used in the embodiments provided in the present application can include non-volatile and / or volatile memories. Non-volatile memories can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memories can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and Rambus dynamic RAM (RDRAM), etc.
[0153] The technical features of the above embodiments can be combined arbitrarily. For the sake of brevity of description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as the scope recorded in this specification.
[0154] The above is only the preferred embodiment of the present invention, and the protection scope of the present invention is not limited to the above embodiments. All technical solutions falling within the idea of the present invention belong to the protection scope of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present invention, several improvements and refinements should also be regarded as the protection scope of the present invention.
Claims
1. An image defect sample generation method, characterized in that Including: Annotating a pre - collected dataset of fabric defects to obtain a number of target boxes with defective images; Calculating the aspect ratio and area of each target box; Classifying each target box according to a preset aspect ratio, a preset area, the aspect ratio and area of each target box; Determining the scaling factor corresponding to each classification; Transforming each target box corresponding to each classification according to the scaling factor corresponding to each classification to obtain a number of image defect samples; The transforming each target box corresponding to each classification according to the scaling factor corresponding to each classification to obtain a number of image defect samples includes: Calculating the enhanced heat value corresponding to each target box of each classification according to each scaling factor; drawing the corresponding enhanced heat map according to each enhanced heat value; performing optical transformation on the image within the target box corresponding to each enhanced heat map to obtain a number of image defect samples; By , ; ; where W and H are the width and height of the image, and w and h are the width and height of the target box, and are the center point coordinates of the target box. For a given picture, W and H are fixed values; for a given target box, w, h, x c , y c are inherent attributes and also fixed values; After the scaling factor r is determined, given the coordinate values x, y of a pixel point in the image, calculate the enhanced heat value α(x, y) of the pixel point according to the formula; then draw the enhanced heat map corresponding to the target box according to the enhanced heat values of each pixel point within the target box; and control the degree of optical transformation of the image within the target box according to the enhanced heat map; the higher the enhanced heat value of a pixel point, the higher the numerical value of its optical transformation, and the Gaussian - enhanced heat map can balance the pixel point values bbox_value(x, y) at the boundary of the target box; Where bbox_value(x, y)=transform_value(x, y)*α(x, y)+ori_value(x, y)*(1 - α(x, y)); for a certain pixel point with coordinate values x, y, its original pixel point value is denoted as ori_value(x, y), and the transformed pixel point value is denoted as transform_value(x, y). The optical transformation of the target box includes: color transformation, brightness adjustment, contrast adjustment, histogram equalization, and sharpening.
2. The method according to claim 1, wherein The annotating a pre - collected dataset of fabric defects to obtain a number of target boxes with defective images includes: Performing polygon box annotation on various defects of all images in the pre - collected dataset of fabric defects to obtain a number of polygon boxes; Determining the center point coordinate values of each polygon box according to the number of polygon boxes; Generating a minimum rectangular box for accommodating the corresponding polygon box at any rotation angle according to each center point coordinate value through geometric morphology to obtain a number of target boxes with defective images.
3. The method according to claim 2, wherein The calculating the aspect ratio and area of each target box includes: Obtaining the width values and height values of all target boxes; Calculating the aspect ratio and area of the corresponding target box according to the width value and height value of each target box.
4. The method according to claim 3, wherein The classifying each target box according to a preset aspect ratio, a preset area, the aspect ratio and area of each target box includes: Comparing the aspect ratio of each target box with the preset aspect ratio, classifying the target box with an aspect ratio greater than 5:1 as a weft - direction size target box; classifying the target box with an aspect ratio less than 1:5 as a radial - direction size target box; For target bounding boxes with an aspect ratio ranging from 1:5 to 5:1, compare the area of each target bounding box with a preset area. Classify those with an area greater than 1000 as large-size target bounding boxes and those with an area less than 1000 as small-size target bounding boxes.
5. The method according to claim 4, wherein Transform each target bounding box corresponding to each classification according to the scaling factor corresponding to each classification to obtain a number of image defect samples, including: Calculate the enhanced heat value corresponding to each target bounding box corresponding to each classification according to each scaling factor; Draw a corresponding enhanced heat map according to each enhanced heat value; Perform an optical transformation on the image within the corresponding target bounding box according to each enhanced heat map to obtain a number of image defect samples.
6. The method according to claim 4, wherein Transform each target bounding box corresponding to each classification according to the scaling factor corresponding to each classification to obtain a number of image defect samples, including: Perform horizontal flipping, vertical flipping, and affine transformation on all target bounding boxes to obtain a number of first defect samples; Perform horizontal translation and replication on the radial scale target bounding box to obtain a number of second defect samples; Perform vertical translation and replication on the latitudinal scale target bounding box to obtain a number of third defect samples; Perform moving and replication on the small-scale target bounding box to obtain a number of fourth defect samples; Enlarge the small-scale target bounding box with a magnification factor ranging from 1.0 to the scaling factor corresponding to the small-scale target bounding box to obtain a number of fifth defect samples; Obtain a number of image defect samples based on the number of first defect samples, second defect samples, third defect samples, fourth defect samples, and fifth defect samples.
7. The method according to claim 4, characterized in that, Transform each target bounding box corresponding to each classification according to the scaling factor corresponding to each classification to obtain a number of image defect samples, and further include: Crop the defect images within each target bounding box; Attach all defect images to good product pictures respectively to obtain a number of image defect samples.
8. An image defect sample generation system, characterized in that, Include: A defect annotation module for annotating a pre-collected fabric defect data set to obtain a number of target bounding boxes with defect images; A width-height calculation module for calculating the aspect ratio and area of all target bounding boxes; A target bounding box classification module for classifying each target bounding box according to a preset aspect ratio, preset area, and the aspect ratio and area of each target bounding box; A scaling determination module for determining the scaling factor of all classified target bounding boxes; A sample generation module for transforming each target bounding box corresponding to each classification according to the scaling factor corresponding to each classification to obtain a number of image defect samples; Transform each target bounding box corresponding to each classification according to the scaling factor corresponding to each classification to obtain a number of image defect samples, including: Calculate the enhanced heat value corresponding to each target bounding box corresponding to each classification according to each scaling factor; draw a corresponding enhanced heat map according to each enhanced heat value; perform an optical transformation on the image within the target bounding box corresponding to each enhanced heat map to obtain a number of image defect samples; By , ; ; where W and H are the width and height of the image, and w and h are the width and height of the target box, and are the center point coordinates of the target box. For a given picture, W and H are fixed values; for a given target box, w, h, x c , y c are inherent attributes and also fixed values; After the scaling factor r is determined, for the coordinate values x and y of a pixel point in the given image, the enhanced heat value α(x, y) of the pixel point is calculated according to the formula; then, an enhanced heat map corresponding to the target box is drawn based on the enhanced heat values of each pixel point within the target box; and the degree of optical transformation of the image within the target box is controlled according to the enhanced heat map; the higher the enhanced heat value of a pixel point, the higher the numerical value of its optical transformation, and the Gaussian-enhanced heat map can balance the pixel point values bbox_value(x, y) at the boundary of the target box; where bbox_value(x, y) = transform_value(x, y) * α(x, y) + ori_value(x, y) * (1 - α(x, y)); for a certain pixel point with coordinate values x and y, its original pixel point value is denoted as ori_value(x, y), and the transformed pixel point value is denoted as transform_value(x, y). The optical transformation of the target box includes: color transformation, brightness adjustment, contrast adjustment, histogram equalization, and sharpening.
9. A computer device, comprising a memory and a processor, the memory storing a computer program, characterized in that When the processor executes the computer program, it implements the steps of the method described in any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the method described in any one of claims 1 to 7.
Citation Information
Patent Citations
Data processing method and device, electronic equipment and storage medium
CN113793292A
Defect detection and sample generation method and device, equipment and storage medium
CN114266733A