Methods, apparatus, devices and storage media for generating defect images
By generating defect images through target mask and defect mask control mechanisms, the problem of generating high-fidelity structural defect images under zero-sample conditions is solved. It realizes the construction of defect samples for multiple types of objects and multi-scale textures, thereby improving the adaptability and detection accuracy of industrial detection models.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-14
- Publication Date
- 2026-03-31
AI Technical Summary
Existing technologies struggle to generate high-fidelity structural defect images under zero-sample conditions, and traditional methods cannot meet the demand for diverse and high-fidelity defect samples, thus limiting the generalization ability and detection accuracy of industrial detection models.
By using a target mask and defect mask control mechanism, a target mask image is generated using a segmentation model, and a defect region is inserted on it. The defect image is then generated by replacing the background image, thus achieving high-fidelity simulation of the defect region.
While maintaining the overall structure and semantic continuity of the image, it generates structurally complete and visually consistent defect images, which are suitable for industrial inspection and visual training sample expansion, thus improving the adaptability and versatility of the model in complex tasks.
Smart Images

Figure CN121120867B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image generation technology, and in particular to a method, apparatus, device and storage medium for generating defective images. Background Technology
[0002] With the rapid development of industrial scenarios such as intelligent manufacturing, power transmission inspection, and precision equipment quality inspection, the impact of structural defects on system safety and stability is becoming increasingly prominent, making them a core focus of anomaly detection models. However, these defects occur very infrequently in real-world environments, and the cost of collecting and labeling them is high, resulting in an extreme scarcity of defect samples available for training. This has become a key bottleneck restricting the generalization ability and detection accuracy of the models.
[0003] Traditional image enhancement methods can only perform simple transformations on existing defective images, lacking the ability to generate entirely new defective data, making it difficult to meet the demand for diverse and high-fidelity defect samples. In recent years, generative adversarial networks and diffusion models have demonstrated good data generation capabilities in image synthesis tasks, but existing methods usually rely on a large number of training samples or lack fine control over the defective structure, making it difficult to achieve high-fidelity structural defect simulation under zero-sample conditions. Summary of the Invention
[0004] This application provides a method, apparatus, device, and storage medium for generating defect images. It achieves adaptive generation of defect regions in a target image through a target mask and defect mask control mechanism. The method acquires the target image and segmentation prompts, generates a target mask image using a segmentation model, inserts defects into the mask image to generate a missing mask image, and finally replaces the missing regions with corresponding regions in the background image to obtain a complete defect image. This solution can achieve high-fidelity simulation of defect regions while maintaining the overall image structure and semantic continuity, and is suitable for applications such as industrial inspection, visual training sample expansion, and data augmentation of anomaly recognition models.
[0005] In a first aspect, this application provides a method for generating defective images, including:
[0006] Obtain the target image to be processed and the segmentation prompt information corresponding to the target object to be processed in the target image; input the target image and the segmentation prompt information into the trained segmentation model to obtain the target mask image corresponding to the target image;
[0007] A defect mask image is obtained by performing defect insertion processing on the target mask image, and a missing mask image is determined based on the target mask image and the defect mask image to indicate the missing parts of the target image;
[0008] A background image is generated based on the target mask image and the target image. The region corresponding to the missing mask image in the target image is replaced with the corresponding region in the background image to obtain the defective image.
[0009] Secondly, this application provides a defect image generation apparatus, comprising:
[0010] The acquisition module is used to acquire the target image to be processed and the segmentation prompt information corresponding to the target object to be processed in the target image;
[0011] A mask image generation module is used to input the target image and the segmentation prompt information into a trained segmentation model to obtain a target mask image corresponding to the target image, perform defect insertion processing on the target mask image to obtain a defect mask image, and determine a missing mask image to indicate the missing part of the target image based on the target mask image and the defect mask image.
[0012] An image generation module is used to generate a background image based on the target mask image and the target image, and to replace the region corresponding to the missing mask image in the target image with the corresponding region in the background image to obtain a defective image.
[0013] Thirdly, this application provides a defect image generation device, comprising:
[0014] One or more processors;
[0015] A memory that stores one or more programs, which, when executed by one or more processors, cause the one or more processors to implement the defect image generation method as described in the first aspect.
[0016] Fourthly, this application provides a storage medium containing computer-executable instructions, which, when executed by a computer processor, are used to perform the defect image generation method as described in the first aspect.
[0017] In this application, a defect image generation method based on segmentation cue recognition and mask mapping is constructed, achieving structured extraction of target objects and intelligent synthesis of defect regions. After acquiring the target image to be processed and the segmentation cue information corresponding to the target objects within it, the method inputs the target image and cue information into a trained segmentation model to generate a target mask map representing the distribution of object regions, providing a regional basis for subsequent defect construction. When an operable region is detected in the target mask map, defect insertion processing is performed to generate a defect mask map, and a missing mask map is determined based on the difference between the target mask map and the defect mask map, thus accurately indicating the missing parts of the target image. Further, a background image is generated based on the target mask map and the original target image, and the target region indicated by the missing mask map is replaced with the corresponding region in the background image, ultimately generating a structurally complete and visually consistent defect image. This scheme improves the realism and controllability of defect images by combining a multi-stage generation strategy of segmentation recognition, mask fusion, and background replacement, and is suitable for defect sample generation scenarios involving multiple object categories and multi-scale textures. Attached Figure Description
[0018] Figure 1 This is a flowchart of a defect image generation method provided in an embodiment of this application;
[0019] Figure 2 This is a flowchart of a branch-type object defect insertion processing method provided in an embodiment of this application;
[0020] Figure 3 This is a flowchart of a branch endpoint determination method provided in an embodiment of this application;
[0021] Figure 4 This is a flowchart of a defect insertion processing method for an axisymmetric object provided in an embodiment of this application;
[0022] Figure 5 This is a flowchart of a method for drawing defective line segments provided in an embodiment of this application;
[0023] Figure 6 This is a flowchart of a background image generation method provided in an embodiment of this application;
[0024] Figure 7 This is a flowchart of a defect image generation method provided in an embodiment of this application;
[0025] Figure 8 This is a structural block diagram of a defect image generation device provided in an embodiment of this application;
[0026] Figure 9 This is a schematic diagram of the structure of a defect image generation device provided in an embodiment of this application. Detailed Implementation
[0027] To make the objectives, technical solutions, and advantages of this application clearer, specific embodiments of this application will be described in further detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are merely for explaining this application and not for limiting it. It should also be noted that, for ease of description, only the parts relevant to this application are shown in the drawings, not all of them. Before discussing exemplary embodiments in more detail, it should be mentioned that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although the flowcharts describe operations (or steps) as being processed sequentially, many of these operations can be performed in parallel, concurrently, or simultaneously. Furthermore, the order of the operations can be rearranged. A process can be terminated when its operation is completed, but it may also have additional steps not included in the drawings. A process can correspond to a method, function, procedure, subroutine, subroutine, etc.
[0028] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0029] Currently, defect image generation methods suffer from significant shortcomings in terms of data richness, structural controllability, and generation realism, making it difficult to meet the defect sample requirements of high-reliability industrial scenarios such as intelligent manufacturing, power transmission inspection, and precision equipment quality inspection. On the one hand, structural defects occur extremely infrequently in real-world environments, and the acquisition and annotation processes are time-consuming and costly, resulting in a severe scarcity of training samples. This becomes a key bottleneck restricting the generalization ability and recognition accuracy of anomaly detection models. On the other hand, traditional image enhancement methods can only perform limited morphological transformations on existing defect images and cannot generate defect samples with new structural features, leading to insufficient adaptability of the models in real-world industrial environments.
[0030] To address the aforementioned issues, this embodiment provides a defect image generation method. By constructing an image synthesis mechanism based on target segmentation and recognition combined with mask fusion, it achieves precise localization and high-fidelity reconstruction of defect regions. After acquiring the target image to be processed and the segmentation prompts corresponding to the target objects it contains, this method inputs the target image and prompts into a trained segmentation model to generate a target mask map representing the boundaries of the object regions, providing a structural basis for subsequent defect construction. When a defect needs to be generated, defect insertion processing is performed based on the target mask map to obtain a defect mask map containing the features of the defect region. By comparing the regional differences between the target mask map and the defect mask map, a missing mask map is determined to indicate the missing parts of the image, achieving a precise description of the defect location and extent. Based on this, this method generates a background image based on the target mask map and the original target image, and replaces the defect region indicated by the missing mask map with the corresponding region in the background image, thereby obtaining a structurally complete and visually coherent defect image. This scheme overcomes the limitations of traditional defect image generation methods in terms of defect controllability and realism through a collaborative processing mechanism of target segmentation, mask evolution, and background replacement, significantly improving the structural consistency and visual quality of generated samples. It also supports defect construction for multiple object types and multi-scale textures, enhancing the model's adaptability and versatility in complex tasks such as industrial inspection, image restoration, and quality assessment. This technical solution provides a high-precision and scalable implementation path for defect data generation under zero-shot conditions, offering a rich and reliable training data foundation for intelligent vision systems.
[0031] The defect image generation method provided in this embodiment can be executed by a defect image generation device, which can be implemented by software and / or hardware. The defect image generation device can consist of two or more physical entities, or it can consist of a single physical entity. For example, the defect image generation device can be an image generation server for generating defect images.
[0032] The defect image generation device is equipped with at least one type of operating system, including but not limited to Android, Linux, and Windows. The defect image generation device can install at least one application based on the operating system; this application can be a built-in application of the operating system or an application downloaded from a third-party device or server. In this embodiment, the defect image generation device has at least one application capable of executing the defect image generation method.
[0033] For ease of understanding, this embodiment uses an image generation server as the main entity executing the defect image generation method as an example for description.
[0034] Figure 1 A flowchart of a defect image generation method provided in an embodiment of this application is given. (Reference) Figure 1 The defect image generation method specifically includes:
[0035] S110. Obtain the target image to be processed and the segmentation prompt information corresponding to the target object to be processed in the target image. Input the target image and the segmentation prompt information into the trained segmentation model to obtain the target mask image corresponding to the target image.
[0036] In some embodiments, the process first acquires the target image to be processed and segmentation prompts corresponding to the target objects within the target image. The target image refers to the input image used for image segmentation, the target object refers to a specific region or element in the image that needs to be identified and extracted, and the segmentation prompts represent auxiliary feature information used to guide the segmentation model in recognizing the target object. These auxiliary features may include location annotations, category labels, or bounding box information. The target image can be uploaded by the client or retrieved from a pre-defined image database. After acquiring the target image and segmentation prompts, they are input into the trained segmentation model to generate a target mask map corresponding to the target image. The target mask map represents the pixel-level region division results of the target object in the image and is used for subsequent image editing, object replacement, or feature extraction operations.
[0037] In one embodiment, the segmentation model can be a SAM model based on an encoder-decoder structure, which extracts multi-level visual features through a feature extraction module and uses an attention mechanism to enhance the feature representation of the target region, thereby improving segmentation accuracy.
[0038] In one embodiment, the segmentation prompt information can be determined by generating it based on user interaction, obtaining the prompt information by the user selecting, clicking, or drawing a target area on the image.
[0039] In one embodiment, the target mask image can be generated by: thresholding the probability map output by the segmentation model, marking regions with probability values higher than a set threshold as target regions, thereby forming the final mask result.
[0040] In one embodiment, the target mask image can be generated by using SAM model binding points and box cues to generate the target mask image of the target object. ,in White areas (areas with a value of 1) represent the target object, while the remaining black areas (areas with a value of 0) represent the background. The SAM model is a general image segmentation model based on the Visual Transformer architecture, possessing zero-shot segmentation capability and interactive cue response capability. Through pre-training, the SAM model gains a generalized understanding of target region boundaries in large-scale images, and can quickly generate high-precision target masks based on multimodal cues such as points, boxes, and text. The SAM model mainly consists of three functional modules: an image encoder, a cue encoder, and a mask decoder. The image encoder uses a Vision Transformer-based backbone network to extract global features from the input image. The image encoder can transform the original image into a high-dimensional semantic feature map, thereby capturing texture information and spatial relationships at different scales. The cue encoder encodes the user-input cue information into feature vectors to guide the segmentation process to focus on specific target regions. For example, a single-point cue represents a seed pixel in the target region, while a rectangular box cue constrains the segmentation range. The mask decoder generates the corresponding target mask map based on the fusion result of image features and cue features. The mask decoder dynamically matches the cue and image semantic features through a cross-attention mechanism, thereby outputting a binarized target mask image. In this embodiment, after receiving the image and cue input, the SAM model first generates multi-scale semantic features of the image by the image encoder; then, the cue encoder maps point or box information to the same feature space; finally, the mask decoder integrates the information from both to output the target mask image. The mask image represents the target region in binary form, where white areas represent the segmented target object and black areas represent the background region. Through this structure, the SAM model can quickly adapt to different image scenes without retraining, achieving high-precision mask generation for any target object, providing an accurate spatial segmentation foundation for subsequent tasks such as feature extraction, image enhancement, or target reconstruction.
[0041] S120. Perform defect insertion processing on the target mask map to obtain a defect mask map, and determine a missing mask map to indicate the missing part of the target image based on the target mask map and the defect mask map.
[0042] In some embodiments, defect insertion processing is performed on the target mask image to generate a defect mask image. Defect insertion processing refers to the operation of introducing morphological perturbations, pixel occlusion, or texture anomalies into a specific region of the target mask image to simulate defect morphology in a real-world environment. The defect mask image represents the target object region after defect feature enhancement and is used to construct training samples or generate defect images. After obtaining the defect mask image, a missing mask image is determined based on the difference between the target mask image and the defect mask image to indicate missing portions of the target image. The missing mask image represents pixel regions in the target image that are covered or destroyed by the defect insertion operation and can be used for subsequent repair model training or defect completion processes.
[0043] In one embodiment, the defect insertion process can be as follows: select a local region in the target mask image based on a random shape generation algorithm, and perform occlusion, erosion or noise superposition operations on the region to construct defect regions of different shapes.
[0044] In one embodiment, the defect insertion process can be performed by manually modifying the target mask image. Manual editing is required; specifically, it is necessary to... The missing parts of the target object to be generated are set to zero, which means they are painted black. The resulting defect mask image... This can represent a segmentation mask image of a target object with defective parts.
[0045] In one embodiment, the missing mask image can be determined by performing pixel-level difference operations on the target mask image and the defect mask image, extracting the non-overlapping pixel regions between them, and marking these regions as missing parts to generate the corresponding missing mask image.
[0046] Optionally, Figure 2 A flowchart of a branch-type object defect insertion processing method provided in an embodiment of this application is given. (Reference) Figure 2 The specific methods for handling defect insertion in branch-type objects include:
[0047] S1201. If the target object is a branched object, perform edge point extraction on the target mask image to obtain the contour point set corresponding to the target object.
[0048] For example, when the target object is a branched object, an edge point extraction operation is performed on the target mask image to obtain the contour point set corresponding to the target object. Here, a branched object refers to a target object with a multi-branched structure or a non-closed shape, such as a crack, fiber, or fine line structure. Edge point extraction refers to the process of identifying and extracting the boundary pixels of the target object from the target mask image. The contour point set represents the edge spatial distribution information of the target object and is used for subsequent morphological reconstruction or defect generation processing.
[0049] In one embodiment, the branched object can be a target with a branched structure, such as a bird-proof windmill or a vibration damper. Its defects are mostly distributed at the branch nodes or ends and extend linearly along the branch direction.
[0050] In one embodiment, edge point extraction can be achieved by applying an edge detection algorithm, such as the Canny operator or the Sobel operator, to the target mask image to identify the boundary pixels of the target object, and recording the detected edge points in spatial coordinate order to form a set of contour points.
[0051] In one embodiment, the contour point set can be generated by performing morphological refinement and connectivity filtering on the detected edge points, removing isolated points and noise points, and retaining a sequence of boundary points with good continuity, so as to construct a contour point set that accurately describes the boundary morphology of the target object.
[0052] S1202. Determine the branch endpoints of the target object from the set of contour points, and perform defect insertion processing on the target mask map with the branch endpoints as the center to obtain a defect mask map.
[0053] For example, branch endpoints of the target object are determined from a set of contour points. Branch endpoints refer to key points at the ends of the branched object's contour structure, used to identify the start and end positions of branch extensions. These endpoints are typically obtained by analyzing the connectivity of the contour points and the branch topology. After obtaining the branch endpoints, a defect insertion process is performed on the target mask map centered on the branch endpoints to generate a defect mask map. This defect insertion process involves introducing local occlusion, erosion, or pixel perturbations in the neighborhood of the branch endpoints to simulate missing or damaged features at the branch ends. The defect mask map represents the pixel-level region distribution on the target object after defect simulation and is used to train a defect recognition or repair model.
[0054] In one embodiment, the branch endpoints can be determined by analyzing the topology of the contour point set, identifying the endpoint locations with a single adjacent point or few connected branches, and recording their coordinates to form a branch endpoint set.
[0055] In one embodiment, the defect mask image can be generated by defining the radius or shape of the defect region centered on the branch endpoint, and using a pixel-level perturbation algorithm to occlude or erode the region, thereby forming a defect region on the target mask image and generating the final defect mask image.
[0056] Optionally, Figure 3 A flowchart of a branch endpoint determination method provided in an embodiment of this application is given. (Reference) Figure 3 The method for determining the branch endpoints specifically includes:
[0057] S12021. The endpoints with the largest and smallest horizontal coordinates in the set of contour points are respectively determined as the first endpoint and the second endpoint.
[0058] For example, the endpoints with the largest and smallest x-coordinates are determined from the set of contour points. The endpoint with the largest x-coordinate is the endpoint with the largest x-coordinate value in the set of contour points, and the endpoint with the smallest x-coordinate is the endpoint with the smallest x-coordinate value in the set of contour points. The first endpoint represents the rightmost position of the branching object in the horizontal direction, and the second endpoint represents the leftmost position of the branching object in the horizontal direction, which is used for subsequent defect insertion or morphological analysis operations.
[0059] In one embodiment, the first endpoint and the second endpoint can be determined by: traversing and comparing the x-coordinates of all endpoints in the contour point set, selecting the endpoint corresponding to the maximum x-coordinate as the first endpoint, and selecting the endpoint corresponding to the minimum x-coordinate as the second endpoint.
[0060] S12022. When the target object is left-right symmetrical, the first endpoint and the second endpoint are determined as branch endpoints.
[0061] For example, when the target object is left-right symmetrical, the first endpoint and the second endpoint are determined as branch endpoints. Left-right symmetry means that the target object has a mirror distribution feature in the horizontal direction. The branch endpoints represent the key end positions of the object on both sides of the horizontal direction, which are used for subsequent defect insertion or morphological processing operations.
[0062] In one embodiment, the branch endpoints can be determined by: based on the symmetry of the target object, marking the maximum and minimum endpoints of the horizontal coordinates in the contour point set as the first branch endpoint and the second branch endpoint, respectively, to form a set of branch endpoints for center positioning in defect simulation processing.
[0063] Optionally, Figure 4 A flowchart of a defect insertion processing method for axisymmetric objects provided in an embodiment of this application is given. (Reference) Figure 4 The defect insertion processing method for this axisymmetric object specifically includes:
[0064] S1203. When the target object is an axisymmetric object, extract the target contour of the target mask image and construct the minimum bounding rectangle of the target contour to obtain the first rectangle.
[0065] For example, when the target object is an axisymmetric object, the target contour of the target mask image is first extracted. An axisymmetric object refers to an object that is mirror-symmetrical along a central axis. The target contour represents the pixel-level boundary information of the target object, used for subsequent morphological analysis and defect processing operations. After obtaining the target contour, the minimum bounding rectangle of the target contour is constructed to obtain the first rectangle. The minimum bounding rectangle is the rectangular region that can completely enclose the target contour; it has the smallest area and its boundary closely fits the target contour. The first rectangle is used to determine the spatial range and symmetry center position of the object, providing a reference for defect insertion and branch endpoint positioning.
[0066] In one embodiment, the minimum bounding rectangle can be constructed by analyzing the set of boundary points of the target contour, calculating its minimum enclosing rectangle at each rotation angle, selecting the rectangle with the smallest area as the first rectangle, and recording the center coordinates and boundary coordinates of the rectangle.
[0067] S1204. Determine the long side of the first rectangle, and shorten the distance between the opposite long sides of the first rectangle to obtain the second rectangle.
[0068] For example, the long sides of a first rectangle are determined, where the long sides refer to the two longer sides of the first rectangle, used to describe the spatial extension range of the target object in the main symmetry direction. After obtaining the long sides, a second rectangle is obtained by shortening the distance between the opposite long sides of the first rectangle, where the second rectangle represents a rectangular region after local compression along the long side direction, used to assist in defect insertion or local shape adjustment, maintain the axial symmetry characteristics of the object, and provide a spatial reference for defect simulation.
[0069] In one embodiment, the second rectangle can be generated by: calculating the center line between the two long sides along the long side direction, shrinking the long sides towards the center line by a set scaling ratio to obtain the second rectangle with shortened spacing, and recording its boundary and center coordinate information.
[0070] S1205. Using the second rectangle, perform defect insertion processing on the target mask image to obtain a defect mask image.
[0071] For example, a defect insertion process is performed on the target mask map using a second rectangle to generate a defect mask map. The defect insertion process refers to introducing local pixel occlusion, erosion or perturbation within the target object area covered by the second rectangle to simulate the missing or damaged features of an axisymmetric object. The defect mask map represents the pixel-level region distribution on the target object after defect simulation and can be used to train a defect detection or repair model.
[0072] In one embodiment, the defect mask image can be generated by: defining the shape and size of the defect region with reference to the boundary and center of the second rectangle, performing pixel-level perturbation or occlusion operations on the region, and smoothing the defect boundary through an edge fusion algorithm to form the final defect mask image.
[0073] Optionally, Figure 5 A flowchart of a method for drawing defect line segments according to an embodiment of this application is provided. (Reference) Figure 5 The specific method for drawing the defect line segment includes:
[0074] S12051. Use the long side of the second rectangle as the reference axis for defect insertion processing.
[0075] For example, the long side of the second rectangle is determined as the reference axis for defect insertion processing. The reference axis refers to the reference direction used to guide the positioning and shape generation of the defect area. It is usually consistent with the main symmetry direction or extension direction of the target object, which can ensure that the defect insertion is coordinated with the overall structure of the object.
[0076] In one embodiment, the reference axis can be determined by: extracting the long side vector of the second rectangle, using this vector as a directional reference for defect insertion processing, and defining the position and extension range of the defect region along the direction of the reference axis for subsequent generation of the defect mask map.
[0077] S12052. The reference axis is divided into a set of target line segments located in the target mask image using a straight line algorithm, and the set of defect line segments is determined based on the set of target line segments.
[0078] For example, a linear algorithm is used to segment the reference axis into a set of target line segments located in the target mask image. The linear algorithm divides the reference axis along its length into several continuous line segments, each corresponding to an operable pixel region in the target mask image. The set of target line segments represents the segmented structure information of the target object along the reference axis, used for defect insertion and localization. After obtaining the set of target line segments, a set of defect line segments is determined based on this set. The set of defect line segments refers to the line segment regions selected or adjusted based on the target line segments, used for performing defect insertion operations. Each defect line segment corresponds to a pixel region in the target mask image that will be simulated as missing or damaged.
[0079] In one embodiment, the target line segment set can be generated by using the Bresenham line algorithm to divide the reference axis into line segments located within the white area of the mask image, thereby generating at least one target line segment pair. And convert the target line segment pairs into a set of target line segments.
[0080] In one embodiment, the set of defective line segments can be determined by: selecting some line segments as defective line segments based on the length, position and distribution characteristics of the target line segments according to a preset defect ratio or random perturbation rule, and recording the start and end coordinates of each defective line segment for defect mask generation.
[0081] Optionally, determining the set of defective line segments based on the target line segment set includes:
[0082] Calculate the average length of the line segments in the target line segment set to obtain the average length of the line segments.
[0083] For example, the length of each line segment in the target line segment set is calculated, and the average length of all line segments is calculated to obtain the average length of the line segments. The line segment length refers to the Euclidean distance or straight-line distance of each target line segment in the pixel coordinate space. The average length of the line segments characterizes the typical line segment scale of the target object along the reference axis, which can be used to guide the size setting of defective line segments or the local range of defect insertion.
[0084] In one embodiment, the average length of a line segment can be calculated by summing the lengths of each line segment in the target line segment set and then dividing by the total number of line segments to obtain a representative average length, which can be used as a scale reference in subsequent defect insertion processing.
[0085] The defective line segment set is obtained by filtering the line segments in the target line segment set that are within a preset multiple of the average length of the line segments.
[0086] For example, line segments within a preset multiple range of the average length of the line segments are selected from the target line segment set to obtain a defect line segment set. The preset multiple range refers to the line segment length interval defined by the upper and lower limits based on the average length of the line segments. The defect line segment set represents a subset of target line segments suitable for defect insertion and can be used to generate defect areas with reasonable size and distribution.
[0087] In one embodiment, the defective line segment set can be filtered by comparing the length of each line segment in the target line segment set with the average length of the line segments, selecting line segments whose lengths are between the upper and lower limits of a preset multiplier, and forming these line segments into a defective line segment set for subsequent defect mask image generation.
[0088] In one embodiment, the defective line segment set can be filtered by length based on the length of each line segment in the target line segment set, retaining lengths between 0.2 and 1.5 times the average length. The average length of the line segments between them The calculation method is as follows:
[0089]
[0090] in, The total number of line segments in the target line segment set. and They are respectively x and y coordinates and They are respectively The x and y coordinates.
[0091] S12053. Generate a set of defect curves with curvature based on the set of defect line segments, and draw the set of defect curves onto the target mask to obtain the defect mask.
[0092] For example, a set of defect curves with curvature is generated based on a set of defect line segments. The set of defect curves refers to continuous curves obtained by smoothing or curve fitting the defect line segments, and the curvature characterizes the degree of curvature of the curves, used to simulate natural or random defect morphologies on the target object. After obtaining the set of defect curves, this set is plotted onto a target mask to generate a defect mask. The defect mask represents the pixel-level region distribution on the target object after defect simulation and can be used to train a defect recognition or repair model.
[0093] In one embodiment, the defect curve set can be generated by applying spline curve fitting or Bezier curve interpolation algorithm to the defect line segment set, introducing a certain random perturbation to simulate the bending shape of the real defect, and forming a continuous and smooth defect curve set.
[0094] In one embodiment, the defect curve set can be generated by: for each selected... It generates a circular arc or Bézier curve with curvature based on geometric constraints.
[0095] In one embodiment, the defect mask image can be generated by: drawing the defect curve set on the target mask image at the pixel level, and filling the pixels around the curve according to the defect width and edge smoothing strategy, thereby obtaining a complete defect mask image.
[0096] S130. Generate a background image based on the target mask image and the target image, and replace the region corresponding to the missing mask image in the target image with the corresponding region in the background image to obtain a defective image.
[0097] For example, a background image is generated based on the target mask and the target image. The background image refers to the pure background region image formed by removing the target object region from the target image, used to provide a background filling reference during defect generation. The background image can be generated using image inpainting algorithms or texture diffusion algorithms to maintain overall visual continuity and background consistency. After generating the background image, the region corresponding to the missing mask in the target image is replaced with the region at the same location in the background image, thus obtaining the defect image. The defect image represents the image result obtained after simulating defects in the original target image, possessing realistic defect features and natural background transition characteristics, and can be used for training and validation of subsequent defect detection or repair models.
[0098] In one embodiment, the background image can be generated by: segmenting the target image using a target mask image, setting the pixels of the target object region to null values, and filling in the missing regions using a texture propagation-based repair algorithm to generate a structurally complete background image.
[0099] In one embodiment, the defective image can be generated by: determining the missing region of the target image based on the missing mask image, replacing the pixels in the missing region with the pixel values of the corresponding region in the background image, and smoothing the replacement boundary through edge fusion and color adjustment algorithms to ensure that the defective region and the original image are visually seamlessly connected.
[0100] In one embodiment, the defect image can be generated based on a missing mask image. For the target image and background image Defect images The synthesis, that is, the target image Corresponding missing mask image The area is covered by a background image. Corresponding region replacement:
[0101]
[0102] Optionally, Figure 6 A flowchart of a background image generation method provided in an embodiment of this application is given. (Reference) Figure 6 The background image generation method specifically includes:
[0103] S1301. Obtain the background prompt text corresponding to the background portion in the target image.
[0104] For example, background prompt text corresponding to the background portion in the target image is obtained. The background prompt text refers to text information used to describe or identify the features of the background region of the target image, which can assist in the generation or filling of the background image. The background portion refers to the pixel region in the target image that does not contain the target object, which is used to provide semantic guidance in the process of defect generation or image repair.
[0105] In one embodiment, the background hint text can be obtained by: masking the target object region based on the target mask image, inputting the remaining background region into an image annotation model or an image description model, and automatically generating semantic text hints to guide the generation of the background image or the filling of missing regions.
[0106] S1302. Perform dilation processing on the target mask image to obtain the dilated mask image corresponding to the target object.
[0107] For example, dilation processing is performed on the target mask image to obtain a dilated mask image corresponding to the target object. Here, dilation processing refers to performing a morphological expansion operation on the target object region in the target mask image, which expands the spatial coverage of the target object by increasing the boundary pixels of the target region. The dilated mask image represents the target object region after dilation and is used for subsequent background fusion or defect region filling.
[0108] In one embodiment, the dilated mask image can be generated by performing a morphological dilation operation on the target mask image based on the structuring element, expanding the boundary of the target region outward by a set number of pixels, thereby obtaining the dilated target object mask image, which is used to enhance the connection effect between the target object and the background.
[0109] S1303. Input the target image, the dilated mask image, and the background prompt text into the trained image inpainting model to obtain a background image with the target object removed.
[0110] For example, the target image, the dilated mask image, and the background cue text are input into the trained image inpainting model to obtain the background image after removing the target object. The image inpainting model refers to a deep learning-based generative model that can generate visually continuous and natural image regions using the input mask information and semantic cue text. The background image represents the filling result of the original image background region after removing the target object, and is used for subsequent defect insertion or image synthesis operations.
[0111] In one embodiment, the background image can be generated as follows: the image inpainting model reconstructs the pixels of the target object region indicated by the dilated mask map, while using background cue text to provide semantic constraints, and generating fill pixels consistent with the surrounding background through a convolutional neural network or attention mechanism, thereby obtaining a complete and natural background image.
[0112] In one embodiment, the background image can be generated by using a target mask image. StableDiffusion inpainting removes the target object from the target image. The middle area is erased, and the corresponding area is filled with the background to obtain the background image. :
[0113]
[0114] In this process, to better erase the target object, appropriate measures can be taken. Perform expansion treatment to ensure It can completely cover the target object, thereby improving performance. The erasure effect. During the background restoration process, text hints for the SD model. The model can be guided to generate content consistent with the surrounding background by providing either image content or empty prompts. By erasing the target from a normal image and filling the target area with background, data with overall missing units can be effectively generated. The SD model is a generative image model based on a latent space diffusion mechanism, capable of generating high-fidelity images matching the input content based on text prompts or semantic conditions. The SD model achieves efficient image generation and local inpainting by performing diffusion and de-diffusion processes in the compressed latent space. The core structure of the SD model includes three main modules: a variational autoencoder, a U-Net diffusion network, and a text encoder. The variational autoencoder encodes the input image into the latent feature space and decodes the latent space features into a high-resolution image during the generation stage. Diffusion sampling in the low-dimensional latent space significantly reduces computational cost and improves generation speed. The U-Net diffusion network, as the backbone of the diffusion process, is used to progressively denoise and reconstruct semantically consistent image features in the latent space. The U-Net structure consists of multiple layers of convolutional encoders and decoders, with skip connections fusing multi-scale features, enabling the model to simultaneously capture local details and global semantic information. Text encoders typically employ pre-trained language models to encode the input text cue T into semantic vectors. A cross-attention mechanism guides the U-Net to generate semantically relevant content during the diffusion process, thus achieving text-controlled image generation. In background restoration scenarios, the SD model first uses the target mask image... Identify the area requiring repair, treating it as the initial noise portion of the latent space; then, incorporate textual prompts during the diffusion inversion process. Based on the features of the surrounding unoccluded areas, the model is guided to generate content that is semantically consistent with the original background. (If prompted...) If the image is empty, the model tends to automatically fill in the missing areas based on the image context information, thereby achieving natural background extension and defect area repair. Through the above mechanism, the SD model can effectively erase and repair the target object while maintaining the continuity of the overall image structure and texture, achieving realistic synthesis and amplification of data with missing unit structures, and providing high-quality samples for the training of subsequent detection models.
[0115] Optionally, Figure 7 A flowchart of a defect image generation method provided in an embodiment of this application is given. (Reference) Figure 7 The defect image generation method includes:
[0116] S201, Target Image The acquisition of.
[0117] For example, acquiring the target image , among which, target image The input image used for subsequent processing or analysis contains the target object to be processed and its background information, and can be uploaded by the client, called from an image database, or acquired by an image acquisition device.
[0118] In one embodiment, the target image The acquisition methods can be: directly capturing or scanning images through image acquisition devices, or reading existing image files from a storage system and performing necessary preprocessing on the images, such as resizing, format conversion, or color space standardization, to meet the input requirements of subsequent processing flows.
[0119] S202 and SAM segmentation.
[0120] For example, for the target image Using the SAM model combined with point and box hints, a target mask image of the target object is generated. In the target mask image, the white area represents the target object, and the remaining black area represents the background.
[0121] S203, Processing of the defect mask generator.
[0122] For example, after obtaining the target mask image After that, it is necessary to combine Based on the shape characteristics, a defect mask image is generated customizable for it. There are two methods for generating defect mask images: manual drawing and automatic generation.
[0123] In one embodiment, if precise control over the location and size of the defect is desired, the target mask image can be manually adjusted. Manual editing is required; specifically, it is necessary to... The missing parts of the target object to be generated are set to zero, which means they are painted black. The resulting defect mask image... This can represent a segmentation mask image of a target object with defective parts.
[0124] In one embodiment, if there are no strict requirements regarding the size of the defect location and it is desirable to generate defect images in batches, an automatic defect mask generator can be used to obtain diverse defect mask images. The specific implementation of defect masking can be divided into two types based on the structural characteristics of the target object: branch-type target defect masking and axisymmetric target defect masking.
[0125] In one embodiment, for branched targets such as bird-proof windmills and vibration dampers, the defects generally occur at a certain branch location and primarily extend from the branch endpoint. This can be addressed by first... Edge point extraction is performed to obtain a set of contour points for the target contour. Then, branch endpoints are found from this set of contour points. Specifically, the maximum and minimum values are found in the x-coordinate and y-coordinate of all points, thus identifying the four endpoints (left, right, up, and down) of the target contour. , , , These four special points generally contain branch endpoints. For example, in a left-right symmetrical branching structure... and These are the branch endpoints. Based on the characteristics of the target structure, filtering conditions can be set to select from the four endpoints found each time. After finding a branch endpoint, ellipses, circles, triangles, rectangles, etc., are drawn with that endpoint as the center, and this pattern is then compared with... Setting the intersecting parts to zero yields the defect mask image. The size of the pattern can be determined according to... The size can be flexibly set within a range of values.
[0126] In one embodiment, for axisymmetric targets such as insulators, gears, and rotary printed parts that are periodically connected in series, the defects mainly occur in the series units. Therefore, the target object is first extracted. Outline the shape, construct its smallest bounding rectangle, determine the two longer sides of the rectangle, and reduce the distance between the two longer sides to make it equal to the bounding rectangle. The intersecting units in series serve as a reference axis. The Bresenham line algorithm is used to segment the defect insertion along the reference axis into line segments located within the white area of the mask image, generating target line segment pairs. These line segments are filtered based on length, retaining those with a length of 0.2 times the average length. Up to 1.5 times the average length Line segments between:
[0127]
[0128] in, The total number of line segments in the target line segment set. and They are respectively x and y coordinates and They are respectively The x and y coordinates.
[0129] For each selected Generate a circular arc or Bézier curve with curvature based on geometric constraints, and plot the curve on... This allows for the simulation of defects such as "nonlinear fractures" or "cracks." Through contour analysis, the segmented main contour regions are extracted from the image after curve plotting, thus obtaining a newly generated defect mask image. By controlling the curvature of the arc and the way the two endpoints are connected, a variety of shapes can be generated. .
[0130] S204, Image generation of locally missing units.
[0131] For example, based on the target mask image and defect mask image obtained above, a missing mask image can be obtained. Finally, the missing mask image is used. For the target image and background image Defect images The synthesis, that is, the target image Corresponding missing mask image The area is covered by a background image. Corresponding region replacement:
[0132]
[0133] S205~S206, Use SD erasure to generate background image .
[0134] For example, using Stable Diffusion inpainting removes the target object from the image and fills the corresponding area with the background to obtain the background image. :
[0135]
[0136] In one embodiment, to better erase the target object, appropriate measures can be taken... Perform expansion treatment to ensure It can completely cover the target object, thereby improving performance. The erasure effect. During the background restoration process, text hints for the SD model. The prompt can be provided in conjunction with the image content or directly with an empty prompt word, guiding the model to generate content consistent with the surrounding background. By erasing the target from the target image and filling the target area with background, data with overall missing cells can be effectively generated.
[0137] S207, Image generation of a unit that is completely missing.
[0138] For example, an image with a completely missing unit is generated, where a completely missing unit refers to the removal or occlusion of a specific target object or region in the target image to simulate a scenario of missing or damaged objects. The generated image is used for defect detection, repair model training, or image enhancement tasks.
[0139] In one embodiment, the method for generating an image with an overall missing unit can be as follows: first, the target object region is determined based on the target mask image; then, the region is erased from the target image or replaced with a background image region; and the missing region is smoothly transitioned using an image inpainting algorithm or a filling algorithm to ensure that the generated image is visually seamless while preserving the background information and features of the non-missing regions of the original image.
[0140] Based on the above embodiments, Figure 8 This is a structural block diagram of a defect image generation apparatus provided in an embodiment of this application. (Reference) Figure 8 The defect image generation device provided in this embodiment specifically includes: an acquisition module 21, a mask image generation module 22, and an image generation module 23.
[0141] The acquisition module 21 is configured to acquire the target image to be processed and the segmentation prompt information corresponding to the target object to be processed in the target image; the mask image generation module 22 is configured to input the target image and the segmentation prompt information into the trained segmentation model to obtain the target mask image corresponding to the target image, perform defect insertion processing on the target mask image to obtain a defect mask image, and determine a missing mask image to indicate the missing part of the target image based on the target mask image and the defect mask image; the image generation module 23 is configured to generate a background image according to the target mask image and the target image, and replace the region corresponding to the missing mask image in the target image with the corresponding region in the background image to obtain the defect image.
[0142] Based on the above embodiments, the mask image generation module 22 includes: a contour point extraction unit, configured to extract edge points from the target mask image when the target object is a branch object, to obtain a set of contour points corresponding to the target object; a branch endpoint determination unit, configured to determine the branch endpoints of the target object from the set of contour points; and an endpoint defect insertion unit, configured to perform defect insertion processing in the target mask image with the branch endpoints as the center to obtain a defect mask image.
[0143] Based on the above embodiments, the branch endpoint determination unit includes: an endpoint determination subunit configured to determine the endpoints with the largest and smallest horizontal coordinates in the contour point set as the first endpoint and the second endpoint, respectively; and a branch endpoint determination subunit configured to determine the first endpoint and the second endpoint as branch endpoints when the target object is left-right symmetrical.
[0144] Based on the above embodiments, the mask image generation module 22 further includes: a first rectangle unit, configured to extract the target contour of the target mask image and construct the minimum bounding rectangle of the target contour to obtain a first rectangle when the target object is an axisymmetric object; a second rectangle unit, configured to determine the long side of the first rectangle and shorten the spacing between the opposite long sides of the first rectangle to obtain a second rectangle; and a rectangle defect insertion unit, configured to use the second rectangle to perform defect insertion processing on the target mask image to obtain a defect mask image.
[0145] Based on the above embodiments, the rectangular defect insertion unit includes: a reference axis subunit, configured to use the long side of the second rectangle as the reference axis for defect insertion processing; a defect line segment subunit, configured to use a straight line algorithm to divide the reference axis into a set of target line segments located in the target mask image, and determine a set of defect line segments based on the set of target line segments; and a defect mask image subunit, configured to generate a set of defect curves with curvature based on the set of defect line segments, and draw the set of defect curves onto the target mask image to obtain a defect mask image.
[0146] Based on the above embodiments, the defective line segment subunit includes: an average length component, configured to calculate the average length of line segments in the target line segment set to obtain the average length of the line segments; and a line segment filtering component, configured to filter line segments in the target line segment set that are within a preset multiple range of the average length of the line segments to obtain a defective line segment set.
[0147] Based on the above embodiments, the image generation module 23 includes: a text prompt unit configured to acquire background prompt text corresponding to the background portion in the target image; a mask dilation unit configured to dilate the target mask image to obtain an dilated mask image corresponding to the target object; and a background image unit configured to input the target image, the dilated mask image, and the background prompt text into a trained image inpainting model to obtain a background image with the target object removed.
[0148] The defect image generation apparatus provided in this application embodiment, by constructing a hierarchical collaborative processing system consisting of an acquisition module, a mask image generation module, and an image generation module, achieves automated control of target image processing, defect insertion, and missing region annotation, improving the reliability and controllability of defect image generation while ensuring image structural integrity and processing accuracy. The acquisition module 21 has the capability to acquire input images and can automatically complete target object recognition and information acquisition after receiving the target image to be processed and the corresponding target object segmentation prompt information. The target image may include natural scene images or industrial inspection images, and the target object segmentation prompt information may include points, boxes, or text prompts to guide subsequent segmentation processing to accurately locate the target region. The mask image generation module 22 undertakes the target region segmentation and defect generation tasks. After receiving the target image and segmentation prompt information, it inputs them into the trained segmentation model to generate a target mask image. Subsequently, this module performs defect insertion processing on the target mask image to generate a defect mask image. The defect insertion processing can be based on a preset defect shape, texture perturbation, or random generation strategy to achieve simulated defect overlay on the target region. The module further automatically generates a missing mask map to indicate the missing parts of the target image based on the difference between the target mask map and the defect mask map, thereby accurately characterizing the structurally incomplete or texture-deficient areas in the target image and providing pixel-level reference for subsequent image processing. The image generation module 23 is responsible for the generation and region replacement of the defect image. It can generate a background image based on the target mask map and the original target image, and replace the corresponding region in the missing mask map with the corresponding region in the background image to finally obtain the defect image. This module realizes the automated fusion of defect insertion and background filling, ensuring that the generated image maintains a balance between defect simulation and overall visual effect, and improving the practicality and reliability of defect images in application scenarios such as training data augmentation, visual inspection, or quality assessment. Based on the target image acquisition, mask map generation, and image generation path constructed by the above modules, the device realizes closed-loop control of the defect image generation process, has high-precision target positioning, defect simulation, and missing region annotation capabilities, and can be widely used in scenarios such as visual data augmentation, industrial defect simulation, and artificial intelligence training data generation.
[0149] The defect image generation apparatus provided in this application embodiment can be used to execute the defect image generation method provided in the above embodiment, and has corresponding functions and beneficial effects.
[0150] Figure 9 This is a schematic diagram of the structure of a defect image generation device provided in an embodiment of this application, with reference to... Figure 9 The defect image generation device includes a processor 31, a memory 32, a communication device 33, an input device 34, and an output device 35. The number of processors 31 and the number of memories 32 in the defect image generation device can be one or more. The processor 31, memory 32, communication device 33, input device 34, and output device 35 of the defect image generation device can be connected via a bus or other means.
[0151] The memory 32, as a computer-readable storage medium, can be used to store software programs, computer-executable programs, and modules, such as program instructions / modules corresponding to the defect image generation method in any embodiment of this application (e.g., acquisition module 21, mask image generation module 22, and image generation module 23 in the defect image generation apparatus). The memory 32 may primarily include a program storage area and a data storage area. The program storage area may store the operating system and at least one application program required for a function; the data storage area may store data created based on the use of the device, etc. Furthermore, the memory 32 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state storage device. In some instances, the memory may further include memory remotely located relative to the processor, and these remote memories can be connected to the device via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0152] The communication device 33 is used for data transmission.
[0153] The processor 31 executes various functional applications and data processing of the device by running software programs, instructions and modules stored in the memory 32, thereby realizing the above-mentioned defect image generation method.
[0154] Input device 34 can be used to receive input digital or character information, and to generate key signal inputs related to user settings and function control of the device. Output device 35 may include display devices such as a display screen.
[0155] The defect image generation device provided above can be used to execute the defect image generation method provided in the above embodiments, and has corresponding functions and beneficial effects.
[0156] This application embodiment also provides a storage medium containing computer-executable instructions. When executed by a computer processor, the computer-executable instructions are used to perform a defect image generation method. The defect image generation method includes: acquiring a target image to be processed and segmentation prompt information corresponding to a target object to be processed in the target image; inputting the target image and the segmentation prompt information into a trained segmentation model to obtain a target mask image corresponding to the target image; performing defect insertion processing on the target mask image to obtain a defect mask image; determining a missing mask image for indicating missing parts of the target image based on the target mask image and the defect mask image; generating a background image according to the target mask image and the target image; and replacing the region corresponding to the missing mask image in the target image with the corresponding region in the background image to obtain a defect image.
[0157] Storage medium—any type of memory device or storage device. The term "storage medium" is intended to include: mounting media, such as CD-ROM, floppy disk, or magnetic tape devices; computer system memory or random access memory, such as DRAM, DDR RAM, SRAM, EDO RAM, etc.; non-volatile memory, such as flash memory, magnetic media (e.g., hard disk or optical storage); registers or other similar types of memory elements, etc. Storage medium may also include other types of memory or combinations thereof. Furthermore, storage medium may reside in a first computer system in which a program is executed, or it may reside in a different second computer system connected to the first computer system via a network (such as the Internet). The second computer system can provide program instructions to the first computer for execution. The term "storage medium" may include two or more storage media residing in different locations (e.g., in different computer systems connected via a network). Storage medium may store program instructions (e.g., specifically implemented as a computer program) executable by one or more processors.
[0158] Of course, the computer-executable instructions provided in the embodiments of this application are not limited to the defect image generation method described above, but can also perform related operations in the defect image generation method provided in any embodiment of this application.
[0159] The defect image generation apparatus, storage medium, and defect image generation device provided in the above embodiments can execute the defect image generation method provided in any embodiment of this application. For technical details not described in detail in the above embodiments, please refer to the defect image generation method provided in any embodiment of this application.
[0160] The above description is merely a preferred embodiment and the technical principles employed in this application. This application is not limited to the specific embodiments described herein, and various obvious changes, readjustments, and substitutions that can be made by those skilled in the art will not depart from the scope of protection of this application. Therefore, although this application has been described in detail through the above embodiments, this application is not limited to the above embodiments, and may include many other equivalent embodiments without departing from the concept of this application. The scope of this application is determined by the scope of the claims.
Claims
1. A defect image generation method characterized by comprising: The method comprises the following steps: obtaining a target image to be processed and segmentation prompt information corresponding to a target object to be processed in the target image, inputting the target image and the segmentation prompt information into a trained segmentation model to obtain a target mask corresponding to the target image; performing defect insertion processing on the target mask to obtain a defect mask, and determining a missing mask for indicating a missing part of the target image based on the target mask and the defect mask; generating a background image according to the target mask and the target image, replacing a region corresponding to the missing mask in the target image with a corresponding region in the background image to obtain a defect image; the method of generating a background image according to the target mask and the target image comprises: obtaining background prompt text corresponding to a background part in the target image; performing dilation processing on the target mask to obtain a dilated mask corresponding to the target object; inputting the target image, the dilated mask and the background prompt text into a trained image inpainting model to obtain a background image in which the target object is removed; the method of inputting the target image, the dilated mask and the background prompt text into the trained image inpainting model to obtain the background image in which the target object is removed comprises: inputting the target image, the dilated mask and the background prompt text into the trained image inpainting model, generating a background for a region where the dilated mask is located while keeping the image content of a region outside the dilated mask in the target image unchanged, and outputting the background image in which the target object is removed.
2. The defect image generation method according to claim 1, characterized by, the method of performing defect insertion processing on the target mask to obtain a defect mask comprises: in a case where the target object is a branch object, performing edge point extraction on the target mask to obtain a set of contour points corresponding to the target object; determining branch end points of the target object from the set of contour points, and performing defect insertion processing on the target mask with the branch end points as centers to obtain a defect mask.
3. The defect image generation method according to claim 2, characterized by, the method of determining branch end points of the target object from the set of contour points comprises: determining an end point with the maximum horizontal coordinate and an end point with the minimum horizontal coordinate in the set of contour points as a first end point and a second end point respectively; in a case where the target object is left-right symmetrical, determining the first end point and the second end point as branch end points.
4. The defect image generation method according to claim 1, characterized by, the method of performing defect insertion processing on the target mask to obtain a defect mask comprises: in a case where the target object is an axis-symmetrical object, extracting a target contour of the target mask, constructing a minimum circumscribed rectangle of the target contour to obtain a first rectangle; determining a long side of the first rectangle, shortening the interval between the opposite long sides of the first rectangle to obtain a second rectangle; performing defect insertion processing on the target mask by using the second rectangle to obtain a defect mask.
5. The defect image generation method according to claim 4, characterized in that, the method of performing defect insertion processing on the target mask by using the second rectangle to obtain a defect mask comprises: taking the long side of the second rectangle as a reference axis for defect insertion processing; The reference axis is divided into a target line segment set located in the target mask image by using a straight line algorithm, and a defect line segment set is determined according to the target line segment set; A defect curve set with an arc is generated based on the defect line segment set, and the defect curve set is drawn on the target mask image to obtain a defect mask image.
6. The defect image generation method according to claim 5, characterized in that, The defect line segment set is determined according to the target line segment set, including: An average value of lengths of line segments in the target line segment set is calculated to obtain a line segment average length; Line segments in the target line segment set that are within a preset multiple range of the line segment average length are screened to obtain a defect line segment set.
7. A defect image generating apparatus characterized by comprising: It includes: An acquisition module is configured to acquire a target image to be processed and segmentation prompt information corresponding to a target object to be processed in the target image; A mask image generation module is configured to input the target image and the segmentation prompt information into a trained segmentation model to obtain a target mask image corresponding to the target image, perform defect insertion processing on the target mask image to obtain a defect mask image, and determine a missing mask image for indicating a missing part of the target image based on the target mask image and the defect mask image; An image generation module is configured to generate a background image according to the target mask image and the target image, replace a region corresponding to the missing mask image in the target image with a corresponding region in the background image, and obtain a defect image; The image generation module includes a text prompt unit configured to acquire background prompt text corresponding to a background part in the target image, a mask inflation unit configured to perform inflation processing on the target mask image to obtain an inflation mask image corresponding to the target object, and a background image unit configured to input the target image, the inflation mask image, and the background prompt text into a trained image inpainting model to obtain a background image in which the target object is removed; The background image unit includes a background image component configured to input the target image, the inflation mask image, and the background prompt text into the trained image inpainting model, perform background generation on a region where the inflation mask image is located while keeping image content of a region outside the inflation mask image in the target image unchanged, and output a background image in which the target object is removed.
8. A defect image generation apparatus characterized by comprising: It includes: One or more processors; A memory storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement the defect image generation method according to any one of claims 1-6.
9. A storage medium containing computer-executable instructions, wherein: The computer executable instructions, when executed by a computer processor, are used to perform the defect image generation method according to any one of claims 1-6.
Citation Information
Patent Citations
Defect sample generation method and device
CN120219877A
New type product defect image generation method, device and equipment and storage medium
CN120337476A