Method for adding object in image by adopting non-training diffusion modification mode
Through the training-free diffusion modification method in the text-to-image model, users can select areas on the original image and use words to specify added objects. Encoding and mutual attention maps are used to enhance the generated results, which solves the difficulty of conveying spatial relationships and high learning in the existing technology. Cost issue, achieving efficient and low-cost image editing.
Patent Information
- Application Number
- CN202410497219.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-24
- Publication Date
- 2024-09-03
AI Technical Summary
It is difficult for existing text-to-image models to accurately convey the spatial relationships between objects when generating images, and users require high learning costs and multiple modifications to achieve satisfactory results, and existing methods usually require additional input or retraining of the model. Added data and hardware requirements.
Using the non-training diffusion modification method, the user selects the generated area on the original image and uses words to specify the added objects. The generated results are enhanced through encoding and mutual attention maps. Objects are added without changing the rest of the original image, and K clustering and corrosion are used. -The dilation operation ensures the position and shape of the added objects.
It enables easy addition of objects without changing the rest of the original content, reduces user operation costs and model training costs, is suitable for different scenes and object types, and improves editing efficiency and consistency.
Smart Images

Figure CN118587104A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of viz-images, and in particular to a method for adding objects to an image by adopting a non-training diffusion modification method. Background Art
[0002] In recent years, significant progress has been made in transformer architectures (e.g., CLIP) and improved natural language embedding methods. In addition, the development of diffusion models has promoted more accurate and diverse image generation. Together, these advances have made text-to-image generation increasingly popular. Typically, text-to-image models accept a text description as input and generate an image related to the text description. Models such as DALL-E 3 and Stable Diffusion are particularly noteworthy for their impressive performance. However, most text-to-image models rely solely on text descriptions as input, which makes it difficult for users to convey / express the spatial relationship between objects. Take ChatGPT, the most famous large model, as an example. It requires users to describe all requirements through chat, which is not an easy task for non-professionals. To solve this problem, the academic community has proposed some solutions, and ControlNet may be one of the most famous models. ControlNet allows users to add additional inputs to control the posture of people or animals in the generated image. This additional input is usually connected by points and lines drawn by the user. The "points" represent key parts of the human or animal body, such as the head, elbow joints, etc., and the "lines" represent the connection relationship between key parts. Users can use this additional input to briefly draw the posture of the generated object they want.
[0003] At present, the field of text-generated images mainly faces two practical problems: first, it may be difficult to describe the image you want to generate with only text, which requires too high a learning cost for non-professional users; second, users usually need to modify the generated image multiple times to achieve the results they want, which is too inefficient. Existing methods are difficult to solve these two problems at the same time. For example, in our ChatGPT-4 test using DALL-E 3 for image generation, although the initial image it generates is of high quality and can also accept instructions to modify it based on the original image, the direction of the characters and their clothing details will be lost when comparing before and after the modification, and it cannot be completely consistent. In addition, DALL-E 3 does not support additional inputs; and methods such as ControlNet, although increasing the types of inputs, cannot be modified based on the original image, so it still requires users to decide the layout once before seeing any results; in addition, methods such as ControlNet that add additional inputs for control often require retraining of existing pre-trained models, or training additional modules and inserting them into pre-trained models, which puts higher requirements on data and hardware. Summary of the invention
[0004] The purpose of the present invention is to provide a method for adding objects to an image by adopting a training-free diffusion modification method, so as to solve the problems existing in the prior art. Without adding additional input or requiring any training, the method allows the user to add an object to a selected image area while keeping the rest of the image content almost unchanged, so that the user can more conveniently use the text graph model for creation.
[0005] In order to achieve the above object, the solution of the present invention is:
[0006] A method for adding objects to an image using a non-training diffusion modification method comprises the following steps:
[0007] Step 1: Allow the user to select a generation area on the original image generated by the diffusion model, and use a word to specify the user-added object that he wants to be generated in the selected generation area;
[0008] Step 2: Encode the prompts for generating the original image and the prompts for generating the user-added objects separately, and then concatenate the encoding results to obtain the prompt encoding of the final generated result;
[0009] Step 3, respectively generate three images based on the prompts for generating the original image, the prompts for generating the user-added objects, and the prompt encoding of the final generated result; in the generation process, based on the layout control technology, control the generation position of the user-added objects in the first 20% of the time steps to make it consistent with the selected generation area; concatenate the latent variables of the user-added objects in the generation area with the latent variables of the rest of the original image as the latent variables of the final generation result; enhance the mutual attention value of the final generation result in the selected generation area;
[0010] Step 4: When the generation process is about to end, edit the final generated result in the following way;
[0011] 4-1 Based on the mutual attention map, the K clustering method is used to preliminarily determine the pixels belonging to the user-added objects from all the points of the class whose number of points in the generated area selected by the box exceeds the preset threshold;
[0012] 4-2 Based on the pixel points belonging to the user-added object determined in 4-1, region growth is performed starting from these pixel points in the latent variable to obtain other similar points;
[0013] 4-3 In 4-1 and 4-2, the results are subjected to erosion-dilation operations to eliminate unconnected small areas.
[0014] In step 3, the mean of the original mutual attention map is calculated. If the mean is less than 1, it is counted as 1. Then, the value in the selected generation area in the mutual attention map is set to the mean, and the value of the remaining part is set to 0, so as to enhance the mutual attention value of the final generation result in the selected generation area.
[0015] After adopting the above technical solution, the present invention has the following technical effects:
[0016] Compared with some existing well-known methods, the present invention can achieve better editing results. The user only needs to select the area where the object is desired to be added in the original image generated by the model, and use a word as a prompt for the added object, and the corresponding object can be added to the original image without changing the image features of the rest of the original image, and the rest of the image content can be kept almost unchanged. For the user, there is no need to add additional input, and the operation is convenient and simple. For the model, no training is required, and the cost is lower. In addition, the method steps of the present invention can adapt to the generation of different scenes and different types of objects, and have a wider applicability. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 Schematic diagram of the splicing process of the encoding results of a specific embodiment of the present invention;
[0018] Figure 2is a schematic diagram of a process of enhancing mutual attention value according to a specific embodiment of the present invention;
[0019] Figure 3 It is a schematic diagram of the editing process of the final generated result of a specific embodiment of the present invention;
[0020] Figure 4 is a comparison diagram of the final generation results of the specific embodiment of the present invention and other methods;
[0021] Figure 5 It is a schematic diagram of generation results of a specific embodiment of the present invention in different types and scenarios. DETAILED DESCRIPTION
[0022] In order to further explain the technical solution of the present invention, the present invention is described in detail below through specific embodiments.
[0023] refer to Figures 1 to 5 As shown, the present invention discloses a method for adding objects to an image by adopting a non-training diffusion modification method, which realizes the image editing function by fusing the original image and the diffusion process of the user-specified generated object, and specifically includes the following steps:
[0024] Step 1: Allow the user to select a generation area on the original image generated by the diffusion model, and use a word to specify the user-added object that he wants to be generated in the selected generation area;
[0025] Step 2: See Figure 1 , respectively encode (embedding) the prompt used to generate the original image and the prompt used to generate the user-added object (encoding is a function of the diffusion model itself), and then concatenate the encoding results as the prompt encoding of the final generated result;
[0026] Step 3: Generate three images simultaneously based on the prompts for generating the original image, the prompts for generating the user-added objects, and the prompt codes for the final generated results; in the generation process, based on the layout control technology, control the generation position of the user-added objects in the first 20% of the time steps to make it consistent with the selected generation area; concatenate the latent variables of the user-added objects in the generation area with the latent variables of the rest of the original image as the latent variables of the final generated result; see Figure 2 , enhance the mutual attention value of the final generated result in the boxed generation area. Enhancement means calculating the mean of the original mutual attention map. If the mean is less than 1, it is counted as 1. Then, the value in the mutual attention map in the boxed generation area is set to the mean, and the rest of the values are set to 0;
[0027] Step 4: When the generation process is about to end, edit the final generated result in the following way to ensure that the original image remains unchanged except for the objects added by the user;
[0028] 4-1 Based on the mutual attention map, the K clustering method is used to preliminarily determine the pixels belonging to the user-added objects from all the points of the class whose number of points in the generated area selected by the box exceeds the preset threshold;
[0029] 4-2 Based on the pixel points belonging to the user-added object determined in 4-1, region growth is performed starting from these pixel points in the latent variable to obtain other similar points;
[0030] 4-3 In 4-1 and 4-2, the results are subjected to erosion-dilation operations to eliminate unconnected small areas.
[0031] The above are the overall steps of this technology, and the editing process of the final generated result is as follows Figure 3 shown.
[0032] Through the above scheme, see Figure 4 Compared with some existing well-known methods, the present invention can achieve better editing results. The user only needs to select the area where the object is expected to be added in the original image generated by the model and use a word as a prompt for the added object to add the corresponding object to the original image. The image features of other positions of the original image will not be changed, and the rest of the image content can be kept almost unchanged. For the user, no additional input is required, and the operation is convenient and simple. For the model, no training is required, and the cost is lower. In addition, Figure 5 It can be seen that the method steps of the present invention can adapt to the generation of different scenes and different types of objects, and have wider applicability.
[0033] The above embodiments and drawings do not limit the product form and style of the present invention. Any appropriate changes or modifications made by ordinary technicians in the relevant technical field should be deemed to be within the patent scope of the present invention.
Claims
1. A method for adding objects to an image using a non-training diffusion modification method, characterized in that The following steps are involved: Step 1: Allow the user to select a generation area on the original image generated by the diffusion model, and use a word to specify the user-added object that he wants to be generated in the selected generation area; Step 2: Encode the prompts for generating the original image and the prompts for generating the user-added objects separately, and then concatenate the encoding results to obtain the prompt encoding of the final generated result; Step 3: Generate three images simultaneously based on the prompts for generating the original image, the prompts for generating the user-added objects, and the prompt codes for the final generated results; during the generation process, based on the layout control technology, the generation position of the user-added objects is controlled in the first 20% of the time steps to make it consistent with the selected generation area; The hidden variables of the user-added object in the generated area are concatenated with the hidden variables of the rest of the original image as the hidden variables of the final generated result; the mutual attention value of the final generated result in the selected generated area is enhanced; Step 4: When the generation process is about to end, edit the final generated result in the following way; 4-1 Based on the mutual attention map, the K clustering method is used to preliminarily determine the pixels belonging to the user-added objects from all the points of the class whose number of points in the generated area selected by the box exceeds the preset threshold; 4-2 Based on the pixel points belonging to the user-added object determined in 4-1, region growth is performed starting from these pixel points in the latent variable to obtain other similar points; 4-3 In 4-1 and 4-2, the results are subjected to erosion-dilation operations to eliminate unconnected small areas.
2. The method for adding objects to an image using a non-training diffusion modification method as claimed in claim 1, characterized in that: In step 3, the mean of the original mutual attention map is calculated. If the mean is less than 1, it is counted as 1. Then, the value in the selected generation area in the mutual attention map is set to the mean, and the value of the remaining part is set to 0, so as to enhance the mutual attention value of the final generation result in the selected generation area.
