Sketch image repairing and editing method and system based on diffusion network
Through the sketch image inpainting and editing method based on the diffusion network, combined with the sketch enhancement network and the mask expansion module, the semantic level understanding and editing challenges in the field of image inpainting are solved, high-quality, realistic inpainting results are generated, and the user's manual selection of inpainting is solved. It solves the time-consuming problem of regional problems and achieves natural fusion and high-consistency repair effects.
Patent Information
- Application Number
- CN202410637667.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-22
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2044-05-22
AI Technical Summary
Existing technologies are difficult to generate high-quality, realistic repair results in the field of image repair. In particular, there are challenges in image understanding and editing at the semantic level, and users need to manually select the repair area, which is time-consuming.
A sketch image repair and editing method based on diffusion network is adopted to predict the ideal repair area by learning the association between text and sketch. The sketch enhancement network, mask expansion module and diffusion network are used to enhance the semantic consistency and semantic consistency between the repair area and the context. Spatial alignment produces natural, realistic restoration results.
It achieves the generation of restoration results that are highly coordinated and naturally integrated with the surrounding environment. The content remains consistent with the original image in terms of texture, color and lighting, significantly improving visual quality and consistency and meeting users' needs for high-quality image restoration.
Smart Images

Figure CN118587124A
Abstract
Description
Technical Field
[0001] The invention belongs to the field of diffusion network image restoration in computer graphics, and in particular relates to an image restoration editing method and system based on a diffusion network. Background Art
[0002] In the field of image restoration, scientists initially relied mainly on rule-based methods such as interpolation, but the restoration losses for complex images were serious; later, with the rise of deep learning technology, image restoration has made great progress in generating restoration and fusion effects.
[0003] Deng et al. proposed a method based on efficient Transformer. By introducing hierarchical encoders and self-attention modules to find the application of self-attention mechanisms at each scale, long-range dependencies between features are established, and gated convolution is used to improve the expressiveness and efficiency of the model. However, this method still relies on accurate mask information. In practical applications, obtaining accurate masks may be challenging. Dong et al. proposed an incremental image restoration structure that generates high-quality restoration results by gradually refining features. In terms of mask acquisition, a dynamic attention mask is designed to adaptively adjust the attention weight according to the current restoration state, so that the model can pay more attention to the feature information related to the restoration. In the decoder part, a multi-head attention mechanism is used to capture feature dependencies between long distances. However, this method still stays at the feature representation and restoration of the image level, and the semantic level image understanding and editing remain to be solved. Ni et al. proposed a language-guided image restoration algorithm that uses text description information to guide the image restoration process and generates high-quality restoration results that meet the description. A defect-free vector quantization generative adversarial network is introduced in the network structure as a generative model for image restoration. However, this method does not have enough understanding of contextual pixels. Although it can generate semantically consistent objects, artifacts and unnatural fusion will inevitably occur during edge fusion. Yu et al. proposed a multi-scale restoration strategy and attention mechanism to enable the restoration model to better understand and utilize the contextual information of the image, and achieved excellent performance results on the diffusion network, but the user needs to manually select the target area to be restored, which may be time-consuming when processing complex subject images.
[0004] In the field of image restoration, many challenges remain in generating high-quality, realistic images. Summary of the invention
[0005] In view of the shortcomings of the prior art, the present invention proposes a sketch image restoration editing method and system based on diffusion network, which predicts the ideal restoration area by learning the relationship between text and sketch, and enhances the semantic consistency and spatial alignment of the restoration area with the context by modeling local and global long-range dependencies, thereby generating more realistic and natural restoration results.
[0006] The technical solution adopted by the present invention to solve the technical problem is:
[0007] In a first aspect, the present invention proposes a sketch image restoration and editing method based on a diffusion network, comprising the following steps:
[0008] Get the sketch, text description data and the original image to be edited;
[0009] Generate a contour map corresponding to the sketch using a sketch enhancement network;
[0010] According to the contour map and text description, a mask dilation module is used to generate a moderately dilated mask map;
[0011] According to the moderately expanded mask image and the original image to be edited, a mask position map and the masked original image are generated using a mask position module;
[0012] According to the contour map, the mask position map, the masked original image and the text description, a diffusion network is used to generate the edited original image.
[0013] Furthermore, the sketch enhancement network includes a fusion module and an enhancement module based on a codec structure, wherein the fusion module takes the sketch as input to generate a refined sketch, and the enhancement module takes the refined sketch as input to generate a contour map.
[0014] Furthermore, the training process of the sketch enhancement network includes:
[0015] Randomly delete some strokes from the original sketch, regard the original sketch as a fine sketch, and regard the sketch after deleting the strokes as a rough sketch. The training goal of the fusion module is to convert the rough sketch into a fine sketch.
[0016] The contour of the original sketch is extracted as a label, and the training objective of the enhancement module is to convert the refined sketch into a contour map.
[0017] Furthermore, the mask expansion module includes a mask expansion encoder and a mask expansion decoder. The mask expansion encoder takes the initial mask image and text description corresponding to the contour image as input to generate an expanded mask feature, and the mask expansion decoder takes the expanded mask feature, the mask image, and the expansion kernel size as input to generate an expanded mask image.
[0018] Furthermore, in the decoding process of the mask expansion decoder, a step-by-step decoding method is adopted. At each decoding step, the mask map after the current step expansion is generated according to the current step element in the expansion mask feature and the latest mask map, and all elements in the expansion mask feature are traversed, and the final mask map is used as the moderately expanded mask map.
[0019] Furthermore, the mask position module is specifically:
[0020] The moderately expanded mask image is processed with four convolution kernels in different directions to generate four feature maps containing directional information;
[0021] Perform 3*3 convolution on the moderately expanded mask image to obtain the distance map from the mask position to the nearest unmasked position;
[0022] The four feature maps containing direction information and the distance map are superimposed through Fourier mask to generate a mask position map.
[0023] Furthermore, the diffusion network includes a diffusion encoder, a Unet network based on a nested attention mechanism, and a diffusion decoder; the Unet network based on the nested attention mechanism includes a downsampling part, an intermediate part, and an upsampling part;
[0024] The mask position map and the original image after mask processing are spliced to obtain a mask feature map; the mask feature map is processed by a diffusion encoder, a pre-trained Unet network based on a nested attention mechanism, and a diffusion decoder in sequence. During the processing, it is necessary to introduce text descriptions to participate in the nested attention mechanism, and to introduce contour maps to participate in the middle part and upsampling part of the Unet network based on the nested attention mechanism, as well as the calculation of the diffusion decoder.
[0025] Furthermore, when the contour map is calculated in the diffusion network, the downsampling part of the pre-trained Unet network based on the nested attention mechanism is copied as a replica model. In the replica model, the contour map is used as input to generate a downsampling result, which is then input into the middle part of the Unet network based on the nested attention mechanism that is being trained, and is spliced with the output result of the upsampling part of the Unet network based on the nested attention mechanism that is being trained, and subsequent processing is performed together.
[0026] Furthermore, the nested attention mechanism calculation process includes:
[0027] Take the mask feature map as the input tensor and convert it into the query tensor Q through the projection layer. m , key tensor K m Sum value tensor V m , by computing the query tensor Q m With key tensor K mThe dot product of the transpose of and divided by Get the self-attention similarity matrix S of the mask feature map self Similarly, the text description is processed into text embedding, and the text embedding is used as the input tensor to generate the self-attention similarity matrix S of the text description text ;
[0028] According to the self-attention similarity matrix S text Calculate the similarity score Atext = SoftMax(Stext), for the moderately expanded mask map For each pixel j in A, calculate its text The alignment score t in j , the alignment score t for all pixels j Normalize, for pixel i in the unknown area and pixel j in the known area, cyclically update the original matrix:
[0029]
[0030] The updated similarity matrix Apply the Softmax function and compare it with the value tensor V m Multiply, and then add it to the mask feature map as the input tensor X to get the final output
[0031] In a second aspect, the present invention proposes a sketch image restoration and editing system based on a diffusion network, comprising:
[0032] A data acquisition module, which is used to acquire sketches, text description data and original images to be edited;
[0033] A sketch enhancement network module, which is used to generate a contour map corresponding to the sketch using the sketch enhancement network;
[0034] A mask dilation module, which is used to generate a moderately dilated mask image using the mask dilation module according to the contour image and the text description;
[0035] A mask position module, which is used to generate a mask position map and a masked original image using the mask position module according to the moderately expanded mask map and the original image to be edited;
[0036] The diffusion network module is used to generate an edited original image using a diffusion network according to the contour map, the mask position map, the masked original image and the text description.
[0037] Beneficial effects of the present invention: The method of the present invention also shows excellent performance in terms of visual quality and consistency of generated content. By incorporating the dual mechanisms of sketch guidance and mask expansion, the method of the present invention can generate restoration results that are highly coordinated and naturally integrated with the surrounding environment. The generated content maintains good consistency with the original image in terms of texture, color, and lighting, and looks like part of the image itself, rather than rigidly filling in blank areas. This high level of visual quality and consistency makes our method have a wider range of application prospects in real scenes and can meet users' needs for high-quality image restoration. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the network structure and the training and forward reasoning process in the embodiment of the present invention, the following briefly introduces the drawings required for use in the embodiment:
[0039] Figure 1 Schematic diagram of the framework of the sketch image inpainting editing method based on diffusion network.
[0040] Figure 2 This is a schematic diagram of the mask expansion module;
[0041] Figure 3 Effect diagram of the sketch enhancement network implementation.
[0042] Figure 4 This is the effect diagram of the mask expansion module.
[0043] Figure 5 This is a schematic diagram of the mask position module;
[0044] Figure 6 Schematic diagram of the nested attention mechanism;
[0045] Figure 7 This is a comparison chart of the image restoration editing effects generated by the present invention and other methods. DETAILED DESCRIPTION
[0046] In order to describe the present invention more specifically, the technical solution of the present invention is described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0047] The accompanying drawings are only schematic illustrations of the present invention and are not necessarily drawn to scale. Some of the block diagrams shown in the accompanying drawings are functional entities that do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0048] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the steps. For example, some steps may be decomposed, while some steps may be combined or partially combined, so the actual execution order may change according to the actual situation.
[0049] like Figure 1 As shown, the sketch image restoration and editing method based on diffusion network proposed in the present invention mainly includes the following steps:
[0050] Step 1: Get sketch and text description data.
[0051] In this step, the sketch refers to a simple image drawn by a user using lines at a location of an object that the user wants to edit on the original image, and the text description refers to descriptive text of the sketch, that is, the characteristics of the image that the user expects to be generated.
[0052] Step 2: Use the sketch enhancement network to generate a contour map corresponding to the sketch.
[0053] In a specific implementation of the present invention, the sketch enhancement network includes a fusion module and an enhancement module, and the two modules are introduced below respectively.
[0054] (1) Fusion Module
[0055] A random function is used to randomly delete some strokes from the sketch to obtain a rough sketch.
[0056] The original sketch is considered as a refined sketch, represented as in represents the stroke at the tth time step in the original sketch, T qd is the number of strokes in the original sketch. The rough sketch is obtained by randomly deleting some strokes in the original sketch. in represents the stroke at the tth time step in the rough sketch, is the number of strokes in the rough sketch.
[0057] The fusion module adopts a codec structure, in which the fusion encoder converts the rough sketch Convert to vector representation z qd , the fusion decoder is based on z qd Generate predictions for refined sketches By minimizing the fusion loss Update the parameters of the fusion encoder and the fusion decoder. The fusion encoder and the fusion decoder are specifically selected by those skilled in the art according to the needs, and the present invention does not limit them.
[0058] Therefore, the goal of the fusion module is to learn how to transform the rough sketch into a fine sketch. The pixel loss function of the fusion module at this stage is:
[0059]
[0060] in, is the predicted output of the decoder at time step t, is the t-th stroke in the original sketch of the training set, |.| 1 is the L1 norm.
[0061] (2) Enhancement module
[0062] The Canny edge contour detection algorithm is used to extract the contour of the original sketch and obtain the true contour set E t .
[0063] Similar to the fusion module, the predicted fine sketch is input into the enhancement module to generate the contour map of the sketch and obtain the generated contour set S e Specifically, the enhancement module adopts a codec structure, wherein the enhancement encoder converts the fine sketch into a vector representation, and the enhancement decoder generates a contour prediction based on the encoded vector representation. Update the parameters of the enhanced encoder and the enhanced decoder. The enhanced encoder and the enhanced decoder are specifically selected by those skilled in the art according to the needs, and the present invention does not limit them.
[0064] Therefore, the goal of the enhancement module is to learn how to transform the fine sketch into a contour map. The pixel loss function of the enhancement module at this stage is:
[0065]
[0066] Among them, Ω represents the pixel set obtained by dividing the contour map into pixel layers, p i Represents a pixel, Represents the value of the pixel point in the true contour set, Represents the value of the pixel point in the pixel set corresponding to the generated contour set.
[0067] The effect diagram of the sketch enhancement network is as follows Figure 3 shown.
[0068] Step 3: Based on the contour image and text description, a mask dilation module is used to generate a moderately dilated mask image.
[0069] like Figure 2As shown, the mask expansion module adopts a mask expansion prediction method based on text prompt words, and is composed of a mask expansion encoder and a mask expansion decoder. The mask expansion encoder takes the initial mask map and text description corresponding to the contour map as input to generate an expanded mask feature. The mask expansion decoder takes the expanded mask feature, mask map, and expansion kernel size as input to generate an expanded mask map. In the decoding process of the mask expansion decoder, a step-by-step decoding method is adopted. At each step of decoding, the current step expanded mask map is generated according to the current step element in the expanded mask feature and the latest mask map, and all elements in the expanded mask feature are traversed, and the final mask map is used as a moderately expanded mask map. Here, the expansion kernel size is a hyperparameter and can be set manually.
[0070] In a specific implementation of the present invention, the first step is the encoding process: the contour image and the text description are processed, and a mask is extracted from the contour image as an initial mask image m 0 , the text description is represented by channel conversion to obtain the text alignment vector The mask dilation encoder is used to extract the initial mask image m 0 Align the text vector The weighted result of the two embedded representations is taken as the expanded mask feature τ θ In this embodiment, the mask expansion encoder uses a pre-trained CLIP text encoder, and those skilled in the art may also select other types of encoders as needed.
[0071] The second is the decoding process. This embodiment sets the range of the expansion iteration number [it min ,it max ] and pass the current element in the dilated mask feature to the mask dilator in each iteration Mask Expander With the current mask m i , the dilation kernel size k and the current element τ' in the dilation mask feature θi As input, generate the expanded mask m i+1 , expressed as After traversing all elements in the expansion mask feature, the final moderate expansion mask map is obtained In this embodiment, the mask expansion decoder can be selected by those skilled in the art as needed.
[0072] The effect diagram of the mask expansion module is as follows: Figure 4 shown.
[0073] Step 4: Based on the moderately expanded mask image and the original image to be edited, a mask position module is used to generate a mask position map and a masked original image.
[0074] like Figure 5As shown, the mask position module first processes the moderately expanded mask image with four convolution kernels in different directions to generate four feature maps containing directional information; in addition, the moderately expanded mask image is subjected to 3*3 convolution processing to obtain a distance map from the mask position to the nearest unmasked position. The four feature maps containing directional information and the distance map are superimposed through a Fourier mask to generate a mask position map. The Fourier mask is a prior art in the art and will not be described in detail.
[0075] The original image to be edited is processed by using a moderately dilated mask image to generate a masked original image, in which the area to be edited is cleared or noise is generated.
[0076] Step 5, generating the edited original image using a diffusion network according to the contour image, the mask position image, the masked original image and the text description, wherein the number of diffusion steps of the diffusion network is a hyperparameter and can be set manually.
[0077] In a specific implementation of the invention, the diffusion network includes a diffusion encoder, a Unet network based on a nested attention mechanism, and a diffusion decoder. The Unet network based on the nested attention mechanism includes a downsampling part, an intermediate part, and an upsampling part. The Unet network based on the nested attention mechanism is obtained by introducing a cross attention mechanism on the basis of an existing Unet network based on a self-attention mechanism.
[0078] The mask position map and the original image after mask processing are spliced to obtain the mask feature map; the mask feature map is processed by diffusion encoder, pre-trained Unet network based on nested attention mechanism, and diffusion decoder in sequence. Text description needs to be introduced in the processing process. Figure 6 As shown, the calculation process of the nested attention mechanism is as follows:
[0079] Takes mask feature map as input tensor Where h and w represent the height and width of the mask feature map, respectively, and d represents the feature dimension. The input tensor X is converted to the query tensor Q through the projection layer. m , key tensor K m Sum value tensor V m , whose dimensions are Next, we calculate the query tensor Q m With key tensor K m The dot product of the transpose of and divided by Make its distribution smoother, avoid saturation of the output of the Softmax function, and obtain the self-attention similarity matrix of the mask feature map Similarly, the text description is processed into text embedding, and the text embedding is used as the input tensor to generate the self-attention similarity matrix S of the text description text .
[0080] According to the self-attention similarity matrix S text Calculate the similarity score A text =SoftMax(S text ), for moderately dilated mask images For each pixel j in A, calculate its text The alignment score t in j , the alignment score t for all pixels j Normalize, for pixel i in the unknown area and pixel j in the known area, cyclically update the original matrix:
[0081]
[0082] The updated similarity matrix Apply the Softmax function and compare it with the value tensor V m Multiply and add to the input tensor X to get the final output
[0083] By nesting cross attention in the self-attention mechanism, the attention weight of known pixels on the repaired area can be dynamically adjusted to reduce the excessive influence of the background and nearby objects. At the same time, the nested cross attention enhances the guiding role of text descriptions in the repair process, enabling the model to better capture the semantic relationship between pixels and text descriptions, which helps to generate more comprehensive and accurate repair results.
[0084] In addition, the contour map also needs to introduce the Unet network based on the nested attention mechanism to help generate the edited original image. Here, the contour map copies the down-sampling part of the pre-trained Unet network based on the nested attention mechanism as a replica model. In the replica model, the contour map is used as input to generate the down-sampling result, and then the down-sampling result is input to the middle part of the Unet network based on the nested attention mechanism in the training process, and spliced with the output result of the up-sampling part of the Unet network based on the nested attention mechanism in the training process, and then processed together.
[0085] Calculate diffusion losses:
[0086]
[0087] Among them, ∈ represents the noise that follows Gaussian distribution, ∈ θ represents the diffusion network, x t represents the input mask feature map, t represents the number of diffusion steps, c represents the text description, s represents the contour map, Represents the square of the L2 norm.
[0088] Step 6: Combine the sketch enhancement network loss and the diffusion network loss to train the sketch enhancement network, mask expansion module, mask location module and diffusion network.
[0089]
[0090]
[0091] Among them, λ 1 , 2 is the weight coefficient, Enhance the network loss for the sketch, To diffuse the network loss, is the total loss,
[0092] Step 7: Use the trained model to implement sketch repair editing.
[0093] Specifically, the user draws a sketch of the editing object at the target position of the original image and provides a text description, uses the sketch enhancement network to obtain the contour map of the sketch, uses the mask expansion module to generate a moderately expanded mask map based on the contour map and the text description, uses the mask position module to generate a mask position map and the masked original image based on the moderately expanded mask map and the original image to be edited, and uses the diffusion network to generate the edited original image based on the contour map, the mask position map, the masked original image and the text description.
[0094] The experimental results are as follows Figure 7 As shown, the present invention shows excellent performance in terms of visual quality and consistency of generated content. By incorporating the dual mechanisms of sketch guidance and mask expansion, the present invention is able to generate restoration results that are highly coordinated and naturally integrated with the surrounding environment. The generated content maintains good consistency with the original image in terms of texture, color, and lighting, and looks like part of the image itself, rather than rigidly filling in blank areas. The generated object contours are basically consistent with the input sketch, accurately capturing the shape and structural features of the object, showing the powerful effect of sketch guidance.
[0095] In this embodiment, a sketch image restoration and editing system based on a diffusion network is also provided, which is used to implement the above embodiment. The terms "module", "unit", etc. used below can implement a combination of software and / or hardware for a predetermined function. Although the system described in the following embodiments is preferably implemented in software, it is also possible to implement hardware, or a combination of software and hardware.
[0096] This embodiment provides a sketch image restoration and editing system based on a diffusion network, comprising:
[0097] A data acquisition module, which is used to acquire sketches, text description data and original images to be edited;
[0098] A sketch enhancement network module, which is used to generate a contour map corresponding to the sketch using the sketch enhancement network;
[0099] A mask dilation module, which is used to generate a moderately dilated mask image using the mask dilation module according to the contour image and the text description;
[0100] A mask position module, which is used to generate a mask position map and a masked original image using the mask position module according to the moderately expanded mask map and the original image to be edited;
[0101] The diffusion network module is used to generate an edited original image using a diffusion network according to the contour map, the mask position map, the masked original image and the text description.
[0102] For the system embodiment, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment, and the implementation methods of the remaining modules will not be repeated here. The system embodiment described above is only schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of the present invention. Ordinary technicians in this field can understand and implement it without paying creative work.
[0103] The embodiments of the system of the present invention can be applied to any device with data processing capabilities, and the device with data processing capabilities can be a device or apparatus such as a computer. The system embodiments can be implemented by software, or by hardware or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, the corresponding computer program instructions in the non-volatile memory are read into the memory by the processor of any device with data processing capabilities and run.
[0104] Obviously, the above-described embodiments and drawings are only some examples of the present application. For those of ordinary skill in the art, the present application can also be applied to other similar situations based on these drawings without creative work. In addition, it is understandable that, although the work done in this development process may be complicated and lengthy, for those of ordinary skill in the art, certain changes in design, manufacturing or production based on the technical content disclosed in this application are only conventional technical means and should not be regarded as insufficient content disclosed in this application. Without departing from the concept of the present application, several variations and improvements can also be made, which all belong to the scope of protection of the present application. Therefore, the scope of protection of the present application shall be subject to the attached claims.
Claims
1. A sketch image inpainting and editing method based on diffusion network, characterized in that: The following steps are involved: Get the sketch, text description data and the original image to be edited; Generate a contour map corresponding to the sketch using a sketch enhancement network; According to the contour map and text description, a mask dilation module is used to generate a moderately dilated mask map; According to the moderately expanded mask image and the original image to be edited, a mask position map and the masked original image are generated using a mask position module; According to the contour map, the mask position map, the masked original image and the text description, a diffusion network is used to generate the edited original image.
2. The sketch image restoration and editing method based on diffusion network according to claim 1 is characterized in that: The sketch enhancement network includes a fusion module and an enhancement module based on a codec structure. The fusion module takes the sketch as input to generate a refined sketch, and the enhancement module takes the refined sketch as input to generate a contour map.
3. The sketch image restoration and editing method based on diffusion network according to claim 2 is characterized in that: The training process of the sketch enhancement network includes: Randomly delete some strokes from the original sketch, regard the original sketch as a fine sketch, and regard the sketch after deleting the strokes as a rough sketch. The training goal of the fusion module is to convert the rough sketch into a fine sketch. The contour of the original sketch is extracted as a label, and the training objective of the enhancement module is to convert the refined sketch into a contour map.
4. The sketch image restoration and editing method based on diffusion network according to claim 1 is characterized in that: The mask dilation module includes a mask dilation encoder and a mask dilation decoder. The mask dilation encoder takes the initial mask image and text description corresponding to the contour image as input to generate dilated mask features. The mask dilation decoder takes the dilated mask features, the mask image, and the dilation kernel size as input to generate the dilated mask image.
5. The sketch image restoration and editing method based on diffusion network according to claim 4 is characterized in that: In the decoding process of the mask expansion decoder, a step-by-step decoding method is adopted. At each decoding step, the mask map after the current step expansion is generated according to the current step element in the expansion mask feature and the latest mask map. All elements in the expansion mask feature are traversed, and the final mask map is used as the moderate expansion mask map.
6. The sketch image restoration and editing method based on diffusion network according to claim 1 is characterized in that: The mask position module is specifically: The moderately expanded mask image is processed with four convolution kernels in different directions to generate four feature maps containing directional information; The moderately expanded mask image is subjected to 3*3 convolution processing to obtain a distance map from the mask position to the nearest unmasked position; the four feature maps containing directional information and the distance map are superimposed through Fourier masking to generate a mask position map.
7. The sketch image restoration and editing method based on diffusion network according to claim 1 is characterized in that: The diffusion network includes a diffusion encoder, a Unet network based on a nested attention mechanism, and a diffusion decoder; the Unet network based on the nested attention mechanism includes a downsampling part, an intermediate part, and an upsampling part; The mask position map and the original image after mask processing are spliced to obtain a mask feature map; the mask feature map is processed by a diffusion encoder, a pre-trained Unet network based on a nested attention mechanism, and a diffusion decoder in sequence. During the processing, it is necessary to introduce text descriptions to participate in the nested attention mechanism, and to introduce contour maps to participate in the middle part and upsampling part of the Unet network based on the nested attention mechanism, as well as the calculation of the diffusion decoder.
8. The sketch image restoration and editing method based on diffusion network according to claim 7 is characterized in that: When the contour map is calculated in the diffusion network, the downsampling part of the pre-trained Unet network based on the nested attention mechanism is copied as a replica model. In the replica model, the contour map is used as input to generate a downsampling result, and then the downsampling result is input into the middle part of the Unet network based on the nested attention mechanism in the training process, and spliced with the output result of the upsampling part of the Unet network based on the nested attention mechanism in the training process, and subsequent processing is performed together.
9. The sketch image restoration and editing method based on diffusion network according to claim 7 is characterized in that: The nested attention mechanism calculation process includes: Take the mask feature map as the input tensor and convert it into the query tensor Q through the projection layer. m , key tensor K m Sum value tensor V m , by computing the query tensor Q m With key tensor K m The dot product of the transpose of and divided by Get the self-attention similarity matrix S of the mask feature map self Similarly, the text description is processed into text embedding, and the text embedding is used as the input tensor to generate the self-attention similarity matrix S of the text description text ; According to the self-attention similarity matrix S text Calculate the similarity score Atext = SoftMax(Stext), for the moderately expanded mask map For each pixel j in A, calculate its text The alignment score t in j , the alignment score t for all pixels j Normalize, for pixel i in the unknown area and pixel j in the known area, cyclically update the original matrix: The updated similarity matrix Apply the Softmax function and compare it with the value tensor V m Multiply, and then add it to the mask feature map as the input tensor X to get the final output 10. A sketch image restoration and editing system based on diffusion network, characterized in that: include: A data acquisition module, which is used to acquire sketches, text description data and original images to be edited; A sketch enhancement network module, which is used to generate a contour map corresponding to the sketch using the sketch enhancement network; A mask dilation module, which is used to generate a moderately dilated mask image using the mask dilation module according to the contour image and the text description; A mask position module, which is used to generate a mask position map and a masked original image using the mask position module according to the moderately expanded mask map and the original image to be edited; The diffusion network module is used to generate an edited original image using a diffusion network according to the contour map, the mask position map, the masked original image and the text description.
Citation Information
Patent Citations
Power transformation place suspender recognition method based on enhanced image comparison
CN111080562A
Pipeline contour detection method based on full convolutional neural network
CN111862042A
Image target pertinence enhancement method and device, equipment and storage medium
CN113409224A
Single-image rain removal method and system based on deep convolutional neural network, and storage medium
CN113450288A
Face image restoration method based on contour and semantic guidance
CN114862696A
Cited By
Landscape design system based on artificial intelligence man-machine interaction
CN120543759A
Landscape design system based on artificial intelligence human-computer interaction
CN120543759B
Cultural relic virtual restoration method and device, equipment and storage medium
CN120580172A
Sketch retrieval three-dimensional model method and system based on cross-modal class center alignment
CN120632135A
