LocInv: Localization-aware Inversion for Text-Guided Image Editing

Chuanming Tang, Kai Wang, Fei Yang, Joost van de WeijerarXiv 2024 · DOI

Abstract

Text-guided image editing using diffusion models often suffers from "cross-attention leakage," where edits intended for specific objects inadvertently affect the background or adjacent elements. We present LocInv (Localization-aware Inversion), a method that leverages spatial priors—such as segmentation masks or bounding boxes—to constrain cross-attention maps during the inversion process. By optimizing tokens at each denoising step and introducing adjective-binding losses, LocInv achieves high-fidelity edits with precise spatial control. Our evaluation on the COCO-edit benchmark shows that LocInv significantly outperforms current state-of-the-art inversion techniques in both quantitative metrics and human preference.

Introduction: The Challenge of Precise Editing

Large-scale Text-to-Image (T2I) diffusion models like Stable Diffusion have revolutionized image generation. However, editing existing images remains difficult because the internal cross-attention maps—which guide the model on where to apply specific concepts—often lack precision. This "leakage" causes unintended artifacts; for instance, changing a "red apple" to a "purple apple" might turn the entire table purple. This is especially problematic in complex, multi-object scenes where the model struggles to maintain a clean separation between different elements.

Methodology: Localization-aware Inversion

LocInv addresses this by refining the image inversion process—the critical stage where a real image is mapped into the model's latent space. By fixing the attention maps during inversion, the subsequent editing steps become much more stable.

The LocInv pipeline incorporates localization priors (S) and dynamic token updates to align cross-attention maps with target regions using similarity and overlapping losses.

Key Technical Components

  1. Localization Priors: The system utilizes spatial information (segmentation masks or bounding boxes) provided by the user or generated by automated models like SAM or GroundingDINO.
  2. Dynamic Token Optimization: Instead of static embeddings, LocInv optimizes text tokens at every denoising step. It employs a Similarity Loss to minimize the cosine distance between the attention map and the prior, and an Overlapping Loss to ensure attention remains strictly within the intended boundaries.
  3. Adjective Binding: To handle attribute changes (e.g., color or material), a specialized loss binds adjectives to their nouns, ensuring that descriptors "follow" the object's spatial footprint and do not bleed into the background.

Experimental Evaluation

We evaluated LocInv using the COCO-edit dataset, a subset of MS-COCO containing 315 images across 13 editing tasks. These tasks range from simple object swaps (e.g., "dog → fox") to complex multi-object scenarios. Performance was measured using PSNR for image fidelity and LPIPS for perceptual similarity.

Results and Discussion

LocInv consistently produces cleaner edits than baseline methods like Null-Text Inversion (NTI), MasaCtrl, and DiffEdit. Visual results demonstrate that LocInv can swap objects in crowded scenes while leaving the rest of the image completely untouched.

Qualitative comparison of LocInv against various state-of-the-art methods. LocInv demonstrates superior background preservation and precise object replacement across diverse categories.

In a user study involving 20 participants, LocInv was the clear favorite. For "Edit Quality," it was preferred 40% of the time, compared to the next best method, DiffEdit, at 27%. Quantitatively, the method achieved superior scores in PSNR and LPIPS, indicating better background preservation and more accurate edits.

Conclusion and Future Work

LocInv demonstrates that incorporating localization priors during the inversion phase is key to high-quality text-guided image editing. While currently limited by the 16x16 resolution of cross-attention maps and the underlying autoencoder's reconstruction limits, future work will focus on pixel-level control and integration with more advanced frameworks to further simplify the user experience.

Summary updated

BibTeX
@misc{tang2024locinv,
  author = {Chuanming Tang and Kai Wang and Fei Yang and Joost van de Weijer},
  title = {{LocInv: Localization-aware Inversion for Text-Guided Image Editing}},
  year = {2024},
  eprint = {2405.01496},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2405.01496},
}
Figure