Diffree: Text-Guided Shape Free Object Inpainting with Diffusion Model

Lirui Zhao, Tianshuo Yang, Wenqi Shao, Yuxin Zhang, Yu Qiao, Ping Luo, Kaipeng Zhang, Rongrong Ji

Abstract

This paper addresses an important problem of object addition for images with only text guidance. It is challenging because the new object must be integrated seamlessly into the image with consistent visual context, such as lighting, texture, and spatial location. While existing text-guided image inpainting methods can add objects, they either fail to preserve the background consistency or involve cumbersome human intervention in specifying bounding boxes or user-scribbled masks. To tackle this challenge, we introduce Diffree, a Text-to-Image (T2I) model that facilitates text-guided object addition with only text control. To this end, we curate OABench, an exquisite synthetic dataset by removing objects with advanced image inpainting techniques. OABench comprises 74K real-world tuples of an original image, an inpainted image with the object removed, an object mask, and object descriptions. Trained on OABench using the Stable Diffusion model with an additional mask prediction module, Diffree uniquely predicts the position of the new object and achieves object addition with guidance from only text. Extensive experiments demonstrate that Diffree excels in adding new objects with a high success rate while maintaining background consistency, spatial appropriateness, and object relevance and quality.

Introduction

Adding a new object to an existing image—a task known as inpainting—is a fundamental challenge in computer vision. A successful model must simultaneously solve three complex problems: Spatial Logic (determining a natural location for the object), Visual Consistency (matching lighting, texture, and shadows to the scene), and Background Preservation (ensuring the rest of the image remains untouched).

Existing tools typically fall into two categories. Mask-guided methods, such as Adobe Firefly, require users to manually define the area for the new object. Conversely, text-guided methods like InstructPix2Pix often suffer from "hallucinations" that corrupt the background or fail to place objects correctly. Diffree bridges this gap, offering the ease of text-only control with the precision of mask-based methods.

Methodology: The Object Mask Predictor (OMP)

The core innovation of Diffree is the Object Mask Predictor (OMP), a lightweight module integrated into a standard Stable Diffusion framework.

The OMP Module

Instead of relying on user-provided masks, Diffree predicts the optimal location and shape for a new object. The OMP consists of convolutional layers, ResBlocks, and attention mechanisms that process intermediate "noise-free" latent features during the diffusion process.

Joint Training and Inference

The diffusion model and the OMP are trained jointly. While the diffusion model learns to generate high-quality objects, the OMP learns to "tighten" a predicted mask around the generated content. During inference, the model predicts the mask in the early steps of the diffusion process. This mask is then used to "lock in" the spatial coordinates, ensuring that only the pixels within the mask are modified, leaving the background 100% preserved.

OABench: Learning from Inverse Removal

To train Diffree, the researchers created OABench, a high-quality synthetic dataset designed specifically for object addition. The dataset was constructed using an "inverse trick":

  1. Selection: Real images from COCO and LVIS containing various objects were selected.
  2. Removal: Advanced inpainting techniques (e.g., PowerPaint) were used to remove these objects, creating "clean" background images.
  3. Pairing: This resulted in 74,000 tuples consisting of the original image, the inpainted background, the ground-truth mask of the removed object, and a text description.

By learning from real-world photos, Diffree acquires an understanding of natural object placement and lighting (e.g., a monitor belongs on a desk) without manual labeling.

Results and Iterative Capability

Diffree was evaluated against baselines like InstructPix2Pix and PowerPaint on the COCO and OpenImages datasets. The results highlight several key strengths:

  • Success Rate: Diffree achieved a 98.5% success rate in adding objects, significantly outperforming InstructPix2Pix (17.4%), which often transformed existing objects rather than adding new ones.
  • Background Consistency: Using LPIPS metrics, Diffree demonstrated superior background preservation by using its predicted mask to protect original pixels.
  • Logical Placement: GPT-4V was utilized as a judge to rate the "reasonableness" of object placement. Diffree scored significantly higher, proving its ability to understand scene context.

Iterative Scene Composition

Because the model preserves the background so effectively, it can be used iteratively. Users can build complex scenes step-by-step—adding a sofa, then a cat, then a lamp—without the image quality degrading over time.

Iterative object addition using Diffree across two different scenes, demonstrating the model's ability to maintain consistency over 16 consecutive edits.

Conclusion

While Diffree represents a significant leap in text-guided inpainting, it is currently constrained by its base model (Stable Diffusion 1.5), which limits the rendering of complex textures or text. Additionally, extremely complex occlusions (e.g., a hand wrapping around a new object) remain a challenge. Future work involves integrating Diffree with larger models like SDXL or Flux and combining it with planning agents to create fully automated, high-fidelity photo editing tools.

Summary updated

BibTeX
@misc{zhao2024diffree,
  author = {Lirui Zhao and Tianshuo Yang and Wenqi Shao and Yuxin Zhang and Yu Qiao and Ping Luo and Kaipeng Zhang and Rongrong Ji},
  title = {{Diffree: Text-Guided Shape Free Object Inpainting with Diffusion Model}},
  year = {2024},
  eprint = {2407.16982},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2407.16982},
}
Figure