FlexEdit: Flexible and Controllable Diffusion-based Object-centric Image Editing

Trong-Tung Nguyen, Duc-Anh Nguyen, Anh Tran, Cuong PhamarXiv 2024 · DOI

Abstract

Object-centric image editing—the task of modifying specific items within a scene—remains challenging for text-to-image diffusion models due to shape discrepancies and background leakage. We present FlexEdit, a framework that combines iterative latent optimization with adaptive masking to provide precise control over object replacement, addition, and removal. By nudging latents toward target spatial constraints and utilizing refined attention-based masks, FlexEdit achieves high-fidelity edits that respect both user intent and original image structure.

Introduction

While diffusion models have revolutionized content generation, granular control over specific objects remains elusive. Existing methods often struggle when the target object's geometry differs significantly from the source (e.g., replacing a round fruit with a long one), often resulting in unnatural blends. Furthermore, maintaining background integrity during such transformations is difficult. FlexEdit addresses these issues by introducing a flexible pipeline that allows for adjustments in object size and position while ensuring the background remains perfectly intact.

Methodology: The FlexEdit Block

The core innovation of this work is the FlexEdit block, integrated into the denoising process of a Latent Diffusion Model. The block operates via two primary modules:

  1. Latent Optimization: At specific denoising steps, the framework calculates the object's centroid and size from attention maps. It then applies gradient descent to align the noisy latents with user-defined spatial parameters ($L_{pos}$ and $L_{size}$). For object addition, a Separation Loss ($L_{sep}$) prevents overlap with existing scene elements.
  2. Adaptive Binary Masking: To prevent background corruption, FlexEdit generates dynamic masks by fusing cross-attention and self-attention maps. This "unify and dilate" strategy creates a mask covering both the source and target object footprints, facilitating seamless transitions.
Original image featuring a blue car in front of a house.

Key Insights

A critical finding is that raw cross-attention maps are often too imprecise for high-quality masking. FlexEdit sharpens these boundaries by multiplying cross-attention maps with self-attention maps. Additionally, the framework employs iterative nudging during the early denoising stages (steps $t=1, 10, 15, 20$), where the high-level structure of the image is established. This allows the model to gradually adapt the latent representation to the new object's geometry.

Edited image with the car replaced by a boat, showcasing background preservation.

Experimental Results

FlexEdit was evaluated on the SynO (Synthetic Object-centric), MagicO, and PieBenchO benchmarks. It consistently outperformed state-of-the-art baselines like Prompt-to-Prompt and MasaCtrl. On the SynO benchmark, FlexEdit achieved a CLIP-O score of 24.27, significantly higher than the 21.89 achieved by the next best method. Qualitative analysis confirms its ability to perform drastic shape changes—such as replacing a car with a boat—without altering the surrounding environment. Human preference studies further validate these results, with FlexEdit being preferred in over 88% of cases for semantic accuracy.

Conclusion and Future Work

FlexEdit offers unprecedented control for object-centric editing, though it currently requires more computational time (approx. 41s per edit) than instruction-based models. Future research will explore the integration of one-step diffusion models to reduce latency. Despite this, FlexEdit sets a new standard for precision and background preservation in the field of controllable image synthesis.

Summary updated

BibTeX
@misc{nguyen2024flexedit,
  author = {Trong-Tung Nguyen and Duc-Anh Nguyen and Anh Tran and Cuong Pham},
  title = {{FlexEdit: Flexible and Controllable Diffusion-based Object-centric Image Editing}},
  year = {2024},
  eprint = {2403.18605},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2403.18605},
}
Figure