Color picture generation method based on potential diffusion model
Through the forward noise addition and reverse denoising processing of the potential diffusion model, combined with Gaussian noise and conditional mechanism, the problems of low color painting generation efficiency, loss of details and high computing resource consumption in the existing technology are solved, and high quality is achieved. Stable and diverse color painting generation.
Patent Information
- Application Number
- CN202410954393.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-17
- Publication Date
- 2024-11-01
AI Technical Summary
The prior art relies on manual labor when generating color paintings, which is inefficient and lacks personalization, details are lost during image generation, computing resources are consumed, the model is sensitive to data deviation, the generation results are unstable, and there is a lack of innovation and diversity.
Using a method based on the potential diffusion model, forward noise diffusion and reverse denoising diffusion are performed through the DP-Encoder encoder and U-Net network to ensure the predictability and consistency of the generation process, and use Gaussian noise and conditional mechanisms. Generate color paintings to achieve deterministic mapping and detail retention.
Improves the quality and relevance of generated color paintings, simplifies network complexity, reduces noise, improves visual quality and robustness, and ensures stability and diversity of generated results.
Smart Images

Figure CN118887315A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of image processing, and in particular to a color painting generation method based on a potential diffusion model. Background Art
[0002] There are many problems in the field of painting training. Generally speaking, painting teaching relies on the teacher's personal demonstration and guidance. This method is often difficult to meet students' personalized and diversified learning needs due to the limitations of teachers and time resources. In addition, students cannot get immediate feedback on the problems they encounter in the learning process, which often affects their learning enthusiasm and the development of creativity.
[0003] With the rapid development of digital technology, some online platforms and applications that assist art education have gradually emerged. These platforms, such as "Painting Cloud" and "Art Express", provide students with more diverse learning resources through functions such as video tutorials, interactive communities and real-time online tutoring. However, most of these tools still rely on traditional teaching content and methods, and due to the limitations of technology and user experience, it is difficult to fully meet students' needs for instant feedback and personalized learning.
[0004] The existing technology mainly uses convolutional neural networks to generate sketches. Secondly, the existing technology also combines neural networks with machine learning technology to generate colorful paintings, and receives user feedback in real time during the generation process, and adjusts the details of the painting based on the feedback to meet the user's personalized needs.
[0005] However, the above method has the following defects:
[0006] 1. Color paintings are drawn by teachers, which heavily rely on manual labor, and the efficiency of painting works is low. Professional teachers need several hours to complete an excellent color work. In addition, teachers are subjective in painting, and different teachers have slightly different views on the same work;
[0007] 2. Only high-level features of the image are extracted, and low-level information is discarded, so the stylized image will lose details; although the attention mechanism can help the model focus on the main area of the image, it ignores some subtle but important elements, such as fine textures and color gradients; these methods are unstable in adversarial training, making it difficult for the model to generate high-resolution images. The model is very sensitive to sample bias in the data set. If the training data is not diverse enough, the generated works will also be affected, lacking innovation and diversity;
[0008] 3. Although it can simulate the natural diffusion effect of paint, this method requires a lot of calculations during the algorithm iteration process and has high demand for computing resources, which is not practical in an environment with limited resources. In addition, the model is highly random, which may cause the final generated painting to deviate significantly from expectations. Summary of the invention
[0009] In view of the shortcomings of the prior art, the present invention provides a color painting generation method based on a latent diffusion model. The present invention ensures the predictability and consistency of the image generation process by changing the denoising and denoising processes of the diffusion process into deterministic mapping, thereby greatly improving the quality and relevance of the image conversion of the generated color painting.
[0010] The technical solution of the present invention is: a color painting generation method based on a potential diffusion model, comprising the following steps:
[0011] S1), build a color painting dataset;
[0012] S2), constructing a potential diffusion model network including a DP-Encoder encoder and a U-Net network;
[0013] S3), using the DP-Encoder encoder to encode the input color painting image into a potential representation Z;
[0014] S4), during the encoding process, the DP-Encoder performs forward noise diffusion processing on the input color painting image to simulate the image degradation process; a series of noise images are generated by gradually transforming Gaussian noise and the color painting image; then the DP-Encoder generates a potential code Zt using the relationship between the noise image and the Gaussian noise;
[0015] S5), using the U-Net network to perform reverse denoising diffusion processing on the noisy latent coding image after the forward denoising diffusion processing, and gradually restore the noisy latent coding to the original data or generate a new data variant;
[0016] S6), after the reverse denoising diffusion process, the conditional mechanism is used to guide the denoising process to obtain the potential representation of the denoised image, and then the U-Net network is used to decode the potential representation of the denoised image to obtain the final target watercolor image.
[0017] Preferably, in step S1), the color painting data set includes color paintings, text descriptions of source images and descriptions of target texts.
[0018] Preferably, in step S1), the creation of each color painting work is divided into four steps, namely, "forming", "finding three major surfaces", "color transition" and "depicting details".
[0019] Preferably, in step S4), the DP-Encoder samples Z~DPEnc(Z|X,G), and then defines the posterior distribution q(X 1:T |X0) to process the input image.
[0020] Preferably, in step S4), for each color painting image X0, a noise image sequence X1..., X t-1 ,X t , which is from the initial color painting image X0 to the completely noisy state X t A series of intermediate states, and at each time step t, calculate the Gaussian noise ∈ t , and then the Gaussian noise ∈ t Combined with the noisy image sequence, the latent code Zt is generated.
[0021] Preferably, in step S4), using Update the potential representation, integrate the denoising estimate into the current potential code, gradually establish a mapping path from noise to clear image, and finally output the potential code Z t .
[0022] As a preference, in step S4), the potential code Z t The calculation formula is:
[0023]
[0024] In the formula, Z t is the potential code at time t; Z t-1 is the potential code at time t-1; β t is the noise level at time t, ∈ is the real noise;
[0025] By gradually transforming the latent representation from a state close to the original data to a more random state, Z t Gradually loses its similarity to the original data and instead contains more random noise components; in the forward diffusion process, the potential code Z of each step is recorded t .
[0026] Preferably, in step S4), the Gaussian noise ∈ t The calculation formula is:
[0027] ∈ t =X t-1 -μ T (X t , t) / σ t ;
[0028] Where, X t-1 represents the noise image at time t-1, X t represents the noise image at time t, μ T Represents the current noise image state X t and the mean function at time step t, σ t represents the noise intensity at time step t.
[0029] Preferably, in step S4), the expression of the objective function of the forward diffusion process is:
[0030] L LDM =E x ,∈~N(0,1),
[0031] Where, L LDM is the loss function of the latent diffusion model, E x To perform the desired processing on the real image data x, ∈~N(0,1) indicates that the real noise ∈ is sampled from the standard state distribution N(0,1), ∈ θ To predict the noise, Z t for latent coding;
[0032] By starting with the real color painting image data x, adding noise to it, we generate the latent code Z t , simulate the intermediate state of the diffusion process, calculate the real noise ∈ and the predicted noise ∈ θ (Z t ,t), the smaller the Euclidean distance is, the more accurate the prediction result of the noise is.
[0033] As a preferred embodiment, in step S5), the reverse denoising process uses a U-Net network to convert the latent code Z containing noise into t Restore to a noise-free potential code Z0 close to the original; the U-Net network uses its internal cross-attention layer to integrate external condition information, and through the QKV mechanism, each step of denoising is adjusted according to external information.
[0034] As a preferred embodiment, in step S5), from the state Z of the noise t Initially, the U-Net network predicts the noise ∈ t , and then gradually restore the previous state Z using the following denoising formula t-1 :
[0035]
[0036] In the formula, Z t-1 is the potential code at time t-1, Z tis the potential code at time t, β t is the noise level at time t, U(Z t ,t) is the current latent code Z at a given time step t t Denoised estimate of the U-Net network output under the condition of .
[0037] Preferably, in step S6), the conditional mechanism is a cross attention mechanism, which enhances the U-Net network backbone through the cross attention mechanism, and introduces a text encoder to encode the text description of the source image and the description information of the target text into an intermediate representation τ θ ; and the intermediate representation τ is transformed through the cross attention mechanism θ Mapped into the middle layer of the U-Net network, where the Q value comes from the potential code, and the K and V values come from the conditional mechanism, namely:
[0038]
[0039] In the formula, Attention(Q, K, V) represents the output of the attention mechanism, where Q, K, and V are the query matrix, key matrix, and value matrix respectively; softmax is a normalization function that converts the input into a probability distribution. represents the scaling factor in the attention mechanism, d is the dimension of the query matrix Q and the key matrix K, which is used to prevent the dot product value from being too large; T represents the transpose operation, denote the parameter matrices of Q, K and V respectively, Represents the potential code Z t The intermediate representation of the i-th layer; τ θ (y) represents the intermediate representation of the conditional input y mapped by the text encoder;
[0040] In the image generation process, the color painting image is assisted in being generated according to the given text conditions, thereby achieving high-quality conversion of the color painting image with text prompts.
[0041] Preferably, in step S6), the loss function of the reverse denoising process of the potential diffusion model is expressed as:
[0042] L LDM =E x ,∈~N(0,1),
[0043] Where, L LDM is the loss function of the latent diffusion model, E x Indicates the expected processing of the real image data x, that is, the average of all training data, ∈~N(0,1) indicates that the real noise ∈ is sampled from the standard state distribution N(0,1), ∈ θ represents the prediction noise; τθ (y) represents the intermediate representation of condition y; Z t represents the latent code at time step t.
[0044] The beneficial effects of the present invention are:
[0045] 1. The present invention ensures the predictability and consistency of the generation process by changing the denoising and denoising process of the diffusion process to a deterministic mapping, thereby greatly improving the quality and relevance of the generated color painting image conversion;
[0046] 2. The present invention utilizes the redefinition of Gaussian latent space, which not only simplifies the complexity of the network but also improves the efficiency of the operation;
[0047] 3. The present invention can effectively reduce the noise in the generation process without sacrificing the richness of details by precisely controlling the latent coding, further improving the visual quality of the color painting image;
[0048] 4. The present invention improves the robustness and stability of the present invention by reconstructing the image into a deterministic mapping, ensuring that the encoding and decoding processes under different conditions are stable and will not produce unexpected results;
[0049] 5. The present invention utilizes a conditional mechanism to guide reverse denoising, and utilizes a conditional guidance signal combined with latent coding to adjust the generation process, thereby achieving a specified gouache style transformation. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] Figure 1 It is a schematic diagram of the process of the present invention;
[0051] Figure 2 A network framework diagram of a potential diffusion model constructed for the present invention;
[0052] Figure 3 It is a schematic diagram of the structure of the U-Net network of the present invention;
[0053] Figure 4 It is a schematic diagram of the process of reverse denoising diffusion of the present invention;
[0054] Figure 5 It is a schematic diagram of the process of using conditional mechanism to guide denoising in the present invention;
[0055] Figure 6 A schematic diagram of the four steps of creating a color painting of the present invention; DETAILED DESCRIPTION
[0056] The specific implementation of the present invention will be further described below in conjunction with the accompanying drawings:
[0057] like Figure 1 and 2As shown, this embodiment provides a color painting generation method based on a potential diffusion model, comprising the following steps:
[0058] S1), build a color painting dataset;
[0059] In this embodiment, the obtained color painting data set includes color paintings, text descriptions of source images, and descriptions of target text. In this embodiment, the creation of each color painting is divided into four steps: "forming", "finding three major surfaces", "color transition", and "depicting details". Figure 6 As shown, Figure 6 From left to right in the picture are the jar and the fruit: "Shape", "Find the three major surfaces", "Color transition", and "Describe the details".
[0060] S2), constructing a potential diffusion model network including a DP-Encoder encoder and a U-Net network; and using the constructed potential diffusion model network to process the color painting in steps S3-S6), such as Figure 2 shown.
[0061] The latent diffusion model network of this embodiment can not only analyze the local features such as the contour and texture of each element in the color painting, but also capture the interaction and harmony between the main body and the supporting role of the color painting. This embodiment accurately maps the input image to the latent space through the DP-Encoder encoder, and the image reconstructed from the latent encoding is completely consistent with the original image, realizing deterministic mapping, which ensures that the generated result can reliably represent the real situation.
[0062] S3), using the DP-Encoder encoder to encode the input color painting image into a potential representation Z;
[0063] S4), during the encoding process, the DP-Encoder performs forward noise diffusion processing on the potential representation Z to simulate the image degradation process; a series of noise images are generated by gradually transforming Gaussian noise and color painting images; then the DP-Encoder uses the relationship between the noise image and Gaussian noise to generate the potential code Zt;
[0064] S5), using the U-Net network to perform reverse denoising diffusion processing on the noisy latent coding image after the forward denoising diffusion processing, and gradually restore the noisy latent coding to the original data or generate a new data variant;
[0065] S6), after the reverse denoising diffusion process, the conditional mechanism is used to guide the denoising process to obtain the potential representation of the denoised image, and then the U-Net network is used to decode the potential representation of the denoised image to obtain the final target watercolor image.
[0066] As a preferred embodiment of this invention, in step S4), the DP-Encoder samples Z~DPEnc(Z|X,G), and then defines the posterior distribution q(X) for each color painting image X0. 1:T |X0) to process the input image. Among them, Z~DPEnc(Z|X,G) means that the DP-Encoder encoder samples from the conditional distribution DPEnc(Z|X,G); Z is the potential representation; X is the input color painting image; G is the potential diffusion model.
[0067] As a preferred embodiment of the present invention, in step S4), for each color painting image X0, a noise image sequence X1, X2, X3, X4 is generated by using a latent diffusion model. t-1 ,X t , which is from the initial color painting image X0 to the completely noisy state X t A series of intermediate states, and at each time step t, the corresponding Gaussian noise ∈ t , the Gaussian noise ∈ t The calculation formula is:
[0068] ∈ t =X t-1 -μ T (X t , t) / σ t ;
[0069] Where, X t-1 represents the noise image at time t-1, X t represents the noise image at time t, μ T Represents the current noise image state X t and the mean function at time step t, σ t represents the noise intensity at time step t.
[0070] Then the Gaussian noise ∈ t Combined with the noise image sequence, a latent code Zt is generated. t The calculation formula is:
[0071]
[0072] In the formula, Z t is the potential code at time t; Z t-1 is the potential code at time t-1; β t is the noise level at time t, ∈ is the real noise;
[0073] By gradually transforming the latent representation from a state close to the original data to a more random state, Z tGradually loses its similarity to the original data and instead contains more random noise components; in the forward diffusion process, the potential code Z of each step is recorded t .
[0074] As a preferred embodiment of the present invention, in step S4), the expression of the objective function of the forward noise diffusion processing of the potential model is:
[0075] L LDM =E x ,∈~N(0,1),
[0076] Where, L LDM is the loss function of the latent diffusion model, E x To perform the desired processing on the real image data x, ∈~N(0,1) indicates that the real noise ∈ is sampled from the standard state distribution N(0,1); ∈ θ To predict the noise, Z t for latent coding;
[0077] By starting with the real color painting image data x, adding noise to it, we generate the latent code Z t , simulate the intermediate state of the diffusion process, calculate the real noise ∈ and the predicted noise ∈ θ (Z t ,t), the smaller the Euclidean distance is, the more accurate the prediction result of the noise is.
[0078] As a preferred embodiment of the present invention, in step S5), the reverse denoising diffusion process refers to using a U-Net network to transform the latent code Z containing noise into t The U-Net network uses its internal cross-attention layer to integrate external condition information, and the QKV mechanism is used to adjust each step of denoising according to external information. Figure 3 shown.
[0079] As a preferred embodiment of this invention, in step S5), if Figure 4 As shown, this embodiment is from the state Z of the noise t Initially, the U-Net network predicts the noise ∈ t , and then gradually restore the previous state Z using the following denoising formula t-1 :
[0080]
[0081] In the formula, Z t-1 is the potential code at time t-1, Z tis the potential code at time t, β t is the noise level at time t, U(Z t ,t) is the current latent code Z at a given time step t t Denoised estimate of the U-Net network output under the condition of .
[0082] As a preferred embodiment of this invention, in step S6), the conditional mechanism is a cross attention mechanism, and the U-Net network backbone is enhanced by the cross attention mechanism, such as Figure 5 As shown, this embodiment introduces a text encoder to encode the text description of the source image and the description information of the target text into an intermediate representation τ θ ; and the intermediate representation τ is transformed through the cross attention mechanism θ Mapped into the middle layer of the U-Net network, where the Q value comes from the potential code, and the K and V values come from the conditional mechanism, namely:
[0083]
[0084] In the formula, Attention(Q, K, V) represents the output of the attention mechanism, where Q, K, and V are the query matrix, key matrix, and value matrix respectively; softmax is a normalization function that converts the input into a probability distribution. represents the scaling factor in the attention mechanism, d is the dimension of the query matrix Q and the key matrix K, which is used to prevent the dot product value from being too large; T represents the transpose operation, denote the parameter matrices of Q, K and V respectively, represents the potential code z t The intermediate representation of the i-th layer; τ θ (y) represents the intermediate representation of the conditional input y mapped by the text encoder;
[0085] In the image generation process, the color painting image is assisted in being generated according to the given text conditions, thereby achieving high-quality conversion of the color painting image with text prompts.
[0086] As a preferred embodiment of this invention, in step S6), the loss function of the reverse denoising process of the potential diffusion model is expressed as:
[0087] L LDM =E x ,∈~N(0,1),
[0088] Where, L LDM is the loss function of the latent diffusion model, E x Indicates the expected processing of the real image data x, that is, the average of all training data, ∈~N(0,1) indicates that the real noise ∈ is sampled from the standard state distribution N(0,1), ∈θ represents the prediction noise; τ θ (y) represents the intermediate representation of condition y; Z t represents the latent code at time step t.
[0089] The above embodiments and descriptions are only for illustrating the principles and best embodiments of the present invention. Without departing from the spirit and scope of the present invention, the present invention may be subject to various changes and improvements, all of which fall within the scope of the present invention to be protected.
Claims
1. A color painting generation method based on a latent diffusion model, characterized in that: The following steps are involved: S1), build a color painting dataset; S2), constructing a potential diffusion model network including a DP-Encoder encoder and a U-Net network; S3), using the DP-Encoder encoder to encode the input color painting image into a potential representation Z; S4), during the encoding process, the DP-Encoder performs forward noise diffusion processing on the input color painting image to simulate the image degradation process; a series of noise images are generated by gradually transforming Gaussian noise and the color painting image; then the DP-Encoder generates a potential code Zt using the relationship between the noise image and the Gaussian noise; S5), using the U-Net network to perform reverse denoising diffusion processing on the noisy latent coding image after the forward denoising diffusion processing, and gradually restore the noisy latent coding to the original data or generate a new data variant; S6), after the reverse denoising diffusion process, the conditional mechanism is used to guide the denoising process to obtain the potential representation of the denoised image, and then the U-Net network is used to decode the potential representation of the denoised image to obtain the final target watercolor image.
2. The method for generating a color painting based on a latent diffusion model according to claim 1, characterized in that: In step S1), the color painting data set includes color paintings, text descriptions of source images and descriptions of target texts.
3. The method for generating a color painting based on a latent diffusion model according to claim 1, characterized in that: In step S4), the DP-Encoder samples Z~DPEnc(Z|X,G), and then defines the posterior distribution q(X 1:T |X0) to process the input image; For each color painting image X0, a noise image sequence X1...,X t-1 ,X t , which is from the initial color painting image X0 to the completely noisy state X t A series of intermediate states, and at each time step t, calculate the Gaussian noise ∈ t , and then the Gaussian noise ∈ t Combined with the noisy image sequence, the latent code Zt is generated.
4. The method for generating a color painting based on a latent diffusion model according to claim 3, characterized in that: In step S4), using Update the potential representation, integrate the denoising estimate into the current potential code, gradually establish a mapping path from noise to clear image, and finally output the potential code Z t .
5. The method for generating a color painting based on a latent diffusion model according to claim 4, characterized in that: In step S4), the Gaussian noise ∈ t The calculation formula is: ∈ t =X t-1 -m T (X t ,t) / s t ; Where, X t-1 represents the noise image at time t-1, X t represents the noise image at time t, μ T Represents the current noise image state X t and the mean function at time step t, σ t represents the noise intensity at time step t; The potential code Z t The calculation formula is: In the formula, Z t is the potential code at time t; Z t-1 is the potential code at time t-1; β t is the noise level at time t, ∈ is the real noise; By gradually transforming the latent representation from a state close to the original data to a more random state, Z t Gradually loses its similarity to the original data and instead contains more random noise components; in the forward diffusion process, the potential code Z of each step is recorded t .
6. The method for generating a color painting based on a latent diffusion model according to claim 5, characterized in that: In step S4), the expression of the objective function of the forward diffusion process is: Where, L LDM is the loss function of the latent diffusion model, E x To perform the desired processing on the real image data x, ∈~N(0,1) indicates that the real noise ∈ is sampled from the standard state distribution N(0,1), ∈ θ To predict the noise, Z t For latent coding; By starting with the real color painting image data x, adding noise to it, we generate the latent code Z t , simulate the intermediate state of the diffusion process, calculate the real noise ∈ and the predicted noise ∈ θ (Z t ,t), the smaller the Euclidean distance is, the more accurate the prediction result of the noise is.
7. The method for generating a color painting based on a latent diffusion model according to claim 6, characterized in that: In step S5), the reverse denoising process uses a U-Net network to convert the latent code Z containing noise into t Restore to a noise-free potential code Z0 close to the original; the U-Net network uses its internal cross-attention layer to integrate external condition information, and through the QKV mechanism, each step of denoising is adjusted according to external information.
8. The method for generating a color painting based on a latent diffusion model according to claim 7, characterized in that: In step S5), from the state Z of the noise t Initially, the U-Net network predicts the noise ∈ t , and then gradually restore the previous state Z using the following denoising formula t-1 : In the formula, Z t-1 is the potential code at time t-1, Z t is the potential code at time t, β t is the noise level at time t, U(Z t ,t) is the current latent code Z at a given time step t t Denoised estimate of the U-Net network output under the condition of .
9. The method for generating a color painting based on a latent diffusion model according to claim 8, characterized in that: In step S6), the conditional mechanism is a cross attention mechanism, which enhances the U-Net network backbone through the cross attention mechanism, and introduces a text encoder to encode the text description of the source image and the description information of the target text into an intermediate representation τ θ ; and the intermediate representation τ is transformed through the cross attention mechanism θ Mapped into the middle layer of the U-Net network, where the Q value comes from the potential code, and the K and V values come from the conditional mechanism, namely: In the formula, Attention(Q, K, V) represents the output of the attention mechanism, where Q, K, and V are the query matrix, key matrix, and value matrix respectively; softmax is a normalization function that converts the input into a probability distribution. represents the scaling factor in the attention mechanism, d is the dimension of the query matrix Q and the key matrix K, which is used to prevent the dot product value from being too large; T represents the transpose operation, denote the parameter matrices of Q, K and V respectively, Represents the potential code Z t The intermediate representation of the i-th layer; τ θ (y) represents the intermediate representation of the conditional input y mapped by the text encoder; In the image generation process, the color painting image is assisted in being generated according to the given text conditions, thereby achieving high-quality conversion of the color painting image with text prompts.
10. The method for generating a color painting based on a latent diffusion model according to claim 9, characterized in that: In step S6), the loss function of the reverse denoising process of the potential diffusion model is expressed as: Where, L LDM is the loss function of the latent diffusion model, E x Indicates the expected processing of the real image data x, that is, the average of all training data, ∈~N(0,1) indicates that the real noise ∈ is sampled from the standard state distribution N(0,1), ∈ θ represents the prediction noise; τ θ (y) represents the intermediate representation of condition y; Z t represents the latent code at time step t.
Citation Information
Cited By
Improved plant disease data enhancement method
CN119228678A
Data intelligent security protection method and system for computer terminal data interaction
CN119622714A
Data Intelligent Security Protection Method and System for Computer Terminal Data Interaction
CN119622714B
Graph-graph conversion method and device for fine tuning by using noise control module and diffusion model principle
CN121073754A
Graph-to-graph conversion method and apparatus using noise control module and diffusion model principles for fine tuning
CN121073754B
