Continuous Layout Editing of Single Images with Diffusion Models

Zhiyuan Zhang, Zhitong Huang, Jing Liao

Abstract

While text-to-image diffusion models have achieved remarkable success in generating high-quality imagery, precise spatial control over existing images remains a significant challenge. Current layout-to-image frameworks are primarily designed for generation from scratch, often failing to preserve the unique visual identity of specific objects when their positions are modified. This paper introduces a novel framework for continuous layout editing that enables the rearrangement of multiple objects within a single image while strictly maintaining their appearance and background consistency. By combining masked textual inversion with a training-free iterative latent optimization process, we demonstrate superior performance in object disentanglement and layout fidelity compared to existing baselines.

Introduction

State-of-the-art diffusion models like Stable Diffusion allow for impressive creative output, yet they lack the granular control required for practical image editing. Specifically, "layout-to-image" tools such as GLIGEN or ControlNet can place objects within defined bounding boxes, but they generate new instances of those objects every time the layout changes. If a user wishes to move a specific cat from a rug to a sofa in an existing photograph, these models typically replace the original cat with a different one.

This limitation stems from two primary hurdles: disentanglement and layout fidelity. Disentanglement requires the model to learn the distinct visual identity of multiple objects from a single reference image without their features bleeding into one another. Layout fidelity requires the diffusion process to respect new spatial coordinates without introducing artifacts or losing the fine-grained details of the original subjects.

Methodology

The proposed framework addresses these challenges through a two-stage pipeline: identity preservation and spatial steering.

1. Masked Textual Inversion and Fine-tuning

To capture the identity of objects within a single image, the system employs Masked Textual Inversion. Standard textual inversion learns a pseudo-word (token) for an object by observing it across multiple images. To adapt this for a single multi-object image, spatial masks are applied to the loss function during embedding optimization. This ensures that the "cat" token only learns from pixels designated as the cat, and the "pot" token only from the pot pixels, preventing "concept bleeding."

Following the embedding optimization, a brief fine-tuning of the U-Net’s cross-attention layers is performed. This step is crucial for capturing the fine-grained textures and specific nuances of the objects that a simple token might miss.

2. Training-Free Layout Editing

Once the objects are memorized as tokens, they must be placed in a new layout. Rather than retraining the model, the framework utilizes Iterative Latent Optimization during the inference phase:

  • Cross-Attention Steering: The system leverages the fact that cross-attention maps in diffusion models represent the spatial influence of specific words. By defining a "region loss," the model penalizes instances where the attention map for a specific token (e.g., "cat") does not align with the user-defined bounding box.
  • The 16x16 Resolution Sweet Spot: Research found that layers at a 16x16 resolution contain the most meaningful semantic information. Optimizing at this specific resolution provides the ideal balance between spatial control and overall image quality.
  • Background Preservation: To maintain background consistency, the original image's latents are blended into areas not covered by the new object masks during the denoising process, ensuring a seamless transition between moved objects and the static environment.

Experimental Results

The method was evaluated on complex real-world images featuring diverse subjects, including animals, furniture, and landscapes. It was compared against modified versions of state-of-the-art frameworks such as GLIGEN, ControlNet, and MultiDiffusion.

Quantitative Performance

In user studies, the proposed method was preferred 31% of the time for visual similarity and 29% for layout alignment, significantly outperforming the GLIGEN + Textual Inversion baseline. Furthermore, the method achieved the highest scores across key metrics:

  • Visual Similarity: 0.61 (via CLIP distance)
  • Layout Alignment: 0.0099 (the lowest error rate among tested approaches)

Qualitative Advantages

Unlike "copy-paste" image manipulation, which often results in visible seams and perspective errors, this method produces harmonious results. It naturally adjusts lighting and shadows when an object is moved, ensuring the edited object looks as though it truly belongs in its new environment.

Discussion and Limitations

While the framework represents a significant step forward, certain limitations remain. Extreme Resizing can lead to a loss in fidelity, as the learned tokens may not contain enough resolution information to scale a small object to a much larger size. Additionally, Occlusion Handling remains difficult; if an object was partially hidden in the original image, the model may struggle to accurately "hallucinate" the missing parts when moved to an open space. Finally, the iterative optimization process is computationally intensive, requiring approximately 37 seconds per edit on an NVIDIA V100.

Conclusion

This framework provides the first effective solution for continuous layout editing of single images while preserving object identity. By steering cross-attention maps and utilizing masked inversion, it bridges the gap between generative freedom and precise spatial editing. Future work will focus on accelerating the optimization process and improving the model's 3D understanding of objects to better handle rotations and occlusions.

Summary updated

BibTeX
@article{zhang2023continuous,
  author = {Zhiyuan Zhang and Zhitong Huang and Jing Liao},
  title = {{Continuous Layout Editing of Single Images with Diffusion Models}},
  journal = {Computer Graphics Forum},
  year = {2023},
  doi = {10.1111/cgf.14966},
}
Figure