Training-free Color-Style Disentanglement for Constrained Text-to-Image Synthesis
Aishwarya Agarwal Srikrishna Karanam Balaji Vasan Srinivasan







[

Training-free Color-Style Disentanglement for Constrained
 Text-to-Image Synthesis
    Aishwarya Agarwal, Srikrishna Karanam, and Balaji Vasan Srinivasan

Adobe Research, Bengaluru India 

.7{aishagar,skaranam,balsrini}@adobe.com

    September 9, 2024
===================================================================================================================================================



 type=figure
 
    < g r a p h i c s >

 

 We propose the first training-free approach to allow disentangled conditioning of text-to-image diffusion models on color and style attributes from reference images.
 


]

empty

§ ABSTRACT 
We consider the problem of independently, in a disentangled fashion, controlling the outputs of text-to-image diffusion models with color and style attributes of a user-supplied reference image. We present the first training-free, test-time-only method to disentangle and condition text-to-image models on color and style attributes from reference image. To realize this, we propose two key innovations. Our first contribution is to transform the latent codes at inference time using feature transformations that make the covariance matrix of current generation follow that of the reference image, helping meaningfully transfer color. Next, we observe that there exists a natural disentanglement between color and style in the LAB image space, which we exploit to transform the self-attention feature maps of the image being generated with respect to those of the reference computed from its L channel. Both these operations happen purely at test time and can be done independently or merged. This results in a flexible method where color and style information can come from the same reference image or two different sources, and a new generation can seamlessly fuse them in either scenario (see Figure <ref>).








§ INTRODUCTION





We consider the problem of conditioning the text-to-image class of diffusion models <cit.> on color and style attributes extracted from a user-provided reference image. In particular, we want to independently control outputs of text-to-image models with either or both of these attributes, necessitating disentangled color and style conditioning. Furthermore, we seek to do so in a completely training-free and test-time-only fashion. This is practically an important problem since (a) such disentangled control means color and style information can now come from two different sources, and a new generation conditioned on them can be fused to produce an image with color from the first source and style from the second source, and (b) a test-time and training-free solution means one does not have to keep training models each time reference images change.



While there has been much work in customizing text-to-image generation <cit.> with reference images, most of these techniques lack explicit control over which attributes from the reference are to be reflected in the synthesized images. Further, while there have been some attempts at training-free customization approaches, they all focus on a specific aspect, e.g., appearance transfer <cit.> or style transfer <cit.> or ensuring subject consistency <cit.>. None of these training-free methods are able to achieve disentangled attribute transfer that we seek to achieve in our work. Next, training-based methods such as MATTE <cit.> proposed a way to allow attribute-conditioned image synthesis but it needed (a) optimizing textual tokens that may take hours depending on compute and reference image, and (b) a separate custom loss function to achieve disentanglement between color and style. Some other training-based methods such as ProSpect <cit.>, while doing multi-attribute conditioning, are also not able to disentangle color and style despite training tokens.  Consequently, we ask, and answer affirmatively, two key questions- (a) can we achieve test-time-only conditioning of text-to-image models with color and style attributes from reference images? and (b) can we do (a) with disentangled control of color and style? 







We begin with a brief discussion on why recent training-free methods such as <cit.> do not achieve disentangled attribute transfer. This method proposed to capture the customized concept by transfering keys and values computed from the reference image. Given observations from prior work <cit.> the color attribute is captured during the initial denoising stages and style in the later steps, a natural way to repurpose <cit.> for our task is to restrict these key-value operations to specific timesteps depending on the attribute we seek to transfer. We show some results with this approach in Figure <ref>. As can be noted from these results, the attribute transfers are far from desirable. This is because color transfer using the key-value operations of <cit.> is limited by the quality of semantic correspondences between the reference image and the current generation. On the other hand, transferring style by simply limiting key-value copy to the last denoising timesteps is insufficient since by then features would have sufficiently entangled color and style information. Consequently, it is critical to disentangle these attributes in the feature space in a principled fashion to be able to achieve multi-attribute transfer at test time.




To address the aforementioned issues, we propose the first training-free method to enable disentangled control over color and style attributes from a reference image when generating new images. To extract and transfer the color attribute from a reference image, we propose to modify the latent codes during denoising using a novel correspondence-aware recoloring transformation. Our key intuition is there naturally exist color clusters in the reference image, and ensuring regions with the dominant color populations from reference correspond to regions in the image being generated will lead to meaningful color transfer. Given a color clustering of the reference image, we realize this by picking a certain denoising timestep, decoding the latent code, clustering the image, establishing a correspondences between the two sets of clusters, and performing a correspondence-aware whitening and recoloring feature transformation on the latent codes. At the end of the denoising process, the final latent code when decoded will give a new image with colors from the reference image. For instance, see first row/first column in Figure <ref> where the bird follows the colors of the shirt. Next, to transfer style and disentangle it from the color attribute, we propose two innovations. First, we observe that there exists an inherent disentanglement between these two attributes in the LAB color space where the L channel contains content and style information and the A/B channels the color information <cit.>. See Fig <ref> where we also show this qualitatively. In each row, we take the L channel from the image shown in the first column (after converting the RGB image shown into LAB), the A/B channels from the second column, and merge them, giving the result in the third column. In the first row, we see the style from the first column and the colors (blue) from the second column get captured in the resulting bird image. Similarly, in the third row, despite the second column having certain textured patterns, only the color (yellow) gets transferred to the resulting image. Next, noting that style mostly gets captured during the later denoising steps, we propose a time-step-constrained feature manipulation strategy. We do this by first generating an image with the baseline model and the desired prompt, and store the A/B channels. We then transfer style using the L channel from the reference image by aligning the self-attention key-value feature maps of the reference with those of the current generation, copy the A/B channels from the above operation and obtain the final result. See some results with our method in Figure <ref> where in each case, our method is able to respect both color and style references in the final outputs. For instance, the first row has a “a bird" image following the blue/yellow colors from the color reference and origami style, the second row has the bird in blue/yellow colors and watercolor style, and so on.



To summarize, our key contributions in this work are:

    
  * We present the first training-free method to disentangle and control text-to-image diffusion models on color and style attributes from a reference image.
    
  * We propose a new time-step-constrained latent code recoloring transformation that aligns the covariance matrices of a text-to-image model output with that a reference image, helping transfer reference colors to outputs of text-to-image models.
    
  * We notice that the L channel in the LAB space has an inherent separation between style and color and propose a new time-step-constrained self-attention key and value feature manipulation algorithm to transfer style from a reference image.






§ RELATED WORK

With the wide adaptation of diffusion models for text-to-image synthesis <cit.>, much recent effort has been expended in controlling the outputs of these models. These efforts largely focus on learning adapters <cit.> given baseline text-to-image models, finetuning parameters of the base model<cit.>, learning new tokens in the vocabulary of these models <cit.>, introducing dedicated personalization encoders <cit.>, utilising LoRA <cit.> to encapsulate target information <cit.>, and inpainting-based approaches <cit.>. With the exception of MATTE <cit.>, none of these methods are able to achieve disentangled transfer between color and style of a reference image. However, MATTE <cit.> needs custom loss functions and hours of training per reference image, which is practically infeasible. 

On the other hand, there is a new line of recent work that involves training-free approaches to customization <cit.>. However, these methods focus on one specific aspect (e.g., appearance transfer, style transfer, or subject consistency) and are not able to provide independent disentangled control over color and style attributes.  Similarly, the non-diffusion based conventional style transfer methods AesPA-Net<cit.>, StyTR2<cit.>, and ArtFlow<cit.> target disentanglement of content and style, while style and color are not treated independently/separately in these works. We address these gaps in both training-based and training-free methods by proposing the first training-free method to provide disentangled control for text-to-image models over color and style attributes from reference images. Moreover, our proposed approach is not specific to any dataset, and can seamlessly adapt to various styles/content due to the base model's capability.




§ APPROACH


We start with a brief review of latent diffusion models (LDMs). LDMs comprise an encoder-decoder pair and a separately trained denoising diffusion probabilistic model (DDPM). Leveraging an encoder 𝐄, LDMs translate an image 𝐈 into a latent code 𝐳, perform iterative denoising, and subsequently convert the predicted latent codes back to the pixel space via the decoder 𝐃. The training objective of the DDPM ϵ_θ is the following: 𝔼_𝐳∼𝐄(𝐈),p,ϵ∼𝒩(0,1),t[ϵ - ϵ_θ^(t)(𝐳_t, 𝐋(p))]
where p denotes any external conditioning factor e.g., a text prompt, which is typically encoded using text encoder 𝐋 (e.g., CLIP <cit.>, T5 <cit.>). At any timestep t of the denoising process, given the current latent code z_t, the goal is to produce z_t-1.  The first step here is to predict the noise ϵ_θ^(t)(𝐳_t, 𝐋(p)). Given z_t and ϵ_θ^(t)(𝐳_t, 𝐋(p)), deterministic DDIM <cit.> sampling gives z_t-1 as


    z_t-1 =  √(α_t-1) z_0 + x̂_t

 
where z_0 (denoised prediction) is predicted as z_0 = z_t-√(1-α̅_t)ϵ_θ^(t)/√(α̅_t), and x̂_t (direction pointing to x_t) is computed as x̂_t = √(1-α_t-1-σ_t^2)ϵ_θ^(t).





 §.§ Disentangled Color and Style Conditioning




As discussed in Section <ref>, we seek to provide text-to-image models with disentangled control over  and  attributes extracted from user-supplied reference images. To do this, we  propose a new training-free algorithm that facilitates any of color-only, style-only, or both color-style transfer from reference images. We achieve this with a two-branch architecture (see Figure <ref>), one each for color and style. As we discuss later, outputs from these branches can be used independently (for single attribute transfer) or can be merged seamlessly. This merging can happen with color and style from the same source (one reference image) or color from one image and style from another image (see Fig <ref> again where we show both single-source and two-source results).

Our closest training-free baselines <cit.> inject key and value feature maps from self-attention blocks of the U-Net from the reference image. However, this only helps transfer the overall appearance/identity and cannot control color and style. To fix this gap, we propose two ideas. First, given color information from a reference image, we propose to apply recoloring transformations on the intermediate latent codes which when decoded can give an image following reference colors. Next, we notice that (a) style information gets captured only during the later parts of the denoising process and (b) style is captured in the L channel when an image is converted from the RGB to the LAB space (see Section <ref> and Fig <ref> again). We exploit these two observations to propose a timestep-constrained key and value feature manipulation strategy in the L space where features during early denoising steps are retained as is from the baseline generation and those of later steps are carried over from the reference image. We next explain the details of these ideas. 


 
Color conditioning.
Our proposed method is visually summarized in the  branch in Figure <ref>. We first do a DDIM inversion step on the reference image to obtain the corresponding latent z_t^ref. Once the denoising process begins given a user-specified text prompt, given a latent z_t at timestep t, the DDIM sampling will compute the noise prediction ϵ_θ^(t), followed by computing the z_0 for both the reference image and the new generation. We then decode the latent code z_0 using the decoder 𝒟(.) (see Figure <ref> for an example where we visualize these for several intermediate denoising timesteps). Given a timestep t, we first perform a K-Means clustering operation on both the decoded image I_0^(t)_gen and the reference image to obtain sets of K color clusters 𝒞_gen and 𝒞_ref respectively. Note that one can mask the decoded latent with cross-attention maps to restrict the object of interest in both the new generation as well as the reference image. Given the cluster sets, we next establish correspondences between them based on their proportion, giving a set of masks ℳ_ref and ℳ_gen for each set. The idea here is that a color cluster with the largest membership in the reference image indicates the dominant color that we seek to transfer to the current generation.  
Given the masks above, we achieve this by applying a mask-aware recoloring transformation (RT) on the latent code z_0^(t)_gen as:


    z_0^(t)_gen =    ∑_ m_gen^i ∈ℳ_gen
     m_ref^i ∈ℳ_ref
      1 ≤ i ≤ k{( 1-m_gen^i ) z_0^(t)_gen
        + m_gen^i [RT(m_gen^i z_0^(t)_gen, m_ref^i z_0^(t)_ref) ] }



Here, we iterate over all the K clusters and apply the recoloring transform separately to regions determined by masks corresponding to each cluster. In each iteration i, we use the corresponding mask m_gen^i to constrain the region where color transfer happens, and similarly m_ref^i determines the reference pixels from where the colors are picked. This way, we ensure that in any iteration i, pixels outside the region of interest (determined by the m_gen^i) remain untouched. The recoloring transformation <cit.> itself is a two-step process. We first whiten the latent codes to get its covariance matrix to be identity. We then apply a transformation to match the covariance matrix of the latent codes to match that of the reference image (z_0^(t)_ref). To ensure this operation strictly transfers color only and not style, we use observations from prior work <cit.> that note color is captured during the early parts of the denoising process. Consequently, we restrict Eq <ref> to only a subset of the initial denoising timesteps t_start^c>t>t_end^c.

The updated z_0^(t)_gen obtained in Equation <ref> is then used along with the predicted noise ϵ_θ^t to compute z_t-1^gen (using Equation <ref>) which goes as input to the next denoising step, eventually generating an image which follows the color from the reference image. 
We show an example demonstrating the progression of decoded latents I_0^(t)_gen across denoising timesteps in Figure <ref>. Here given the prompt , one can observe that the model very initially starts forming some colors ( here). We transform the intermediate latents to manipulate these colors using the steps described above and obtain a  bird following the blue cat in the color reference image shown in the figure.






Style conditioning. Given that high-frequency details like  and  shows up in the later denoising timesteps <cit.>, we begin by injecting key and value feature maps from the reference image to the current generation for only the last few (t > t^s_start) denoising timesteps. However, an issue with this approach is the feature maps in the later timesteps will have color information as well (since color would have been captured in the beginning), leading to entanglement of color and style. See the “Resulting image (style repurposed)" column in Fig <ref> for results with this approach- clearly both style and colors are getting transferred in this case, e.g., bird has both the watercolor style and the light pink colors from the “reference" image. To be able to disentangle style from color and allow independent control of the text-to-image diffusion model, our key insight is that there exists an inherent separation between style and color in the LAB space. The L channel captures the content and style, whereas the AB channels have color information (recall our discussion of Figure <ref> in Section <ref>). Since diffusion models are generally trained to operate in the RGB space, we take the grayscale version of the reference as an approximation to the L channel for all the next steps below (see Fig <ref> again for a visual summary). We begin by DDIM inverting the reference to get the latent z_t^ref. Given any user-specified text prompt (e.g., ), for each denoising timestep t < t^s_start, we denoise the input latent codes as in a baseline text-to-image model but once we hit t > t^s_start, we start injecting the self-attention key K and value V feature maps from the reference reconstruction after converting it to grayscale and DDIM inverting it as noted above. Formally, this modified self-attention feature map computation at any denoising timestep t and layer l of the U-Net can be expressed as:



    f̂_t^l =     1_0 ≤ t < t^s_start softmax( Q_gen^l K_gen^l^T√(d_k) V_gen^l ) 
        + 1_t > t^s_start softmax( Q_gen^l K_ref^l^T√(d_k) V_ref^l )



where 1 is an indicator, and Q_gen^l K_gen^l V_gen^l and Q_ref^l K_ref^l V_ref^l denote l^th U-Net layer self-attention queries, keys, and values for the generation and reference respectively. We then take the final latent code, decode it to get an image, convert it to the LAB space, retain the L channel and get the AB channels from the corresponding color branch of Figure <ref>.



Note that t_end^c (=T/5) is strictly less than t>t_start^s (=4T/5) throughout (i.e. the timestep intervals for which color and style conditioning is applied have no overlap), where T denotes the total number denoising steps.



§ RESULTS






Qualitative Evaluation. In addition to the results in Figure <ref>, we show more results with our method in Figure <ref> (color and style reference in the first two columns and our results in columns three-four) to demonstrate disentangled transfer of color and style attributes from reference images. We show different combinations of control over color and style attributes. In the first row, we are able to generate images following the content from the prompt (, ) while following the style and color from the provided reference images.  
In the last two rows, our method generates images following style or color from the reference while imposing no control over the other attribute (observe the straight and sharp edges in dog's outline in the last row). 
















We next compare our method with various baselines including training-free style transfer (Cross-Image <cit.>, StyleAlign <cit.>, FreeDoM <cit.>) in Figure <ref>, conventional diffusion-free style transfer baselines (AesPA-Net<cit.>, StyTR2<cit.>, and ArtFlow<cit.> in Figure <ref>), training-free color transfer (Cross-Image <cit.>, FreeDoM <cit.>) in Figure <ref>, and training-based techniques such as MATTE <cit.> and ProSpect <cit.> in Figure <ref>.

We begin by discussing disentangled style transfer results in Figure <ref>. One can note that our method is able to generate images (see last column) following the style from the reference image in a disentangled manner without affecting any other aspect of what the baseline generates (See Figure <ref> for zoomed in section of images for the first/second rows of origami style transfer). On the other hand, as expected, the Cross-Image baseline transfers the full appearance of the reference image. One can also notice missing regions in the bucket image in fourth row/fifth column due to lack of semantic correspondences. Similarly, the repurposed style version of cross-image baseline, while doing better, can not fully disentangle style from color as the features already have color information by the time style transfer happens during denoising. In StyleAlign, in addition to the style and color being entangled, the algorithm also transfers the structural/layout aspects of the reference image, thereby limiting the kind of control with style we seek over the final outputs (see fourth row/third column, where it tries generating bucket images following the layout of the cat from the reference image). Finally, FreeDoM also entangles color and style because its loss function does not account for any explicit disentanglement of these attributes.

We also compare with conventional style transfer methods in Figure <ref>. The baselines are able to preserve input content, but the transfer of style (e.g. van-gogh patterns in first row) is limited. Since these methods target disentanglement of content and style, style and color are not treated independently/separately, leading to undesirable results (e.g. see the first row/second-third columns where the result flower vase has blue/orange colors from the style reference whereas our method in the last column is able to fix this issue). Finally, while these methods are trained on specific datasets, our method is training free and not specific to any dataset, and can seamlessly adapt to various styles/content due to the base model's capability.


We next discuss disentangled color transfer results in Figure <ref>. In all cases, our method is able to correctly transfer the color from the reference image whereas the cross-image (original) baseline transfers the full appearance from the reference image and can not control the color attribute independently (see third/fourth rows where the generated birds have a cloth-like appearance). Similarly, the repurposed color version of cross-image baseline, while disentangling color and style, is unable to produce good results due to lack of correspondences. 
With FreeDoM, in some cases there is overfitting to the colors during optimization while disregarding the overall aesthetics, whereas in several other cases, the generated images disregards reference colors (the birds in last row/second column) due to incorrect optimization. Our method is able to control and transfer color attribute independently without affecting any other aspects of what the pretrained model would have generated. 

Finally, in Figure <ref>, we compare to recent training-based methods. In ProSpect <cit.>, one can see color and style are completely entangled (e.g., first column where both color and style are transferred). On the other hand, despite our method being completely training free, it performs at par with MATTE <cit.> which is a training-based approach (e.g., first column with our orange dogs). In the second column, whereas both MATTE and ProSpect entangle color and style, our method is able to generate van gogh-styled dogs without the bluish-orange colors.

Quantitative Evaluation. We next quantify improvements with our proposed method. We wish to evaluate how well these methods disentangle style and color (we follow the protocol from MATTE <cit.>), while also following the details specified as part of the text prompt. We keep either of the attributes (out of style/color) fixed from a reference image (we use the same set as in <cit.>) and vary the other (we use the list of 7  types, 13  types and 11  types from previous works <cit.>). In each case, we synthesize a set of 64 images and compute the average CLIP image-text similarity. A higher score indicates better disentanglement since both attributes would then be separately captured well in the output. 

To further evaluate the quality of transfer of each attribute, we also compute similarity scores between the ground truth color/style (color obtained using ColorThief <cit.>) and the generated images. As can be seen from Table 1, our method outperforms all training-free baselines and allows for independent control over style and color attributes. Further, when compared to the training-based MATTE <cit.>, our method performs very competitively despite being training free. 
Finally, we conduct a user study with the generated images where we show survey respondents a textual prompt followed by color and style references, and ask them to select the images (among sets from four different methods) that best follow the provided constraints. From Table 2, our method's results are preferred by a majority of users, providing additional evidence for effectiveness of the proposed approach. 










§ SUMMARY


We considered the problem of disentangled color and style control of text-to-image models and noted none of the existing methods address this problem with a training-free approach. To this end, we proposed the first training-free, test-time-only solution with two key novelties: a timestep-constrained latent code recoloring transformation that aligned colors of generation outputs with reference colors and a timestep-constrained self-attention feature manipulation strategy in the L channel of the LAB space that aligned generation the style of generation outputs with that of the reference. This resulted in a flexible approach that can do color-only, style-only, or both color-style conditioning in a disentangled and indepedent fashion. Extensive qualitative and quantitative evaluations demonstrated the efficacy of our proposed method.











§ 

In Section <ref>, we validate our choice of using a grayscale version of the provided reference image compared to the colored reference image. In Section <ref>, we show additional results for disentangled conditioned on color and style attributes from a user-provided reference image. In Section <ref>, we show applicability of our proposed color conditioning in generating color variants of a given image. In Section <ref>, we show additional results for transfer of style attribute from a reference image. Finally, we conclude with some discussion on
limitations of our method in Section <ref>.



 §.§ Style conditioning with colored reference


We experimented with taking the original (colorised) reference image instead of using its' grayscale counterpart. But we observed that the presence of color information in the reference image, leads to the intensity of colors being modified in the generated image, thereby leading to differences in lightness/darkness of some colors. We show some examples for the same in Figure <ref>. This further validates our choice of using a grayscale reference while transferring style.




 §.§ Additional Qualitative Results


We show additional qualitative results in Figure <ref> to further demonstrate the efficacy of our method in generating images conditioned on either of color or style attribute independently, or both color and style in a joint manner. In the first row, we show results for transferring colors from both background (bg) and foreground (fg) of the reference image to localised regions like the badminton, vase, and the ball in the generated images respectively. In the second row, we show results for global transfer of style from the reference image and as one can clearly note, the van gogh styled patterns are clearly visible in the generated images. Finally, in the third row, we generate images conditioned on both color and style attribute (e.g. see third column/last row where the ball has blue color transferred and the image follows van gogh style).




 §.§ Generating color variants


We show additional color transfer results in Figure <ref> while demonstrating its' utility in generating multiple color variants of a provided input image. We consider different colors (blue, green, red) and their combinations and show that our proposed method can effectively transfer color and all cases to the input image. For instance, note the first rows have the individual colors transferred for all of bird, cup toy car and ball. Similarly the rows 4-6 have combinations of two colors transferred, whereas the last row has all three colors (e.g. see first column where the generated bird has proportions of all three colors).





 §.§ Additional Style transfer results



In Figure <ref>, we show additional results to further demonstrate the effective of our proposed approach in transferring style from reference images in a disentangled manner without having an impact on the colors of the generated image. For instance, consider the last column where the reference image has a repeated squarebox type pattern. One can clearly note that all our generated images as well show the same pattern while still maintaining the colors from the original image.





 §.§ Limitations


In this Section, we briefly discuss a few limitations of the proposed approach. Firstly, as shown in Figure <ref>, the recoloring transforms in some cases lead to a loss of minute details e.g. bird's eye and details on the dog's face. Secondly, the masks obtained for the region of interest to be recolored are obtained using the cross-attention layers which, as shown in previous works <cit.> as well, do not always accurately localize the region. In such a case, one can use high quality off-the-shelf methods <cit.> to obtain segmentation masks for improved localised color and style transfer. 







ieee_fullname




