An abnormal image generation method, device, equipment and medium

By acquiring the main body region in visual inspection and synthesizing pseudo-defect images, the problem of the limited number of defect samples in visual inspection is solved, and high-quality, diverse pseudo-defect training samples are generated, which improves the generalization ability and training efficiency of the model.

CN123052106APending Publication Date: 2026-11-06YANTAI TRIAL RETAIL ENG CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611236297.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-14
Publication Date
2026-11-06

AI Technical Summary

Technical Problem

Existing technologies in visual inspection suffer from limited defect samples and uneven category distribution, leading to insufficient overfitting and generalization capabilities of deep learning models. This makes it difficult to generate diverse pseudo-defect training samples that are structurally sound, physically consistent, and self-labeled, thus affecting the model training effect.

Method used

By acquiring the main body region of the original image, the defect generation strategy and landing point are determined. Pseudo-defect images are synthesized in the main body region using a multi-source defect resource library, and defect labels are generated simultaneously. This enables the batch generation of diverse pseudo-defect training samples with reasonable structure, physical consistency and built-in labels.

Benefits of technology

It effectively reduces the reliance on real defect data and manual annotation, provides high-quality anomaly data for visual model training, and improves the model's generalization ability and training efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123052106A_ABST
    Figure CN123052106A_ABST
Patent Text Reader

Abstract

This application discloses a method, apparatus, device, and medium for generating abnormal images. The method includes: acquiring an original image and extracting a main region from the original image; determining at least one defect generation strategy and determining the landing point position of at least one defect within the main region; based on a pre-constructed multi-source defect resource library, and according to the defect generation strategy, performing defect synthesis processing at the landing point position within the space defined by the main region to obtain a pseudo-defect image, and simultaneously generating defect labels corresponding to the pseudo-defect image. This technical solution, by constraining defect generation within the main region and combining multi-strategy unified scheduling for synthesis, achieves batch generation of diverse pseudo-defect training samples with reasonable structure, physical consistency, and built-in labels, providing high-quality abnormal data for visual model training and effectively reducing the dependence on real defect data and manual annotation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of image processing technology, and in particular to a method, apparatus, device and medium for generating abnormal images. Background Technology

[0002] Visual inspection is a core component of various automated inspection and recognition systems. Its accuracy and robustness heavily rely on training models with a large number of high-quality, diverse defect samples. However, in real-world scenarios, normal samples constitute the vast majority, while truly abnormal samples are typically limited in number, unevenly distributed in categories, and their morphology is strictly constrained by the target's structure, physical properties, and imaging conditions, exhibiting complex physical characteristics such as location-specific, texture continuity, and natural edge transitions. This makes deep learning models prone to overfitting and lacking in generalization ability, becoming a key bottleneck restricting the effectiveness of deployment of inspection systems.

[0003] To alleviate the problem of data scarcity, related technologies often employ data augmentation or synthesis methods. Firstly, traditional rule-based augmentation, such as random noise superposition, local region copying and pasting, or blending using publicly available natural image textures, while simple and easy to implement, often results in defects appearing in unreasonable areas of the workpiece. Furthermore, it's difficult to maintain physical consistency with the main body of the workpiece in terms of geometric structure, grayscale statistics, and edge transitions, leading to the model learning false features. Secondly, directly using large generative models to freely generate defect images, while improving visual realism, suffers from significant deficiencies in structural rationality, interpretability, and pixel-level annotation usability due to the lack of physical constraints on the precise location, shape, and labels of industrial targets. This limits the effective application of synthetic data in training high-quality visual models. Summary of the Invention

[0004] This application provides a method, apparatus, device, and medium for generating abnormal images. The method generates abnormal images by constraining defect generation within the main body region and combining it with unified scheduling of multiple strategies for synthesis. This enables the batch generation of diverse pseudo-defect training samples with reasonable structure, physical consistency, and self-labeled features. This provides high-quality abnormal data for visual model training and effectively reduces the dependence on real defect data and manual annotation.

[0005] According to one aspect of this application, a method for generating an abnormal image is provided, the method comprising: Acquire the original image and extract the main subject region from the original image; Determine at least one defect generation strategy, and determine the landing location of at least one defect within the main body area; Based on a pre-built multi-source defect resource library, and according to the defect generation strategy, defect synthesis processing is performed at the landing point location within the space defined by the main area to obtain a pseudo-defect image, and a defect label corresponding to the pseudo-defect image is generated simultaneously.

[0006] According to another aspect of this application, an apparatus for generating abnormal images is provided, characterized in that the apparatus comprises: The main body region extraction module is used to acquire the original image and extract the main body region from the original image; The strategy and landing point determination module is used to determine at least one defect generation strategy and to determine the landing point location of at least one defect within the main body area. The defect synthesis processing module is used to perform defect synthesis processing at the landing point location and within the space defined by the main body region based on the pre-built multi-source defect resource library and the defect generation strategy, in accordance with the defect generation strategy, to obtain a pseudo-defect image and simultaneously generate a defect label corresponding to the pseudo-defect image.

[0007] According to another aspect of this application, an electronic device is provided, the device comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores a computer program executable by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the abnormal image generation method described in any embodiment of this application.

[0008] According to another aspect of this application, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the abnormal image generation method described in any embodiment of this application.

[0009] According to another aspect of this application, a computer program product is provided, the computer program product comprising a computer program that, when executed by a processor, implements the method for generating abnormal images according to any embodiment of this application.

[0010] The technical solution provided in this application acquires an original image and extracts the main body region from it; determines at least one defect generation strategy and identifies the landing point of at least one defect within the main body region; based on a pre-built multi-source defect resource library, and according to the defect generation strategy, performs defect synthesis processing at the landing point within the space defined by the main body region to obtain a pseudo-defect image, and simultaneously generates defect labels corresponding to the pseudo-defect image. This technical solution, by constraining defect generation within the main body region and combining multi-strategy unified scheduling for synthesis, achieves batch generation of diverse pseudo-defect training samples with reasonable structure, physical consistency, and built-in labels, providing high-quality anomaly data for visual model training and effectively reducing reliance on real defect data and manual annotation.

[0011] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this application, nor is it intended to limit the scope of this application. Other features of this application will become readily apparent from the following description. Attached Figure Description

[0012] To more clearly illustrate the technical solutions in the embodiments of this application, 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 this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0013] Figure 1 This is a flowchart of a method for generating an abnormal image provided in Embodiment 1 of this application.

[0014] Figure 2 This is a flowchart of a method for generating an abnormal image provided in Embodiment 2 of this application.

[0015] Figure 3 This is a schematic diagram of the structure of an abnormal image generation device provided in Embodiment 3 of the present invention.

[0016] Figure 4 This is a schematic diagram of the structure of a device for implementing an abnormal image generation method according to an embodiment of this application. Detailed Implementation

[0017] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.

[0018] It should be noted that the terms "original," "pseudo-defect," "candidate," "historical," "true," "mapping," "effective," "first," "second," and "initial," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0019] It should also be noted that the acquisition, storage, use, and processing of data in the technical solution of this application all comply with the relevant provisions of national laws and regulations.

[0020] Example 1 Figure 1 This is a flowchart of an abnormal image generation method provided in Embodiment 1 of this application. This embodiment can be applied to any scenario where specific feature blocks need to be generated on a specified area of ​​an image, such as generating defect images in defect detection in the industrial field, generating images of out-of-stock areas on shelves in the retail field, generating images of road potholes in the transportation field, etc. This method can be executed by an abnormal image generation device, which can be implemented in hardware and / or software, and can be configured in a device with data processing capabilities.

[0021] like Figure 1 As shown, the method includes the following steps.

[0022] S110. Obtain the original image and extract the main body region from the original image.

[0023] Raw images refer to images acquired through image acquisition devices (such as industrial cameras, microscopes, endoscopes, etc.) that do not contain abnormal targets. Raw images are usually normal samples, good products, or background images.

[0024] The subject region refers to the area of ​​the original image occupied by the target object to be detected. Examples include the appearance area of ​​an industrial part, the region of interest of biological tissue, and the effective area of ​​a printed circuit board. The subject region can be extracted using image segmentation techniques and represented as a binary mask, where pixels with a value of 1 belong to the subject region.

[0025] Specifically, the original image can be converted to grayscale, thresholded, segmented, edge detected, and morphologically manipulated to select the largest connected component as the main body region. Furthermore, a lightweight semantic segmentation model can be used to infer the main body region based on geometric features, template features, hole location features, and bounding rectangle features, among others, to output a segmentation mask for the main body region.

[0026] It should be noted that if there are multiple possible subjects in the original image, they can be filtered based on the largest area or the highest degree of matching with the preset template.

[0027] In this application, the main body region is extracted based on the original image to define the range of defect generation. The mask image of the main body region can be represented as: ; In the formula, Indicates the main area.

[0028] Furthermore, to improve the spatial consistency of the generated image, rotation correction can be applied to the main subject region. First, the minimum bounding rectangle of the mask image of the main subject region is calculated, and its rotation angle is obtained. Secondly, the mask image of the main area is rotated in reverse. An affine transformation of degrees is applied to bring the main subject region into a standard pose. Subsequent steps are performed on the corrected image and mask.

[0029] The affine transformation of the mask image of the main region can be performed using the following formula: ; In the formula, Let be the rotation transformation matrix.

[0030] S120, determine at least one defect generation strategy, and determine the landing location of at least one defect within the main body area.

[0031] A defect generation strategy refers to the algorithmic rules or procedures used to synthesize simulated defects in an image. In this application, the defect generation strategy may include a real defect migration strategy, a texture weighted fusion strategy, a missing block generation strategy, a common fragment migration strategy, etc., each strategy corresponding to a type of abnormal physical feature and generation model.

[0032] Specifically, a set of optional strategies that includes multiple defect generation tactics can be predefined: .

[0033] Assign a non-negative strategy weight to each defect generation strategy. Strategy weights It can be preset or dynamically adjusted based on at least one of the following: product type, historical defect statistics, process stage, training requirements, or human experience, and then fixed in the configuration parameters.

[0034] When selecting a defect generation strategy, the weights of all strategies are first normalized to obtain the probability distribution of each defect generation strategy being selected: ; In the formula, the denominator is the sum of the policy weights of all defect generation strategies, and the probability distribution satisfies .

[0035] Based on the obtained probability distribution and the predetermined number of defect generation strategies, random sampling is performed from the set. Select the corresponding number of defect generation strategies as the defect generation strategy for the current defect.

[0036] When multiple defects need to be superimposed on a single original image, let the final number of defects be... Then we have: ; Alternatively, use bounded integer random variables: ; To achieve the controllable generation of single-defect or multi-defect samples.

[0037] The landing point refers to a selected pixel coordinate point within the main body area, which serves as the spatial positioning reference for subsequent defect synthesis processing. The defect area will be placed with this point as the center or reference.

[0038] Specifically, the pixel points within the main area can be randomly sampled to obtain the landing point position.

[0039] It should be noted that in this application, the number of defect generation strategies and the number of defects are predetermined. For example, the user can input the number of defect generation strategies and the number of defects used in this abnormal image generation through an interactive interface.

[0040] S130. Based on the pre-built multi-source defect resource library, according to the defect generation strategy, defect synthesis processing is performed at the landing point location within the space defined by the main area to obtain a pseudo-defect image, and a defect label corresponding to the pseudo-defect image is generated simultaneously.

[0041] A multi-source defect resource library refers to a structured database built using a unified data structure, which stores various defect resources that can be used for defect synthesis. Defect resources are not limited to the images themselves, but also include corresponding masks, labels, and metadata. Resource types may include historical real defect samples, random noise or program-generated shape fragments, texture image samples, public defect datasets, and defect fragments with segmentation annotations, etc.

[0042] Let the set of multi-source defect resources be: Each defective resource It can be represented as: In the formula, Indicates appearance information, Indicates shape mask, Indicates label information, Indicates the resource type identifier.

[0043] By managing these resources using a unified data structure, multi-strategy reuse and unified scheduling can be achieved.

[0044] Specifically, for shape segments based on random noise, this application employs the Perlin noise algorithm to generate random defect shapes with natural continuity characteristics. This can be achieved through the following steps A1-A3.

[0045] Step A1: Noise field generation.

[0046] Constructing a two-dimensional Perlin noise field By adjusting the scale parameters To control the frequency characteristics of noise: .

[0047] Step A2: Binarize the initial mask.

[0048] Set threshold This converts a continuous noise field into a binary initial mask. : .

[0049] Step A3: Morphological optimization and screening.

[0050] For binary initial mask Morphological operations such as scaling, erosion, and dilation are performed to smooth the edges, and connected components are extracted. Only the area of ​​the connected components is retained. Meets the preset sampling interval Abnormal shape fragments within: .

[0051] The selected shape fragments can then be used as high-fidelity candidate anomaly masks for texture defects, missing blocks, or mixed defects. This method utilizes the spatial continuity of Perlin noise to simulate the natural forms of real industrial anomalies more closely than traditional random noise.

[0052] In this application, for the generation of pseudo-defect images and the generation of labels, defect materials that match the defect generation strategy determined in step S120 can be retrieved from a pre-constructed multi-source defect resource library.

[0053] Secondly, using the landing point position determined in step S120 as a spatial reference, the retrieved defect material is mapped onto the coordinate system of the original image to form a preliminary defect projection area. To ensure that the generated defect is always within a reasonable space allowed by the workpiece body, the preliminary defect projection area can be spatially constrained using the previously extracted body area mask: only the part where the projection area intersects with the body area mask is retained, and the part exceeding the body area is automatically removed, thereby ensuring that all pixels of the defect fall within the space defined by the body area.

[0054] Next, according to the synthesis rules of the selected strategy, the spatially constrained defect area is fused with the original image. The fusion process includes, but is not limited to: mixing the pixel values ​​of the defective material with the corresponding pixel values ​​of the original image according to certain weights; directly replacing the corresponding pixel values ​​of the original image with the pixel values ​​of the defective material; or locally modifying the pixel values ​​of the original image to simulate missing or abnormal effects. During the fusion process, the boundaries of the defective area can be smoothed or transitioned to improve visual realism.

[0055] Finally, while completing image synthesis, based on the spatially constrained defect regions, defect labels strictly aligned with these regions are automatically generated to ensure consistency between the image and the labels. Let the final anomaly region be... The main area is ,but: Anomaly segmentation labels can be represented as: ; A normal subject tag can be represented as: ; The multi-category labels can be further expanded to include categories such as background, normal subject, crack, contamination, missing piece, and scratch. Therefore, this application is applicable to both binary anomaly detection training and multi-category anomaly segmentation training.

[0056] The above process can be repeated multiple times for a single image. Each time, different defect generation strategies and landing points can be selected to superimpose multiple non-overlapping or moderately overlapping defect regions on an image, ultimately resulting in a pseudo-defect image containing multiple defect morphologies and its corresponding comprehensive defect label map.

[0057] This invention provides a method for generating abnormal images. The method involves acquiring an original image and extracting the main body region from it; determining at least one defect generation strategy and identifying the landing point location of at least one defect within the main body region; based on a pre-constructed multi-source defect resource library, performing defect synthesis processing at the landing point location within the space defined by the main body region according to the defect generation strategy to obtain a pseudo-defect image, and simultaneously generating defect labels corresponding to the pseudo-defect image. This technical solution, by constraining defect generation within the main body region and combining multi-strategy unified scheduling for synthesis, achieves batch generation of diverse pseudo-defect training samples with reasonable structure, physical consistency, and built-in labels. This provides high-quality abnormal data for visual model training and effectively reduces the dependence on real defect data and manual annotation.

[0058] Example 2 Figure 2 This is a flowchart of an abnormal image generation method provided in Embodiment 2 of this application. This embodiment is based on the above embodiment and is optimized, specifically by optimizing the process of determining the location of the defect.

[0059] like Figure 2 As shown, the method includes the following steps.

[0060] S210. Obtain the original image and extract the main body region from the original image.

[0061] S220. Determine at least one defect generation strategy.

[0062] S230. Determine a set of candidate pixels based on the main area.

[0063] Specifically, based on the main region mask extracted in step S110 To satisfy all The pixels that make up the candidate pixel set. That is: .

[0064] This set is the valid candidate space for defect landing points, and all subsequent landing point selection operations are performed within this set.

[0065] S240. For each defect, calculate the position weight of each candidate pixel in the candidate pixel set according to a preset position weight function; wherein, the position weight function is constructed based on at least one of the spatial features within the main area and the historical defect distribution features.

[0066] To improve the spatial rationality of defect placement and make the generated defects more consistent with the patterns of defect occurrence in real industrial scenarios, this application uses a set of candidate pixels. Each candidate pixel is assigned a positional weight to characterize its suitability as a defect landing point.

[0067] In some embodiments, the location weighting function may optionally be: ; In the formula, This represents a distance constraint term relative to the center of the main region or a predefined key structure. This indicates the regional risk or priority weighting items preset based on process knowledge. This represents the popularity distribution item obtained based on historical defect data statistics. , and These are the weighting coefficients for each item.

[0068] in, Used to tilt or avoid a specific geometric position when landing. Used to reflect the prior probability of defects occurring in different regions. Statistical laws used to approximate the spatial distribution of generated defects to those of real defects. , and Used to adjust the degree of influence of each factor on the final position weight.

[0069] Of course, the position weight function is not limited to the linear weighting form mentioned above. It can also use nonlinear combinations or other forms of functions, as long as it can distinguish the priority of candidate pixels based on at least one of spatial features and historical distribution features.

[0070] S250. Based on the position weight of each candidate pixel, select a candidate pixel from the set of candidate pixels as the location of the defect.

[0071] It's understandable that candidate pixels with higher positional weights have a greater probability of being selected. Specifically, the candidate pixel with the highest positional weight can be determined as the location of the defect.

[0072] In some embodiments, optionally, the step of selecting a candidate pixel from the set of candidate pixels as the location of the defect based on the position weight of each candidate pixel may include, but is not limited to, the following steps S251-S252.

[0073] S251. Normalize the position weights of each candidate pixel to obtain the selection probability of each candidate pixel.

[0074] First, the candidate pixel set can be... The position weights of all candidate pixels within the range are summed to obtain the total weight. That is, .

[0075] Next, the position weight of each candidate pixel is divided by the sum of those weights to obtain the probability of that pixel being selected. That is, .

[0076] After normalization, the sum of the selection probabilities of all candidate points is always equal to 1, forming a complete discrete probability distribution.

[0077] S252. Randomly sample each candidate pixel according to the selection probability to determine the location of the defect.

[0078] Specifically, the location of the defect can be determined through the following steps.

[0079] First, arrange the candidate point set P in a set order (the order has no effect on the actual result, and points can be selected row by row and column by column), and accumulate the probability of each point in turn to construct a probability interval.

[0080] Next, generate a uniform random number rand within the interval [0,1].

[0081] Finally, iterate through the probability intervals to determine which candidate pixel's interval the random number rand falls into. The coordinates of this candidate pixel are the location of the defect, i.e., the center point of the defect.

[0082] For example, if there are 5 sorted points p1, p2, p3, p4 and p5 in the candidate region, and their corresponding normalized probabilities are 0.1, 0.2, 0.3, 0.3 and 0.1 respectively, then the probability intervals are constructed as [0.0, 0.1], [0.1, 0.3], [0.3, 0.6], [0.6, 0.9] and [0.9, 1.0]. Then a random number of [0, 1] is generated, for example, 0.5, which is located in the third interval, that is, point p3 is selected as the landing point of the defect.

[0083] S260. Based on a pre-built multi-source defect resource library, and according to the defect generation strategy, defect synthesis processing is performed at the landing point location within the space defined by the main area to obtain a pseudo-defect image, and a defect label corresponding to the pseudo-defect image is generated simultaneously.

[0084] This embodiment provides a method for generating abnormal images. This method realizes random landing points guided by spatial rationality within the main body area, which not only ensures that the landing points are always located inside the main body of the workpiece, but also introduces the guidance of process prior and historical statistical information through the position weight function, so that the spatial distribution of generated defects has both randomness and realism.

[0085] Based on the above embodiments, optionally, the defect generation strategy includes at least a real defect migration strategy; the step of performing defect synthesis processing at the landing point location based on a pre-built multi-source defect resource library and the defect generation strategy to obtain a pseudo-defect image includes, but is not limited to, the following steps B1-B5.

[0086] B1. Obtain real defect images and corresponding real defect masks from a pre-built multi-source defect resource library.

[0087] The real defect images are historically collected and labeled real defect sample images, and the real defect mask is a binary mask strictly aligned with the image, used to accurately define the extent of the defect area (pixels with a mask value of 1 belong to the defect area, and pixels with a value of 0 belong to the normal area). The multi-source defect resource library can store multiple real defect samples of different categories and forms for random or on-demand selection in subsequent steps.

[0088] B2. Based on the landing point position, the defect region defined by the defect mask in the real defect image is mapped to the coordinate system of the original image to obtain the mapped defect appearance and the corresponding mapped defect mask.

[0089] Specifically, let the real defect image be... The defect mask is Then, the defect region defined by the real defect mask in the real defect image can be represented as: .

[0090] Based on the landing position Using the reference point, the defined defect area is mapped to the coordinate system of the original image through a translation transformation, resulting in the mapped defect appearance. The corresponding mapping defect mask is .

[0091] B3. Determine the effective defect mask based on the mapped defect mask and the main area mask.

[0092] To ensure that all generated defect pixels are located within the legal space allowed by the workpiece body, this application only retains the portion of the mapped defect mask that falls within the body area.

[0093] Specifically, the effective defect mask can be obtained by performing a logical AND operation on the mapped defect mask and the main region mask. Alternatively, the effective defect mask can be determined using the following formula: .

[0094] It should be noted that if the total pixel area of ​​the obtained effective defect mask is lower than the preset threshold, the current defect synthesis can be interrupted and the landing point can be regenerated or the defect sample can be replaced.

[0095] B4. Perform boundary smoothing on the effective defect mask to obtain the first fusion weight map.

[0096] Due to effective defect masking Using a binary mask (with values ​​of only 0 or 1), direct application to fusion can result in abrupt grayscale transitions at defect boundaries. To address this issue, this application... Boundary smoothing is performed to generate a continuous boundary transition map with values ​​in the range [0,1], which is the first fusion weight map.

[0097] Specifically, the first fusion weight map can be determined using the following formula.

[0098] ; In the formula, This represents the boundary smoothing kernel. This represents the convolution operation.

[0099] B5. Based on the first fusion weight map, the appearance of the mapped defect is weighted and fused with the original image to generate a pseudo-defect image.

[0100] Specifically, the false defect image can be determined using the following formula.

[0101] ; In the formula, This represents the original image.

[0102] The advantages of the above technical solution are that it limits the effective area of ​​the defect to be migrated by masking, avoiding background pollution; it ensures that the defect does not cross the boundary by using the main mask for cropping; it eliminates splicing marks by smoothing the boundary; and it maintains visual consistency by weighted fusion.

[0103] Based on the above embodiments, optionally, the defect generation strategy includes at least a texture weighted fusion strategy; the step of performing defect synthesis processing at the landing point location based on a pre-built multi-source defect resource library and according to the defect generation strategy to obtain a pseudo-defect image includes, but is not limited to, the following steps C1-C4: C1. Obtain texture defect sample images and corresponding texture defect shape masks from the multi-source defect resource library.

[0104] The texture defect sample image is an image patch containing target texture features (such as scratches, stain patches, indentations, etc.). The texture defect shape mask is a binary mask strictly aligned with the image patch, used to define the spatial distribution range of the texture defect (pixels with a mask value of 1 belong to the defect area, and pixels with a value of 0 belong to the normal area). The texture defect sample image and its shape mask can be selected on demand from the resource library, generated in real time by the program, or generated by a defect segmentation algorithm or manually annotated binary images to define the spatial range of the defect.

[0105] C2. Generate a weight enhancement mask based on the texture defect shape mask, wherein the weight enhancement mask is used to enhance the fusion weight of the defect core region far from the boundary in the texture defect shape mask.

[0106] To simulate the physical characteristics of real defects, which are "prominent at the center and gradually disappear at the edges", this application enhances the spatial weight of the texture defect shape mask by performing distance transformation and nonlinear mapping on the texture defect shape mask.

[0107] First, a distance transformation is performed on the texture defect shape mask to calculate the distance of each foreground pixel (i.e., (pixels) to the nearest background boundary (i.e.) The Euclidean distance of the pixels.

[0108] Secondly, the distance values ​​are normalized and nonlinearly mapped to obtain the weight enhancement mask. That is, the weight enhancement mask can be determined using the following formula.

[0109] ; In the formula, Represents a shape mask for texture defects. Represents pixels The Euclidean distance to the boundary of the defect background. This represents the attenuation coefficient, used to adjust the focusing degree of the defect core. , Indicates an indicator function.

[0110] in, The larger the value, the more concentrated the weight is at the defect center. The smaller the value, the more evenly the weight distribution.

[0111] C3. Determine the second fusion weight map based on the texture defect shape mask, the weight enhancement mask, and the pre-generated Gaussian random weight field.

[0112] A Gaussian random weight field is used to introduce random perturbations in texture intensity to simulate imaging noise and material inhomogeneities. Specifically, the Gaussian random weight field can be determined through the following steps.

[0113] First, a Gaussian random fundamental weight field of the same size as the texture defect shape mask can be generated: ; in, Control the average texture intensity. Control the intensity of texture fluctuations.

[0114] Secondly, the generated random field is normalized to the [0,1] interval: .

[0115] The texture defect shape mask, the weight enhancement mask, and the Gaussian random weight field are combined to obtain a spatially adaptive weight map, i.e., the second fused weight map. The second fused weight map can be determined by the following formula: ; In the formula, This represents the morphological enhancement factor. This term makes the defect center region (i.e., The fusion weights of larger areas are significantly higher than those of edges, while preserving This results in microscopic random fluctuations.

[0116] C4. Based on the second fusion weight map, the texture defect sample image and the original image are weighted and fused to generate the pseudo defect image.

[0117] Using the constructed second fusion weight map, the texture defect sample image and the original image are fused pixel-by-pixel with weights. Specifically, the pseudo-defect image can be determined using the following formula: ; In the formula, Represents a texture defect sample image. Represents the original image. This represents the overall integration ratio coefficient.

[0118] It should be noted that the attenuation coefficient Overall integration ratio coefficient Morphological enhancement coefficient The mean of a Gaussian random weighted field with standard deviation All parameters can be adjusted according to the specific defect type and the main material, providing flexible parameter configuration space for different application scenarios.

[0119] The advantage of the above technical solution is that it can achieve differentiated control of the intensity fluctuations and boundary transitions within the texture, which is more in line with the non-uniform characteristics of industrial defects.

[0120] Based on the above embodiments, optionally, the defect generation strategy includes at least a missing block generation strategy; Based on the pre-built multi-source defect resource library, and according to the defect generation strategy, defect synthesis processing is performed at the landing point location to obtain a pseudo-defect image, including but not limited to the following steps D1-D4: D1. Obtain the missing block shape mask from the multi-source defect resource library, and map the missing block shape mask onto the main body area based on the landing point position to obtain the initial missing block area.

[0121] The missing shape mask is a binary mask used to define the shape and extent of the missing region (pixels with a mask value of 1 belong to the missing region, and pixels with a value of 0 belong to the normal region). This missing shape mask can be derived from at least one of the following methods: selecting a preset missing shape template from a resource library, generating it in real time using a random generation algorithm such as Perlin noise, or extracting it from historical real missing sample.

[0122] Based on the landing position Using the reference point, the shape mask of the missing block is translated and transformed to map it to the coordinate system of the original image, thus obtaining the initial missing block region.

[0123] D2. Determine the overlapping area between the initial missing area and the main area, and filter out connected components in the overlapping area whose area is less than a preset area threshold to obtain the effective missing area.

[0124] First, let the main area be... The initial mask for the missing region is Calculate the intersection of the two to obtain the overlapping region: .

[0125] Secondly, extract the overlapping regions. All connected components And calculate the area of ​​each connected component. Let the preset area threshold be... Then the valid missing block regions that meet the conditions are: .

[0126] To make the missing edges more natural, morphological dilation can be performed on the filtered missing regions. That is: ; In the formula, This represents the expansion operation. Represents a structural element. It can be a circular or square core with a radius of 1 to 2 pixels to make the edges of the missing block have a certain roughness, which is closer to the visual effect of real chipped edges or gaps.

[0127] D3. Sample background pixels from the background region outside the main body region in the original image.

[0128] Since the essence of missing block anomalies is the local loss of the main material, the missing area should ideally appear as the background behind the main object (such as a conveyor belt, fixture, or table). Therefore, this application samples background pixels from the background region of the main object mask in the original image to fill the subsequent effective missing block regions.

[0129] Sampling methods may include, but are not limited to, the following: Single-pixel sampling: Randomly select a pixel from the background area and assign its value to the entire missing area; Block sampling: Randomly select an image block from the background region that is roughly the same size as the missing region and copy it entirely to the missing region; Statistical sampling: Statistically analyze the pixel mean or texture distribution of the background area to generate a fill pattern that conforms to the statistical characteristics of the background.

[0130] Let the sampled set of background pixels be denoted as .

[0131] D4. Replace the pixel values ​​in the effective defect area with the background pixels to generate the pseudo-defect image.

[0132] Effective missing area The pixel values ​​of all pixels within the image are replaced with the background pixels sampled in step D3 to generate a pseudo-defect image. That is: .

[0133] It should be noted that when using block sampling, Follow Position change; when using single-pixel sampling, It is a constant.

[0134] The advantages of the above technical solution are that it ensures that the generated missing area is inside the main body of the workpiece and has a detectable continuous scale, and that the pixel statistics at the missing area are consistent with the on-site imaging conditions. Thus, without the need for real missing block samples, it can generate structurally reasonable and visually realistic missing block pseudo-defect training data with high controllability and reproducibility.

[0135] Example 3 Figure 3 This is a schematic diagram of an abnormal image generation device provided in Embodiment 3 of the present invention. Figure 3 As shown, the device includes: The main body region extraction module 310 is used to acquire the original image and extract the main body region from the original image; The strategy and landing point determination module 320 is used to determine at least one defect generation strategy and determine the landing point position of at least one defect within the main body area. The defect synthesis processing module 330 is used to perform defect synthesis processing at the landing point location and within the space defined by the main body region based on the pre-built multi-source defect resource library and the defect generation strategy, in accordance with the defect generation strategy, to obtain a pseudo-defect image and simultaneously generate a defect label corresponding to the pseudo-defect image.

[0136] The present invention provides an anomalous image generation apparatus. This apparatus acquires an original image and extracts the main body region from the original image; determines at least one defect generation strategy and identifies the landing point location of at least one defect within the main body region; based on a pre-constructed multi-source defect resource library, and according to the defect generation strategy, performs defect synthesis processing at the landing point location within the space defined by the main body region to obtain a pseudo-defect image, and simultaneously generates defect labels corresponding to the pseudo-defect image. This technical solution, by constraining defect generation within the main body region and combining multi-strategy unified scheduling for synthesis, achieves batch generation of diverse pseudo-defect training samples with reasonable structure, physical consistency, and built-in labels. This provides high-quality anomalous data for visual model training and effectively reduces the dependence on real defect data and manual annotation.

[0137] Furthermore, the strategy and landing point determination module 320 includes: The candidate pixel determination unit is used to determine a set of candidate pixels based on the main body region. The position weight calculation unit is used to calculate the position weight of each candidate pixel in the candidate pixel set for each defect according to a preset position weight function; wherein, the position weight function is constructed based on at least one of the spatial features within the main area and the historical defect distribution features; The landing point determination unit is used to select a candidate pixel from the set of candidate pixels as the landing point of the defect according to the position weight of each candidate pixel.

[0138] Furthermore, the position weight function is: ; In the formula, This represents a distance constraint term relative to the center of the main region or a predefined key structure. This indicates the regional risk or priority weighting items preset based on process knowledge. This represents the popularity distribution item obtained based on historical defect data statistics. , and These are the weighting coefficients for each item.

[0139] Furthermore, the landing point location determination unit includes: The selection probability determination subunit is used to normalize the position weights of each candidate pixel to obtain the selection probability of each candidate pixel. The landing point determination subunit is used to randomly sample each candidate pixel point according to the selection probability in order to determine the landing point position of the defect.

[0140] Furthermore, the defect generation strategy includes at least a real defect migration strategy; The defect synthesis and processing module 330 includes: The real defect data acquisition unit is used to acquire real defect images and corresponding real defect masks from a pre-built multi-source defect resource library; The mapping defect determination unit is used to map the defect region defined by the defect mask in the real defect image to the coordinate system of the original image based on the landing point position, so as to obtain the appearance of the mapped defect and the corresponding mapped defect mask. An effective defect mask determination unit is used to determine an effective defect mask based on the mapped defect mask and the main region mask; The first fusion weight map determination unit is used to perform boundary smoothing processing on the effective defect mask to obtain the first fusion weight map. The pseudo-defect image generation unit is used to generate a pseudo-defect image by weighted fusion of the mapped defect appearance with the original image based on the first fusion weight map.

[0141] Furthermore, the defect generation strategy includes at least a texture weighted fusion strategy; The defect synthesis and processing module 330 includes: The texture defect data acquisition unit is used to acquire texture defect sample images and corresponding texture defect shape masks from the multi-source defect resource library; A weight enhancement mask generation unit is used to generate a weight enhancement mask based on the texture defect shape mask, wherein the weight enhancement mask is used to enhance the fusion weight of the defect core region far from the boundary in the texture defect shape mask; The second fusion weight map determination unit is used to determine the second fusion weight map based on the texture defect shape mask, the weight enhancement mask, and the pre-generated Gaussian random weight field. The pseudo-defect image generation unit is used to perform weighted fusion of the texture defect sample image and the original image based on the second fusion weight map to generate the pseudo-defect image.

[0142] Furthermore, the defect generation strategy includes at least a missing block generation strategy; The defect synthesis and processing module 330 includes: The initial missing block region determination unit is used to obtain a missing block shape mask from the multi-source defect resource library, and map the missing block shape mask onto the main body region based on the landing point position to obtain the initial missing block region; The effective missing block region determination unit is used to determine the overlapping region between the initial missing block region and the main region, and to filter out connected components in the overlapping region whose area is less than a preset area threshold, thereby obtaining the effective missing block region. A background pixel sampling unit is used to sample background pixels from a background region outside the main body region in the original image; The pseudo-defect image generation unit is used to replace the pixel values ​​in the effective defect area with the background pixels to generate the pseudo-defect image.

[0143] The abnormal image generation apparatus provided in this embodiment of the invention can execute the abnormal image generation method provided in any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0144] Example 4 Figure 4 A schematic diagram of the structure of a device 10 that can be used to implement embodiments of this application is shown. The device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (such as helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the application described and / or claimed herein.

[0145] like Figure 4 As shown, device 10 includes at least one processor 11 and a memory, such as read-only memory (ROM) 12, random access memory (RAM) 13, etc., communicatively connected to at least one processor 11. The memory stores computer programs executable by at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the ROM 12 or loaded into the RAM 13 from storage unit 18. The RAM 13 may also store various programs and data required for the operation of device 10. The processor 11, ROM 12, and RAM 13 are interconnected via bus 14. Input / output (I / O) interface 15 is also connected to bus 14.

[0146] Multiple components in device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of monitors, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0147] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as methods for generating anomalous images.

[0148] In some embodiments, the method for generating an abnormal image may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the method for generating an abnormal image described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to perform the method for generating an abnormal image by any other suitable means (e.g., by means of firmware).

[0149] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0150] Computer programs used to implement the methods of this application may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0151] In the context of this application, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium can be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0152] To provide interaction with a user, the systems and techniques described herein can be implemented on a device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0153] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.

[0154] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.

[0155] In particular, according to embodiments of the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of the present invention include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication unit 19, or installed from storage unit 18, or installed from ROM 12. When the computer program is executed by processor 11, it performs the functions defined in the methods of the embodiments of the present invention.

[0156] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this application can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this application can be achieved, and this is not limited herein.

[0157] The specific embodiments described above do not constitute a limitation on the scope of protection of this application. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this application should be included within the scope of protection of this application.

Claims

1. A method for generating an abnormal image, characterized in that, include: Acquire the original image and extract the main subject region from the original image; Determine at least one defect generation strategy, and determine the landing location of at least one defect within the main body area; Based on a pre-built multi-source defect resource library, and according to the defect generation strategy, defect synthesis processing is performed at the landing point location within the space defined by the main area to obtain a pseudo-defect image, and a defect label corresponding to the pseudo-defect image is generated simultaneously.

2. The method for generating abnormal images according to claim 1, characterized in that, Determining the location of at least one defect within the main body area includes: Based on the main region, a set of candidate pixels is determined; For each defect, the position weight of each candidate pixel in the candidate pixel set is calculated according to a preset position weight function; wherein, the position weight function is constructed based on at least one of the spatial features within the main area and the historical defect distribution features; Based on the position weight of each candidate pixel, a candidate pixel is selected from the set of candidate pixels as the location of the defect.

3. The method for generating abnormal images according to claim 2, characterized in that, The position weighting function is: ; In the formula, This represents a distance constraint term relative to the center of the main region or a predefined key structure. This indicates the regional risk or priority weighting items preset based on process knowledge. This represents the popularity distribution item obtained based on historical defect data statistics. , and These are the weighting coefficients for each item.

4. The method for generating abnormal images according to claim 2, characterized in that, The step of selecting candidate pixels from the set of candidate pixels as the location of the defect based on the position weight of each candidate pixel includes: The position weights of each candidate pixel are normalized to obtain the selection probability of each candidate pixel. The candidate pixels are randomly sampled according to the selection probability to determine the location of the defect.

5. The method for generating abnormal images according to claim 1, characterized in that, The defect generation strategy includes at least a real defect migration strategy; The method, based on a pre-built multi-source defect resource library, performs defect synthesis processing at the landing point location according to the defect generation strategy to obtain a pseudo-defect image, including: Obtain real defect images and corresponding real defect masks from a pre-built multi-source defect resource library; Based on the landing point position, the defect region defined by the defect mask in the real defect image is mapped to the coordinate system of the original image to obtain the mapped defect appearance and the corresponding mapped defect mask. Based on the mapped defect mask and the main region mask, an effective defect mask is determined; The effective defect mask is subjected to boundary smoothing processing to obtain the first fusion weight map; Based on the first fusion weight map, the appearance of the mapped defect is weighted and fused with the original image to generate a pseudo-defect image.

6. The method for generating abnormal images according to claim 1, characterized in that, The defect generation strategy includes at least a texture weighted fusion strategy; The method, based on a pre-built multi-source defect resource library, performs defect synthesis processing at the landing point location according to the defect generation strategy to obtain a pseudo-defect image, including: Obtain texture defect sample images and corresponding texture defect shape masks from the multi-source defect resource library; A weight enhancement mask is generated based on the texture defect shape mask, wherein the weight enhancement mask is used to enhance the fusion weight of the defect core region far from the boundary in the texture defect shape mask; The second fusion weight map is determined based on the texture defect shape mask, the weight enhancement mask, and the pre-generated Gaussian random weight field; Based on the second fusion weight map, the texture defect sample image and the original image are weighted and fused to generate the pseudo defect image.

7. The method for generating abnormal images according to claim 1, characterized in that, The defect generation strategy includes at least a missing block generation strategy; The method, based on a pre-built multi-source defect resource library, performs defect synthesis processing at the landing point location according to the defect generation strategy to obtain a pseudo-defect image, including: Obtain a missing block shape mask from the multi-source defect resource library, and map the missing block shape mask onto the main body region based on the landing point position to obtain an initial missing block region; Determine the overlapping area between the initial missing region and the main region, and filter out connected components in the overlapping region whose area is smaller than a preset area threshold to obtain the effective missing region; Sample background pixels from the background region outside the main body region in the original image; The pixel values ​​within the effective defect area are replaced with the background pixels to generate the pseudo-defect image.

8. An apparatus for generating abnormal images, characterized in that, The device includes: The main body region extraction module is used to acquire the original image and extract the main body region from the original image; The strategy and landing point determination module is used to determine at least one defect generation strategy and to determine the landing point location of at least one defect within the main body area. The defect synthesis processing module is used to perform defect synthesis processing at the landing point location and within the space defined by the main body region based on the pre-built multi-source defect resource library and the defect generation strategy, in accordance with the defect generation strategy, to obtain a pseudo-defect image and simultaneously generate a defect label corresponding to the pseudo-defect image.

9. An electronic device, characterized in that, The device includes: At least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores a computer program executable by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the method for generating an abnormal image according to any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed by a processor, implement the method for generating the abnormal image according to any one of claims 1-7.