Enhanced object manipulation and background consistent image editing method

By updating the potential code in the inversion phase by the cross-attention and self-attention module of the diffusion model, the problem of object action and position editing and background maintenance in the prior art is solved, and a more consistent and controllable image editing effect is achieved.

CN118967880AActive Publication Date: 2024-11-15XIAMEN UNIV

Patent Information

Application Number
CN202410995249.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-24
Publication Date
2024-11-15
Estimated Expiration
2044-07-24

AI Technical Summary

Technical Problem

Existing image editing methods are difficult to edit the actions and positions of objects in the image simultaneously while maintaining the consistency of the background, resulting in poor user experience and loss of background details.

Method used

Using a diffusion model, including VAE encoder, VAE decoder and UNet denoiser, the cross attention module and self-attention module are used to gradually update the potential code during the inversion phase, transfer the object from the source area to the target area, and pass the The L1 loss function repairs the background and maintains the integrity of the unedited area, modifies the object action during the sampling stage, and finally generates the edited image.

Benefits of technology

It realizes simultaneous editing of objects in the image while maintaining the consistency of the background, and the generated results are more in line with user input and environment, improving user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118967880A_ABST
    Figure CN118967880A_ABST
Patent Text Reader

Abstract

An enhanced object manipulation and background consistent image editing method adopts a diffusion model to perform image editing on an original image, and mainly comprises the following steps: performing inversion updating on original potential codes step by step in a preset number of time steps, and transferring an editing object from a source area to a target area in a specific time step, the background of the source region after the editing object is transferred is repaired, and meanwhile, the background of the non-edited region after the editing object is transferred is kept complete, so that a final loss function is adopted in a specific time step of an inversion stage to iteratively update a specific potential code, and finally an updated potential code is obtained; and inputting the updated potential code and the indication text of the action of the editing object into a UNet de-noising device for sampling and de-noising to obtain an editing image. Therefore, the editing object can be injected into the target area in the inversion stage, the background integrity is kept, meanwhile, it can be ensured that the edited object generates specified actions in the sampling stage, and the consistency of image contents before and after editing is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of image processing, and in particular relates to an image editing method with enhanced object manipulation and background consistency. Background Art

[0002] Diffusion models have significantly improved image generation capabilities in the field of text-to-image generation. By leveraging a large amount of training data, these models are able to generate excellent images based on user prompts. Compared to generative adversarial networks (GANs), diffusion models provide superior quality and diversity in image generation. As a result, many studies have begun to investigate diffusion models for image editing tasks. These methods mainly involve text-conditional editing, where users provide text input to modify images. While some techniques can skillfully edit image style, object appearance, and object category based on text input, they do not change the scene layout or modify object motion in the image. However, in some cases, users want to edit the motion of an object while maintaining its appearance and context. This specific editing process is called consistent image editing.

[0003] Imagic introduced a consistent approach to image editing, but it required time-consuming fine-tuning of text embeddings and models. Subsequently, MasaCtrl provided a fine-tuning-free approach that transformed self-attention into mutual self-attention to achieve the same goal. Nevertheless, these methods are limited to editing the action of objects and do not allow control over the generated position of objects. DragonDiffusion enables object displacement within an image, but it cannot edit the action of the moved object. In practical applications, users sometimes need to edit the action and position of an object at the same time. In addition, previous methods also have shortcomings in background preservation. Since these methods only focus on editing the action of objects in the image and ignore the preservation of the background of the image, the backgrounds generated by these methods show a certain loss in details. Summary of the invention

[0004] The purpose of the present invention is to provide an image editing method with enhanced object manipulation and background consistency, which can solve the above-mentioned technical problems, can simultaneously edit the action and position of objects in the image, and maintain the consistency of the background before and after image editing, and has the advantage of improving user experience.

[0005] In order to achieve the above object, the solution of the present invention is: An enhanced object manipulation and background consistent image editing method uses a diffusion model to edit an original image, the diffusion model includes a VAE encoder, a VAE decoder and a UNet denoiser; the UNet denoiser includes a self-attention module and a cross-attention module, and is characterized by comprising the following steps: Step S1: Obtain image editing information, input the original image into the VAE encoder and encode it to obtain the original latent code: The image editing information includes instruction text of the editing object action and a target bounding box of the editing object generation position; Assume that the initial position of the edited object in the original image is the source region, then the position of the target bounding box is the target region of the edited object, and the complement of the union of the target region and the source region is the unedited region; Step S2: Invert and update the original potential code step by step within a preset number of time steps, and perform iterative update of the following steps on the specific potential code of the specific time step in the inversion stage, and finally obtain the updated potential code: Step S21: Transfer the edited object from the source area to the target area at the specific time step: The specific latent code is updated using the cross-attention map of the cross-attention module in the UNet denoiser, so that the cross-attention map corresponding to the edited object obtains the highest attention score within the target area, and the cross-attention map corresponding to the edited object obtains the lowest attention score outside the target area, thereby transferring the edited object from the source area to the target area; Step S22: Repair the background of the source area after the editing object is transferred: After the edited object is transferred to the target area, the source area of ​​the edited object is located through the high response area of ​​the cross attention map. At the same time, the union of the source area and the target area is subtracted from the source area to obtain a new source area. Then, the mask corresponding to the new source area is dilated to obtain the edge area around the new source area. The background of the source area is repaired by extracting the features of the specific latent code in the new source area and the features of the original latent code in the edge area, and calculating the L1 loss between the features of the specific latent code in the new source area and the features of the original latent code in the edge area. Step S23: Keep the background of the unedited area intact after the edited object is transferred: By extracting the features of the original latent code and the specific latent code in the unedited area, and calculating the L1 loss between the features of the original latent code in the unedited area and the features of the specific latent code in the unedited area, the integrity of the unedited area is maintained; Step S24, iteratively updating the specific latent code using the final loss function in a specific time step of the inversion phase to inject the edited object in the target area and maintain the background integrity; Step S3, inputting the updated latent code and the instruction text of the edit object action into the UNet denoiser for sampling and denoising, and modifying the action of the edit object after the transfer in the entire sampling stage to obtain the final latent code; Step S4: Input the final latent code into the VAE decoder for decoding to obtain the edited image.

[0006] Furthermore, the specific time step is the 35th time step, the preset number is 50, the number of iterative updates of the specific potential code is 50 times; and the resolution of the cross-attention map is 16×16.

[0007] Further, in step S21, the cross-attention map of the cross-attention module in the UNet denoiser is used to update the specific potential code, so that the cross-attention map corresponding to the edited object obtains the highest attention score within the target area, and the cross-attention map corresponding to the edited object obtains the lowest attention score outside the target area, thereby transferring the edited object from the source area to the target area, specifically: First, in order to ensure that the cross attention map corresponding to the edited object obtains the highest attention score within the range of the target area, the following loss function is proposed : ; in, The mask representing the target region, Indicates that the corresponding The cross attention map of time steps, The operation is used to extract the largest Attention scores, is the time step; Secondly, by minimizing the attention score of the cross attention map outside the target area, the edited object is not generated outside the target area, and the following loss function is proposed : ; in, The mask representing the target region, Indicates that the corresponding The cross attention map of time steps, N refers to the number of pixels in the non-target area, is the time step; Using edit object to inject loss function Update this specific latent code to inject the edited object from the source region into the target region, where the edited object injects the loss function for: .

[0008] Further, in step S22, the UNet denoiser of the diffusion model is used to extract the features of the specific latent code in the new source region and the features of the original latent code in the edge region, and the source region restoration loss function is used. To calculate the L1 loss between the features of a specific latent code in the new source region and the features of the original latent code in the edge region; The source region restoration loss function Align features in the edge region with the new source region by repeating and truncating the features in the edge region:

[0009] in, and denote the new source region and edge region respectively; represents the features of the original latent code, represents the characteristics of a particular latent code, is a repeat and truncate operation, is the time step.

[0010] Further, in step S23, the UNet denoiser of the diffusion model is used to extract the features of the original latent code and the specific latent code in the unedited area, and the background preservation loss function is used. Calculate the L1 loss between the features of the original latent code in the unedited region and the features of the specific latent code in the unedited region to keep the integrity of the unedited region; The background preservation loss function for:

[0011] in, Indicates an unedited area. represents the features of the original latent code, represents the characteristics of a particular latent code, is the time step.

[0012] Further, in step S24, the final loss function is used in a specific time step of the inversion phase. The specific latent code is updated to inject the edited object in the target area and keep the background integrity. The final loss function for: ; in, , and is the balancing parameter; by using the final loss function , a specific potential code by Update with the step size: ; As the number of update steps increases, the step size It decays linearly. is the time step.

[0013] Furthermore, in step S3, the updated potential code and the instruction text of the edit object action are input into the UNet denoiser for sampling and denoising, and the action of the edit object after the transfer is modified during the entire sampling stage to obtain the final potential code; specifically: In the sampling phase, the UNet denoiser is used to gradually denoise the updated latent code within the same preset number of time steps as in the inversion phase, and the cross-attention module of the UNet denoiser is used to integrate the instruction text of the edit object action into the sampling phase; and from the sampling phase, the first Starting from the time step, replace the key vector and value vector of the self-attention module in the UNet denoiser with the key vector and value vector in the corresponding time step of the inversion phase; The process of replacing the key vector and value vector of the self-attention module with the key vector and value vector in the corresponding time step of the inversion phase is expressed as: ; Among them, Q, K, and V are the query vector, key vector, and value vector in the self-attention module respectively. represents a self-attention layer in the UNet denoiser, and The key vector and value vector representing the corresponding time step of the inversion phase; When the sampling time step t Exceed , and the self-attention layer Is a predefined set When part of , replace the key vector K and value vector V in the self-attention module with and .

[0014] Furthermore, the decoder of the UNet denoiser consists of four blocks of different scales, wherein the third layer contains more geometric information; in step S22, the third layer is selected to extract features from the original latent code and the specific latent code.

[0015] The present invention also provides a computer system, which includes a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set are loaded and executed by the processor to implement the enhanced object manipulation and background consistent image editing method.

[0016] The present invention also provides a computer-readable storage medium, in which at least one instruction, at least one program, code set or instruction set is stored. The at least one instruction, the at least one program, the code set or instruction set is loaded and executed by a processor to implement the enhanced object manipulation and background consistent image editing method.

[0017] After adopting the above technical solution, since the previous methods only focus on editing the action of a certain object in the image, and do not propose a specific method to maintain the consistency of the background before and after the image is edited, these methods also have defects in background maintenance. Compared with the previous methods, the present invention can inject the edited object into the target area in the inversion stage and maintain the integrity of the background, and at the same time ensure that the action specified by the instruction text of the edited object is generated in the sampling stage, ensuring the consistency of the image content before and after editing; the result produced by the method of the present invention is more consistent with the edited text input by the user, and is also more consistent with the surrounding environment. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 is a flow chart of the method steps of the present invention; Figure 2 is a flow chart of the present invention; Figure 3 It is a schematic diagram of the present invention; Figure 4 It is a schematic diagram of locating the source area through the cross attention map and obtaining the edge area through the dilation operation; Figure 5 The editing result of the present invention (I); Figure 6 The editing result of the present invention (II); Figure 7 is the comparison result between the method of the present invention and the previous method when only the action of the object is edited (I); Figure 8 is the comparison result between the method of the present invention and the previous method when only the action of the object is edited (II); Fig. 9 It is the comparison result between the method of the present invention and the previous method when only the action of the object is edited (III). DETAILED DESCRIPTION

[0019] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below in combination with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments.

[0020] In the field of image editing, in practical applications, users sometimes need to edit the action and position of an object in an image at the same time. In order to solve this problem, the present invention proposes an enhanced object manipulation and background consistency image editing method, which is based on a diffusion model for image editing, and uses a diffusion model to edit the original image. The diffusion model includes a VAE encoder, a VAE decoder and a UNet denoiser; the UNet denoiser includes a self-attention module and a cross-attention module.

[0021] First, the object information is transferred from the source region to the target region and the background is repaired at a specific time step in the inversion phase. Then, the action of the object information is modified throughout the sampling phase, and finally the edited image is output.

[0022] Specifically, Figures 1 to 3 As shown, the image editing method comprises the following steps: Step S1: Obtain image editing information, input the original image into the VAE encoder and encode it to obtain the original latent code: The image editing information includes instruction text of the editing object action and a target bounding box of the editing object generation position.

[0023] In this embodiment, the editing instruction of the action may be an editing text in a natural language input by the user, for example Figure 2 The editing prompt shown is: A running bear. The editing indication of the generated position can be a target bounding box specified by the user. At the same time, the present invention refers to the initial position of the edited object in the original image as the source area, and the target bounding box specified by the user as the target area of ​​the edited object, and the complement of the union of the target area and the source area is called the unedited area (equivalent to the background area).

[0024] Step S2: gradually invert and update the original potential code within a preset number of time steps, that is, perform noise update, and perform iterative update of the following steps on the specific potential code of the specific time step in the inversion stage, and finally obtain the updated potential code: Step S21: Transfer the edited object from the source area to the target area at the specific time step: The specific latent code is updated using the cross-attention map of the cross-attention module in the UNet denoiser, so that the cross-attention map corresponding to the edited object obtains the highest attention score within the target area, and the cross-attention map corresponding to the edited object obtains the lowest attention score outside the target area, thereby transferring the edited object from the source area to the target area; Step S22: Repair the background of the source area after the editing object is transferred: After the edited object is transferred to the target area, the source area of ​​the edited object is located through the high response area of ​​the cross attention map, and then the mask corresponding to the source area is dilated to obtain the edge area around the source area; the background of the source area is repaired by extracting the features of the specific latent code in the new source area and the features of the original latent code in the edge area, and calculating the L1 loss between the features of the specific latent code in the new source area and the features of the original latent code in the edge area; Step S23: Keep the background of the unedited area intact after the edited object is transferred: By extracting the features of the original latent code and the specific latent code in the unedited area, and calculating the L1 loss between the features of the original latent code in the unedited area and the features of the specific latent code in the unedited area, the integrity of the unedited area is maintained; Step S24, iteratively updating the specific latent code using the final loss function in a specific time step of the inversion phase to inject the edited object in the target area and maintain the background integrity; Step S3, inputting the updated latent code and the instruction text of the edit object action into the UNet denoiser for sampling and denoising, and modifying the action of the edit object after the transfer in the entire sampling stage to obtain the final latent code; Step S4: Input the final latent code into the VAE decoder for decoding to obtain the edited image.

[0025] In this embodiment, the specific time step may be the 35th time step, the preset number may be 50, the number of iterative updates of the specific potential code may be 50 times; and the resolution of the cross-attention map may be 16×16.

[0026] The specific steps and principles of the method of the present invention are as follows: 1. Editing Object Transfer In step S21, in order to generate an edit object in the target area, the present invention updates the specific latent code by using the cross-attention map of the cross-attention module in the UNet denoiser at the 35th time step of the inversion phase, and adopts the edit object injection loss function to inject the edited object into the target area.

[0027] The present invention uses a 16×16 resolution cross-attention map to update the latent code because the cross-attention map of this specific resolution is rich in semantic information. In order to inject the edited object into the target area, the present invention ensures that the cross-attention map corresponding to the edited object obtains the highest attention score within the scope of the target area, that is, maximizes the attention score within the scope of the target area, and proposes the following loss function : (1) in The mask representing the target region, Indicates that the corresponding time steps of cross attention map, where . The operation is used to extract the largest An attention score.

[0028] Accordingly, in order to prevent the edited object from being generated outside the target area, the present invention minimizes the attention score of the area outside the target area to ensure an accurate and controlled editing process, and proposes the following loss function: : (2) in The mask representing the target region, Indicates that the corresponding time steps of cross attention map, where ; In summary, the editing object injection loss function of the present invention can be obtained: for: (3) 2. Source area restoration In step S22, after the edited object is transferred to the target area, the source area needs to be repaired. The present invention locates the source area of ​​the edited object through the high response area of ​​the cross attention map, such as Figure 3 At the same time, in order to avoid the conflict between the source region background restoration and the maximization of the attention score of the target region, the present invention subtracts the union of the source region and the target region from the original source region to obtain a new source region, and the present invention uses this new source region as the source region of the actual background to be restored.

[0029] Usually, the background of the source region is similar to the background around the source region. To achieve this, the present invention first performs an expansion operation on the mask corresponding to the new source region, thereby obtaining the region around the new source region, such as Figure 4 The present invention records the expanded surrounding area as the edge area.

[0030] In order to coordinate the background of the new source area with the background of the edge area, the present invention extracts the features of the two areas of the latent code, that is, by extracting the features of the specific latent code in the new source area and the features of the original latent code in the edge area, and then calculating the L1 loss between the features of the two areas, and using the source area restoration loss function The background of the source area is repaired. Since the UNet denoiser of the diffusion model is an effective feature extractor, the present invention uses the UNet denoiser to extract features from the latent code. The decoder of the UNet denoiser consists of four blocks of different scales, where the second layer contains more semantic information and the third layer contains more geometric information. In the method of the present invention, the present invention selects the third layer. Since the sizes of the edge area and the source area are not necessarily equal, the present invention repeats and truncates the features of the edge area to align the features in the two areas. Source area repair loss function for: (4) in and Represent the new source area and edge area respectively. represents the features of the original latent code, represents the characteristics of a specific latent code, where . is a repeat and truncate operation.

[0031] 3. Background maintenance In step S23, when relocating the edited object from the source region to the target region, the present invention observes that the injection of object information and the subsequent restoration of the source region may inadvertently damage the image background. In order to solve this problem and maintain the integrity of the unedited region, the present invention proposes a background preservation loss function .

[0032] Using the rich image structure and texture information contained in the intermediate features of the UNet denoiser, the present invention uses the UNet denoiser to extract features from the latent code. Subsequently, the present invention calculates the L1 loss between the features of the original latent code in the unedited area and the features of the specific latent code in the unedited area, i.e., the background preservation loss function for: (5) in Indicates an unedited area. This may result in the loss of some background information in the edited image. ,The present invention ensures the consistency between the background regions before and after editing.,At the same time, the object information in the unedited region is suppressed, ensuring that the edited,object follows the target bounding box constraint specified by the user more,closely.

[0033] (IV) Code Update In step S24, the final loss function of injecting the edited object into the target area and maintaining the background integrity at the 35th time step of the inversion phase is yes: (6) in , and is the balancing parameter. By using the final loss function , a specific potential code by Update with the step size: (7) As the number of update steps increases, the step size It decays linearly. This process ensures a smooth and consistent image editing process, maintaining the background of the unedited area and generating the edited object into the target area.

[0034] 5. Consistent Image Editing In step S3, the updated latent code is obtained through the inversion stage Afterwards, the present invention uses it as the initial point of the reverse denoising process, and inputs the editing instruction of the action in the sampling stage to modify and edit the action of the editing object, and finally outputs the edited image through the decoder.

[0035] In the sampling phase, the updated latent code is gradually denoised using the UNet denoiser within the same number of time steps as in the inversion phase, and in order to ensure that the edited object generates the action specified by the instruction text, the present invention uses the cross-attention module of UNet to integrate the editing instructions of the action into the sampling phase. In addition, in order to ensure the consistency of the image content before and after editing, the sampling phase starts from the first Starting from the time step, the present invention replaces the key vector and value vector in the self-attention module with the key vector and value vector in the corresponding time step of the inversion phase.

[0036] Different from the previous methods, the present invention queries the key vector and value vector of the inversion stage, because the present invention believes that the key vector and value vector of this stage contain richer object appearance and image background information than the sampling stage. In addition, the key vector and value vector of the inversion stage are used to reduce the image reconstruction cost.

[0037] Therefore, the optimization process of the present invention transforms the original three branches of inversion, reconstruction and editing into two branches: inversion and editing. The optimized exchange process of key vector and value vector can be expressed as: (8) in and Keys and values ​​representing the corresponding time steps in the inversion phase.

[0038] Among them, Q, K, and V are the query vector, key vector, and value vector in the self-attention module respectively. represents a self-attention layer in the UNet denoiser, and The key vector and value vector representing the corresponding time step of the inversion phase; When the sampling time step t Exceed , and the self-attention layer Is a predefined set When part of , replace the key vector K and value vector V in the self-attention module with and . .

[0039] In summary, if Figure 5 and Figure 6 As shown in the figure, the left side is the input original image, the middle image is a schematic diagram of the bounding box provided by the user, and the right side is the edited image generated according to the bounding box and the edit text input by the user; the present invention allows the user to input the edit text to edit the action of the object, and also allows the user to provide a bounding box to specify the generation position of the edited object. Compared with previous methods, the present invention provides a more controllable and consistent image editing function.

[0040] In addition, since previous methods such as Imagic, MasaCtrl, and InstructPix2Pix only focus on editing the action of a certain object in an image, but do not propose specific methods to maintain the consistency of the background before and after image editing, these methods also have defects in background preservation.

[0041] like Figure 7 , Figure 8 and Fig. 9 As shown, by specifying the generated position of the object as its original position, the editing results generated by the method of the present invention are compared with the previous methods, where (a) is the original image, and (b)-(e) are the edited images of the original image after being processed by InstructPix2Pix, PnP, MasaCtrl, and the method of the present invention, respectively. The background generated by the previous method shows a certain loss in details, while the background generated by the method of the present invention is closer to the original image. At the same time, compared with the previous method, the result generated by the method of the present invention is more consistent with the edited text input by the user, and is also more consistent with the surrounding environment.

[0042] The present invention provides a computer system, which includes a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the enhanced object manipulation and background consistent image editing method.

[0043] The present invention also provides a computer-readable storage medium, which stores at least one instruction, at least one program, code set or instruction set. The at least one instruction, at least one program, code set or instruction set is loaded and executed by a processor to implement the enhanced object manipulation and background consistent image editing method.

Claims

1. An enhanced object manipulation and background consistent image editing method, using a diffusion model to edit the original image, the diffusion model includes a VAE encoder, a VAE decoder and a UNet denoiser; the UNet denoiser includes a self-attention module and a cross-attention module, characterized in that The steps include: Step S1: Obtain image editing information, input the original image into the VAE encoder and encode it to obtain the original latent code: The image editing information includes instruction text of the editing object action and a target bounding box of the editing object generation position; Assume that the initial position of the edited object in the original image is the source region, then the position of the target bounding box is the target region of the edited object, and the complement of the union of the target region and the source region is the unedited region; Step S2: Invert and update the original potential code step by step within a preset number of time steps, and perform iterative update of the following steps on the specific potential code of the specific time step in the inversion stage, and finally obtain the updated potential code: Step S21: Transfer the edited object from the source area to the target area at the specific time step: The specific latent code is updated using the cross-attention map of the cross-attention module in the UNet denoiser, so that the cross-attention map corresponding to the edited object obtains the highest attention score within the target area, and the cross-attention map corresponding to the edited object obtains the lowest attention score outside the target area, thereby transferring the edited object from the source area to the target area; Step S22: Repair the background of the source area after the editing object is transferred: After the edited object is transferred to the target area, the source area of ​​the edited object is located through the high response area of ​​the cross attention map. At the same time, the union of the source area and the target area is subtracted from the source area to obtain a new source area. Then, the mask corresponding to the new source area is dilated to obtain the edge area around the new source area. The background of the source area is repaired by extracting the features of the specific latent code in the new source area and the features of the original latent code in the edge area, and calculating the L1 loss between the features of the specific latent code in the new source area and the features of the original latent code in the edge area. Step S23: Keep the background of the unedited area intact after the edited object is transferred: By extracting the features of the original latent code and the specific latent code in the unedited area, and calculating the L1 loss between the features of the original latent code in the unedited area and the features of the specific latent code in the unedited area, the integrity of the unedited area is maintained; Step S24, iteratively updating the specific latent code using the final loss function in a specific time step of the inversion phase to inject the edited object in the target area and maintain the background integrity; Step S3, input the updated latent code and the instruction text of the edit object action into the UNet denoiser for sampling and denoising, and modify the action of the edit object after the transfer during the entire sampling phase to obtain the final latent code; Step S4: Input the final latent code into the VAE decoder for decoding to obtain the edited image.

2. The method of enhanced object manipulation and background consistency image editing according to claim 1, characterized in that: The specific time step is the 35th time step, the preset number is 50, the number of iterative updates of the specific potential code is 50 times; the resolution of the cross-attention map is 16×16.

3. The method for enhanced object manipulation and background consistency image editing according to claim 1 or 2, characterized in that: In step S21, the cross-attention map of the cross-attention module in the UNet denoiser is used to update the specific potential code, so that the cross-attention map corresponding to the edited object obtains the highest attention score within the target area, and the cross-attention map corresponding to the edited object obtains the lowest attention score outside the target area, thereby transferring the edited object from the source area to the target area, specifically: First, in order to ensure that the cross attention map corresponding to the edited object obtains the highest attention score within the range of the target area, the following loss function is proposed : ; in, The mask representing the target region, Indicates that the corresponding The cross attention map of time steps, The operation is used to extract the largest Attention scores, is the time step; Secondly, by minimizing the attention score of the cross-attention map outside the target area, the edited object is not generated outside the target area, and the following loss function is proposed : ; in, The mask representing the target region, Indicates that the corresponding The cross attention map of time steps, N refers to the number of pixels in the non-target area, is the time step; Using edit object to inject loss function Update this specific latent code to inject the edited object from the source region into the target region, where the edited object injects the loss function for: 。 4. The method of enhanced object manipulation and background consistency image editing according to claim 3, characterized in that: In step S22, the UNet denoiser of the diffusion model is used to extract the features of the specific latent code in the new source region and the features of the original latent code in the edge region, and the source region restoration loss function is used. To calculate the L1 loss between the features of a specific latent code in the new source region and the features of the original latent code in the edge region; The source region restoration loss function Align features in the edge region with the new source region by repeating and truncating the features in the edge region: in, and denote the new source region and edge region respectively; represents the features of the original latent code, represents the characteristics of a particular latent code, is a repeat and truncate operation, is the time step.

5. The method of image editing with enhanced object manipulation and background consistency according to claim 4, characterized in that:In step S23, the UNet denoiser of the diffusion model is used to extract the features of the original latent code and the specific latent code in the unedited area, and the background preservation loss function is used. Calculate the L1 loss between the features of the original latent code in the unedited region and the features of the specific latent code in the unedited region to keep the integrity of the unedited region; The background preservation loss function for: in, Indicates an unedited area. represents the features of the original latent code, represents the characteristics of a particular latent code, is the time step.

6. The method of enhanced object manipulation and background consistency image editing according to claim 5, characterized in that: In step S24, the final loss function is adopted at a specific time step in the inversion phase The specific latent code is updated to inject the edited object in the target area and keep the background integrity. The final loss function for: ; in, , and is the balancing parameter; by using the final loss function , a specific potential code by Update with the step size: ; As the number of update steps increases, the step size It decays linearly. is the time step.

7. The method of enhanced object manipulation and background consistency image editing according to claim 6, characterized in that: In the step S3, the updated latent code and the instruction text of the edit object action are input into the UNet denoiser for sampling and denoising, and the action of the edit object after the transfer is modified during the entire sampling phase to obtain the final latent code; Specifically: In the sampling phase, the UNet denoiser is used to gradually denoise the updated latent code within the same preset number of time steps as in the inversion phase, and the cross-attention module of the UNet denoiser is used to integrate the instruction text of the edit object action into the sampling phase; and from the sampling phase, the first Starting from the time step, replace the key vector and value vector of the self-attention module in the UNet denoiser with the key vector and value vector in the corresponding time step of the inversion phase; The process of replacing the key vector and value vector of the self-attention module with the key vector and value vector in the corresponding time step of the inversion phase is expressed as: ; Among them, Q, K, and V are the query vector, key vector, and value vector in the self-attention module respectively. represents a self-attention layer in the UNet denoiser, and The key vector and value vector representing the corresponding time step of the inversion phase; When the sampling time step t Exceed , and the self-attention layer Is a predefined set When part of , replace the key vector K and value vector V in the self-attention module with and .

8. The method for enhanced object manipulation and background consistency image editing according to claim 1 or 4, characterized in that: The decoder of the UNet denoiser consists of four blocks of different scales, where the third layer contains more geometric information; in step S22, the third layer is selected to extract features from the original latent code and the specific latent code.

9. A computer system, characterized in that: The computer system includes a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set are loaded and executed by the processor to implement an enhanced object manipulation and background consistency image editing method as described in any one of claims 1 to 8.

10. A computer-readable storage medium, characterized in that: The storage medium stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set are loaded and executed by the processor to implement an enhanced object manipulation and background consistency image editing method as described in any one of claims 1 to 8.

Citation Information

Patent Citations

  • Text-guided multi-region scene image editing method and system based on diffusion model

    CN117456055A

  • Multi-modal image editing

    CN118071881A

  • Text-guided controllable portrait generation method, system and equipment based on diffusion model

    CN118114124A

Cited By

  • Shielding object moving and editing method and system based on diffusion model

    CN119810263A

  • Image processing method, system, equipment and medium

    CN119941770A

  • Background reserved image editing method and device, electronic equipment and program product

    CN120876636A