A sketch image inpainting editing method and system based on diffusion network
By employing a diffusion network-based approach, combined with sketch enhancement networks and nested attention mechanisms, this study addresses the challenges of obtaining precise masks and insufficient contextual understanding in existing image inpainting techniques, generating high-quality inpainting results that are highly coordinated with the surrounding environment.
Patent Information
- Application Number
- CN202410637667.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-22
- Publication Date
- 2026-11-27
- Estimated Expiration
- 2044-05-22
AI Technical Summary
Existing image restoration techniques still face challenges in generating high-quality, realistic images, particularly in issues such as difficulty in obtaining accurate mask information, time-consuming manual selection of restoration areas by users, insufficient contextual understanding, and unnatural edge blending.
By employing a diffusion network-based approach, the association between text and sketches is learned, generating a moderately inflated mask image. Utilizing a nested attention mechanism, combined with a sketch enhancement network and a diffusion network, realistic restoration results are generated, enhancing the semantic consistency and spatial alignment of the restored region with its context.
The generated restoration results are highly coordinated with the surrounding environment, blending naturally, and the texture, color, and lighting are consistent with the original image, achieving high-quality image restoration results.
Smart Images

Figure CN118587124B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of diffusion network image restoration in computer graphics, specifically relating to an image restoration and editing method and system based on diffusion networks. Background Technology
[0002] In the field of image inpainting, scientists initially relied mainly on rule-based methods such as interpolation, but these methods suffered significant losses when inpainting complex images. Later, with the rise of deep learning technology, image inpainting made great progress in generative inpainting and fusion effects.
[0003] Deng et al. proposed an efficient Transformer-based method that introduces a hierarchical encoder and a self-attention module to find the application of self-attention mechanisms at each scale, establishing long-range dependencies between features, and uses gated convolution to improve the model's expressive power and efficiency. However, this method still relies on accurate mask information, which may be challenging in practical applications. Dong et al. proposed an incremental image inpainting structure that generates high-quality inpainting results by progressively refining features. In terms of mask acquisition, they designed a dynamic attention mask that adaptively adjusts attention weights according to the current inpainting state, enabling the model to focus more on features relevant to the inpainting. Furthermore, they employed a multi-head attention mechanism in the decoder to capture long-range feature dependencies. However, this method still focuses on image-level feature representation and inpainting, and semantic-level image understanding and editing remain to be addressed. Ni et al. proposed a language-guided image inpainting algorithm that uses textual descriptions to guide the image inpainting process, generating high-quality inpainting results that conform to the description. They introduced a flawless vector quantization generative adversarial network as the generative model for image inpainting. However, this method lacks sufficient understanding of contextual pixels. Although it can generate semantically consistent objects, artifacts and unnatural fusion inevitably occur during edge blending. Yu et al. proposed a multi-scale inpainting strategy and attention mechanism, enabling the inpainting model to better understand and utilize the contextual information of the image, and achieved excellent performance results on the diffusion network. However, users need to manually select the target region to be inpainted, which may be time-consuming when processing complex subject images.
[0004] In the field of image restoration, there are still many challenges in generating high-quality, realistic images. Summary of the Invention
[0005] To address the shortcomings of existing technologies, this invention proposes a sketch image restoration and editing method and system based on diffusion networks. By learning the relationship between text and sketches, the ideal restoration area is predicted. By modeling long-range dependencies between local and global data, the semantic consistency and spatial alignment between the restoration area and the context are enhanced, resulting in more realistic and natural restoration results.
[0006] The technical solution adopted by this invention to solve the technical problem is as follows:
[0007] In a first aspect, the present invention proposes a sketch image restoration and editing method based on diffusion networks, comprising the following steps:
[0008] Retrieve the sketch, text description data, and the original image to be edited;
[0009] Use a sketch enhancement network to generate a contour map corresponding to the sketch;
[0010] Based on the contour map and text description, a moderately inflated mask map is generated using the mask inflation module;
[0011] Based on the moderately inflated mask image and the original image to be edited, the mask position module is used to generate a mask position image and the original image after masking.
[0012] Based on the outline map, mask location map, original image after masking, and 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 an encoder-decoder structure. The fusion module takes the sketch as input to generate a fine sketch, and the enhancement module takes the fine sketch as input to generate a contour map.
[0014] Furthermore, the training process of the sketch augmentation network includes:
[0015] The original sketch is randomly deleting some strokes, and the original sketch is regarded as a fine sketch. The sketch after deleting strokes is regarded as a rough sketch. The training objective of the fusion module is to convert the rough sketch into a fine sketch.
[0016] The outline of the original sketch is extracted as a label, and the training objective of the augmentation module is to convert the detailed sketch into an outline map.
[0017] Furthermore, the mask inflation module includes a mask inflation encoder and a mask inflation decoder. The mask inflation encoder takes the initial mask image corresponding to the contour image and the text description as input to generate inflation mask features. The mask inflation decoder takes the inflation mask features, the mask image, and the inflation kernel size as input to generate the inflation 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 current step expanded mask image is generated based on the current step element in the expanded mask feature and the latest mask image. All elements in the expanded mask feature are traversed, and the final mask image is used as the moderately expanded mask image.
[0019] Furthermore, the mask location module specifically comprises:
[0020] The moderately inflated mask image is processed by convolutional kernels in four different directions to generate four feature maps containing directional information;
[0021] Perform a 3x3 convolution on the moderately dilated mask image to obtain a distance map from the mask position to the nearest unmasked position;
[0022] Fourier masks are used to overlay four feature maps and distance maps containing orientation information to generate a mask location 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 a nested attention mechanism includes a downsampling part, an intermediate part, and an upsampling part.
[0024] The mask location map and the original image after masking are concatenated to obtain the mask feature map. The mask feature map is then processed sequentially by a diffusion encoder, a pre-trained Unet network based on a nested attention mechanism, and a diffusion decoder. During the processing, text descriptions are introduced to participate in the nested attention mechanism, and contour maps are introduced to participate in the middle and upsampling parts 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 computed 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. This downsampling result is then concatenated with the output of the upsampling part of the Unet network based on the nested attention mechanism that is being trained, and then processed together.
[0026] Furthermore, the nested attention mechanism calculation process includes:
[0027] Using the mask feature map as the input tensor, the input tensor is transformed into a query tensor Q through a projection layer. m Key tensor K m Sum tensor V m By calculating the query tensor Q m With key tensor K mThe dot product of the transpose of and divided by The self-attention similarity matrix S of the mask feature map is obtained. self Similarly, the text description is processed into a 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] Based on the self-attention similarity matrix S text Calculate the similarity score Atext = SoftMax(Stext) for a moderately inflated mask image. For each pixel j in A, calculate its position in A. text Alignment fraction t in j Alignment score t for all pixels j Normalization is performed, and for pixel i in the unknown region and pixel j in the known region, the original matrix is updated iteratively:
[0029]
[0030] For the updated similarity matrix Apply the Softmax function and compare it with the value tensor V m Multiply the results, then add them to the mask feature map as the input tensor X to obtain the final output.
[0031] Secondly, this invention proposes a sketch image restoration and editing system based on a diffusion network, comprising:
[0032] The data acquisition module is used to acquire sketches, text description data, and the original image to be edited;
[0033] The sketch enhancement network module is used to generate a contour map corresponding to the sketch using the sketch enhancement network;
[0034] The mask inflation module is used to generate an appropriately inflated mask image based on the contour map and text description.
[0035] The mask location module is used to generate a mask location map and the original image after masking, based on a moderately inflated mask map and the original image to be edited.
[0036] The diffusion network module is used to generate an edited original image based on the contour map, mask position map, original image after masking, and text description using a diffusion network.
[0037] The beneficial effects of this invention are as follows: The method of this invention also demonstrates superior performance in terms of the visual quality and consistency of the generated content. By incorporating a dual mechanism of sketch guidance and mask expansion, the method of this invention can generate restoration results that are highly coordinated and naturally integrated with the surrounding environment. The generated content maintains excellent consistency with the original image in terms of texture, color, and lighting, appearing as if it were part of the image itself, rather than awkwardly filling in blank areas. This high level of visual quality and consistency makes our method have broader application prospects in real-world scenarios, meeting users' needs for high-quality image restoration. Attached Figure Description
[0038] To more clearly illustrate the network structure and training and forward inference processes in the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly described below:
[0039] Figure 1 This is a schematic diagram of the framework for a sketch image restoration and editing method based on diffusion networks.
[0040] Figure 2 This is a schematic diagram of the mask expansion module;
[0041] Figure 3 The effect of enhancing the network on the sketch.
[0042] Figure 4 This is a diagram showing the effect of the mask expansion module.
[0043] Figure 5 This is a schematic diagram of the mask position module;
[0044] Figure 6 This is a schematic diagram of a nested attention mechanism;
[0045] Figure 7 This is a comparison image showing the image restoration and editing effects generated by this invention and other methods. Detailed Implementation
[0046] To describe the present invention in more detail, the technical solution of the present invention will be described in detail below with reference to the accompanying drawings and specific embodiments.
[0047] The accompanying drawings are merely illustrative of the invention and are not necessarily drawn to scale. Some of the block diagrams shown in the drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.
[0048] The flowchart shown in the attached diagram is merely an illustrative example and does not necessarily include all steps. For example, some steps may be broken down, while others may be combined or partially combined; therefore, the actual execution order may change depending on the specific circumstances.
[0049] like Figure 1 As shown, the sketch image restoration and editing method based on diffusion networks proposed in this invention mainly includes the following steps:
[0050] Step 1: Obtain sketch and text description data.
[0051] In this step, a sketch refers to a simple image drawn by the user on the original image using lines to outline the location of an object that they want to edit. The text description refers to the descriptive text of the sketch, that is, the characteristics that the user expects the generated image to have.
[0052] Step 2: Use the sketch augmentation network to generate the outline map corresponding to the sketch.
[0053] In one specific embodiment of the present invention, the sketch enhancement network includes a fusion module and an enhancement module, which are described below.
[0054] (1) Fusion Module
[0055] A rough sketch is obtained by randomly deleting some strokes from the sketch using a random function.
[0056] Treating the original sketch as a detailed sketch, represented as in T represents the stroke at time step t in the original sketch. qd This refers to the number of strokes in the original sketch. A rough sketch is obtained by randomly deleting some strokes from the original sketch. in This represents the stroke at time step t in the rough sketch. It represents the number of strokes in a rough sketch.
[0057] The fusion module employs an encoder-decoder structure, wherein the fusion encoder converts the rough sketch... Transform into vector representation z qd The fusion decoder is based on z qd Prediction of generating detailed sketches By minimizing fusion loss Update the parameters of the fusion encoder and fusion decoder. The specific fusion encoder and fusion decoder can be selected by those skilled in the art as needed, and this invention does not limit their selection.
[0058] Therefore, the goal of the fusion module is to learn how to transform a rough sketch into a fine sketch. The pixel loss function of the fusion module at this stage is:
[0059]
[0060] in, It is the decoder's predicted output at time step t. Let |t| be the t-th stroke in the original sketch of the training set, and |.|1 be the L1 norm.
[0061] (2) Enhancement Module
[0062] The Canny edge contour detection algorithm is used to extract the contour map of the original sketch, resulting in 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 sketch's outline, resulting in a set of generated outlines S. e Specifically, the enhancement module employs an encoder-decoder structure, where 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. This is achieved by minimizing the fusion loss. Update the parameters of the enhancement encoder and enhancement decoder. The specific enhancement encoder and enhancement decoder can be selected by those skilled in the art as needed, and this invention does not impose any limitations.
[0064] Therefore, the goal of the enhancement module is to learn how to convert a detailed sketch into a contour map. The pixel loss function of the enhancement module at this stage is:
[0065]
[0066] Where Ω represents the set of pixels obtained by dividing the contour map according to pixel layers, p i Represents pixels, This represents the value of a pixel in the set of true contours. This represents the value of a pixel in the pixel set corresponding to the generated contour set.
[0067] The effect of implementing the sketch augmentation network is shown in the figure below. Figure 3 As shown.
[0068] Step 3: Based on the contour map and text description, generate a moderately inflated mask map using the mask inflation module.
[0069] like Figure 2As shown, the mask inflation module employs a text-based prompt word-based mask inflation prediction method, consisting of a mask inflation encoder and a mask inflation decoder. The encoder takes an initial mask image corresponding to the contour map and a text description as input to generate inflation mask features. The decoder takes the inflation mask features, the mask image, and the inflation kernel size as input to generate the inflation mask image. During the decoding process, a step-by-step decoding approach is used. At each step, the current-step inflation mask image is generated based on the current-step elements in the inflation mask features and the latest mask image. All elements in the inflation mask features are traversed, and the final mask image is used as the appropriately inflation mask image. Here, the inflation kernel size is a hyperparameter that can be manually set.
[0070] In one specific embodiment of the present invention, the first step is the encoding process: processing the contour map and the text description, extracting a mask from the contour map as the initial mask map m0, and representing the text description through channel conversion to obtain the text alignment vector. The initial mask image m0 and the text alignment vector are extracted using a mask dilation encoder. The embedding representation is used, and the weighted sum of the two embedding representations is taken as the dilated mask feature τ. θ In this embodiment, the mask expansion encoder uses a pre-trained CLIP text encoder, but other types of encoders can be selected by those skilled in the art as needed.
[0071] Secondly, regarding the decoding process, this embodiment sets the range of the number of dilation iterations [it] min ,it max In each iteration, the current element of the expanded mask feature is passed to the mask expander. Mask Inflator With the current mask m i The size of the expansion kernel k and the current element τ' in the expansion mask features. θi As input, generate the dilated mask m. i+1 , represented as After traversing all elements in the dilated mask features, the final moderately dilated mask image is obtained. In this embodiment, the mask expansion decoder can be selected by those skilled in the art as needed.
[0072] The effect of the mask expansion module is shown in the figure below. Figure 4 As shown.
[0073] Step 4: Based on the moderately inflated mask image and the original image to be edited, use the mask position module to generate a mask position image and the original image after masking.
[0074] like Figure 5As shown, the mask location module first processes the moderately dilated mask image using convolutional kernels in four different directions to generate four feature maps containing directional information. Furthermore, it performs a 3x3 convolution on the moderately dilated mask image to obtain a distance map from the mask location to the nearest unmasked location. The four feature maps containing directional information and the distance maps are then superimposed using a Fourier mask to generate the mask location map. The Fourier mask is existing technology in this field and will not be described in detail further.
[0075] The original image to be edited will be processed using a moderately inflated mask image to generate a masked original image. In the generated masked original image, the area to be edited will be zeroed out or noise will be generated.
[0076] Step 5: Based on the contour map, mask position map, original image after masking, and text description, generate the edited original image using a diffusion network. The diffusion step number of the diffusion network is a hyperparameter that can be set manually.
[0077] In one specific embodiment 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 into an existing Unet network based on a self-attention mechanism.
[0078] The mask location map and the original image after masking are concatenated to obtain the mask feature map. This mask feature map is then processed sequentially by a diffusion encoder, a pre-trained UNet network based on a nested attention mechanism, and a diffusion decoder. Text descriptions are introduced during this process. For example... Figure 6 As shown, the calculation process of the nested attention mechanism is as follows:
[0079] Using the mask feature map as the 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 transformed into the query tensor Q through a projection layer. m Key tensor K m Sum tensor V m All of their dimensions are Next, the query tensor Q is calculated. m With key tensor K m The dot product of the transpose of and divided by This makes the distribution smoother, avoiding output saturation of the Softmax function, and yields the self-attention similarity matrix of the mask feature map. Similarly, the text description is processed into a 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] Based on the self-attention similarity matrix S text Calculate similarity score A text =SoftMax(S text For moderately inflated mask images For each pixel j in A, calculate its position in A. text Alignment fraction t in j Alignment score t for all pixels j Normalization is performed by iteratively updating the original matrix for pixel i in the unknown region and pixel j in the known region:
[0081]
[0082] For the updated similarity matrix Apply the Softmax function and compare it with the value tensor V m Multiply by the input tensor X, then add to the input tensor X to obtain the final output.
[0083] By nesting cross-attention within the self-attention mechanism, the attention weights of known pixels on the repaired region can be dynamically adjusted, reducing the excessive influence of the background and nearby objects. Simultaneously, the nested cross-attention enhances the guiding role of text descriptions in the repair process, enabling the model to better capture the semantic relationships between pixels and text descriptions, thus contributing to more comprehensive and accurate repair results.
[0084] Furthermore, the contour map also needs to incorporate a Unet network based on a nested attention mechanism to help generate the edited original image. Here, the contour map copies the downsampled part of the pre-trained Unet network based on a nested attention mechanism as a replica model. In the replica model, the contour map is used as input to generate a downsampled result, which is then input into the middle part of the Unet network based on a nested attention mechanism that is currently being trained. This downsampled result is then concatenated with the output of the upsampled part of the Unet network based on a nested attention mechanism that is currently being trained for subsequent processing.
[0085] Calculate diffusion loss:
[0086]
[0087] Where ∈ represents noise that follows a Gaussian distribution, ∈ θ Represents a diffusion network, x t Let represent the input mask feature map, t represent the diffusion step number, c represent the text description, and s represent the contour map. This represents the square of the L2 norm.
[0088] Step 6: Combine the sketch augmentation network loss and the diffusion network loss to train the sketch augmentation network, mask dilation module, mask location module, and diffusion network.
[0089]
[0090]
[0091] Where λ1 and λ2 are weighting coefficients, To enhance network loss in the sketch, To mitigate network losses, For the total loss,
[0092] Step 7: Use the trained model to perform sketch repair and editing.
[0093] Specifically, the user draws a sketch of the object to be edited at the target location in the original image and provides a text description. The sketch augmentation network is used to obtain the outline of the sketch. Based on the outline and text description, the mask dilation module generates a moderately dilated mask. Based on the moderately dilated mask and the original image to be edited, the mask position module generates a mask position map and the original image after masking. Based on the outline, mask position map, the original image after masking, and the text description, the diffusion network generates the original image after editing.
[0094] Experimental results are as follows Figure 7 As shown, this invention demonstrates superior performance in terms of the visual quality and consistency of the generated content. By incorporating a dual mechanism of sketch guidance and mask expansion, this invention can generate restoration results that are highly coordinated and naturally integrated with the surrounding environment. The generated content maintains excellent consistency with the original image in terms of texture, color, and lighting, appearing as if it were part of the image itself, rather than awkwardly filling in blank areas. The generated object outlines closely match the input sketch, accurately capturing the shape and structural features of the object, showcasing the powerful effect of sketch guidance.
[0095] This embodiment also provides a sketch image restoration and editing system based on a diffusion network, which is used to implement the above embodiments. The terms "module," "unit," etc., used below refer to combinations of software and / or hardware that perform a predetermined function. Although the system described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible.
[0096] This embodiment provides a sketch image restoration and editing system based on diffusion networks, including:
[0097] The data acquisition module is used to acquire sketches, text description data, and the original image to be edited;
[0098] The sketch enhancement network module is used to generate a contour map corresponding to the sketch using the sketch enhancement network;
[0099] The mask inflation module is used to generate an appropriately inflated mask image based on the contour map and text description.
[0100] The mask location module is used to generate a mask location map and the original image after masking, based on a moderately inflated mask map and the original image to be edited.
[0101] The diffusion network module is used to generate an edited original image based on the contour map, mask position map, original image after masking, and text description using a diffusion network.
[0102] For the system embodiments, since they basically correspond to the method embodiments, relevant details can be found in the descriptions of the method embodiments; the implementation methods of the remaining modules will not be repeated here. The system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of the present invention according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0103] The system embodiments of the present invention can be applied to any device with data processing capabilities, such as a computer or other similar device. The system embodiments can be implemented in software, hardware, or a combination of both. Taking software implementation as an example, as a logical device, it is formed by the processor of any data processing device loading the corresponding computer program instructions from non-volatile memory into memory for execution.
[0104] Obviously, the embodiments and accompanying drawings described above are merely some examples of this application. Those skilled in the art can apply this application to other similar situations based on these drawings without any creative effort. Furthermore, it is understood that although the work done in this development process may be complex and lengthy, for those skilled in the art, certain design, manufacturing, or production modifications made based on the technical content disclosed in this application are merely conventional technical means and should not be considered as insufficient disclosure of this application. Several modifications and improvements can be made without departing from the concept of this application, and these all fall within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the appended claims.
Claims
1. A sketch image restoration and editing method based on diffusion networks, characterized in that, Includes the following steps: Retrieve the sketch, text description data, and the original image to be edited; A sketch enhancement network is used to generate a contour map corresponding to a sketch. The sketch enhancement network includes a fusion module and an enhancement module based on an encoder-decoder structure. The fusion module takes the sketch as input to generate a fine sketch, and the enhancement module takes the fine sketch as input to generate a contour map. The training process of the sketch enhancement network includes: randomly deleting some strokes from the original sketch, treating the original sketch as a fine sketch, and treating the sketch after deleting strokes as a rough sketch. The training objective of the fusion module is to convert the rough sketch into a fine sketch. The outline of the original sketch is extracted as a label, and the training objective of the enhancement module is to convert the fine sketch into an outline image. Based on the contour map and text description, a moderately inflated mask map is generated using the mask inflation module; Based on the moderately inflated mask image and the original image to be edited, the mask position module is used to generate a mask position image and the original image after masking. Based on the outline map, mask location map, original image after masking, and text description, a diffusion network is used to generate the edited original image.
2. The sketch image restoration and editing method based on diffusion networks according to claim 1, characterized in that, The mask inflation module includes a mask inflation encoder and a mask inflation decoder. The mask inflation encoder takes the initial mask image corresponding to the contour image and the text description as input to generate inflation mask features. The mask inflation decoder takes the inflation mask features, the mask image, and the inflation kernel size as input to generate the inflation mask image.
3. The sketch image restoration and editing method based on diffusion networks according to claim 2, 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 expanded mask image of the current step is generated based on the current step element in the expanded mask feature and the latest mask image. All elements in the expanded mask feature are traversed, and the final mask image is used as the moderately expanded mask image.
4. The sketch image restoration and editing method based on diffusion networks according to claim 1, characterized in that, The mask location module is specifically as follows: The moderately inflated mask image is processed by convolutional kernels in four different directions to generate four feature maps containing directional information; Perform a 3x3 convolution on the moderately dilated mask image to obtain a distance map from the mask position to the nearest unmasked position; Fourier masks are used to overlay four feature maps and distance maps containing orientation information to generate a mask location map.
5. The sketch image restoration and editing method based on diffusion networks according to claim 1, 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 location map and the original image after masking are concatenated to obtain the mask feature map. The mask feature map is then processed sequentially by a diffusion encoder, a pre-trained Unet network based on a nested attention mechanism, and a diffusion decoder. During the processing, text descriptions are introduced to participate in the nested attention mechanism, and contour maps are introduced to participate in the middle and upsampling parts of the Unet network based on the nested attention mechanism, as well as the calculation of the diffusion decoder.
6. The sketch image restoration and editing method based on diffusion networks according to claim 5, characterized in that, When the contour map is computed 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. The downsampling result is then input into the middle part of the Unet network based on the nested attention mechanism that is being trained. The result is then concatenated with the output of the upsampling part of the Unet network based on the nested attention mechanism that is being trained, and then processed together.
7. The sketch image restoration and editing method based on diffusion networks according to claim 5, characterized in that, The nested attention mechanism calculation process includes: Using the mask feature map as the input tensor, the input tensor is transformed into a query tensor through a projection layer. Key tensors Sum tensor By calculating the query tensor With key tensor The dot product of the transpose of and divided by The self-attention similarity matrix of the mask feature map is obtained. Similarly, the text description is processed into a text embedding, and the text embedding is used as the input tensor to generate a self-attention similarity matrix of the text description. ; Based on the self-attention similarity matrix Calculate similarity score For moderately inflated mask images For each pixel j in the array, calculate its position in the array. Alignment fractions in Alignment score for all pixels Normalization, for pixels in unknown regions and pixels in the known area Update the original matrix in a loop: ; For the updated similarity matrix Apply the Softmax function and compare it with the value tensor Multiply the results, then add them to the mask feature map as the input tensor X to obtain the final output. .
8. A system for implementing the sketch image restoration and editing method based on diffusion networks as described in any one of claims 1-7, characterized in that, include: The data acquisition module is used to acquire sketches, text description data, and the original image to be edited; The sketch enhancement network module is used to generate a contour map corresponding to the sketch using the sketch enhancement network; The mask inflation module is used to generate an appropriately inflated mask image based on the contour map and text description. The mask location module is used to generate a mask location map and the original image after masking, based on a moderately inflated mask map and the original image to be edited. The diffusion network module is used to generate an edited original image based on the contour map, mask position map, original image after masking, and text description using a diffusion network.
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
