Coherent and Multi-modality Image Inpainting via Latent Space Optimization

Lingzhi Pan, Tong Zhang, Bingyuan Chen, Qi Zhou, Wei Ke, Sabine Süsstrunk, Mathieu Salzmann

TL;DR

PILOT (inPainting vIa Latent OpTimization) is a tuning-free framework that achieves high-quality image inpainting by optimizing latent vectors on-the-fly during the diffusion process. By using novel loss functions to balance semantic alignment and background preservation, it generates coherent, multi-modal edits in under 10 seconds without requiring expensive model retraining.

What Problem Does This Paper Address?

Image inpainting has evolved from simple "hole-filling" to complex, prompt-guided content generation. However, existing methods face a difficult trade-off. Fine-tuning models on specific tasks is computationally expensive, prone to overfitting, and often results in "domain shift" where the new content doesn't quite match the original image's style. On the other hand, blending methods (which simply stitch together noisy latent vectors) often suffer from semantic inconsistencies—the generated object might not align with the prompt, or its edges might not blend seamlessly with the background.

The authors of PILOT argue that large pre-trained diffusion models already possess the "knowledge" to perform perfect inpainting; the challenge is simply guiding the model to find the right path through its latent space.

Methods

PILOT introduces a two-stage pipeline: an Optimization Stage followed by a Blend Stage.

1. Latent Space Optimization

Instead of relying on the model's default denoising path, PILOT iteratively updates the latent vector $z_t$ during the early steps of the reverse diffusion process. This is guided by two key loss functions:

  • Background Preservation Loss ($L_{bg}$): This ensures the unmasked regions remain identical to the original image by comparing the "one-step reconstruction" ($\tilde{x}_0$) to the input image.
  • Semantic Centralization Loss ($L_s$): This leverages cross-attention maps to ensure that the influence of the text prompt is concentrated strictly within the masked region, preventing "semantic leakage" into the background.
Figure 2: Framework of our PILOT. The upper part of the image shows the full pipeline of PILOT. First we apply our latent optimization strategy, where we adjust the direction of gradients and identify the optimal latent vector every τ steps, followed by the normal reverse diffusion process. After that, we apply the latent blending strategy until the denoising process is complete. The lower part of the image shows the details of our optimization strategy. We depict how we optimize the latent vector with prompts from one or more modalities as conditions.

2. Semantic Boundary Control (SBC)

In the early stages of denoising, the model's understanding of the image layout is still "blurry." To prevent the prompt from accidentally affecting the background during these critical steps, the authors introduce SBC. This technique explicitly masks the cross-attention scores, setting background attention to zero to ensure a clean separation between the new content and the existing scene.

3. Efficiency Strategy

The authors observed that the early stages of denoising define the image's semantics, while later stages focus on fine details.

Figure 3: An example of the variation of ˜x0,t during the denoising process. In the early stages of denoising, the focus is on forming the semantics of the image, while in the later stages, the emphasis shifts to enriching the image details.

By stopping the optimization after a certain point (governed by a coherence scale parameter $\gamma$) and switching to a simple blending stage, PILOT maintains high quality while significantly reducing computational overhead.

Datasets

The researchers evaluated PILOT using:

  • MS COCO: 5,000 images from the validation set were used for text-guided inpainting benchmarks.
  • PIE-Bench: A specialized dataset for local image editing, used to measure content replacement and object surface alteration.
  • Custom Multi-modal Inputs: The authors also tested the system using sketches, Canny maps, and segmentation maps to demonstrate its versatility.

Key Insights and Ideas

  • Tuning-Free Versatility: Because PILOT optimizes the latent space rather than the model weights, it is "plug-and-play." It works seamlessly with Stable Diffusion, SDXL, and adapters like ControlNet or IP-Adapter without any additional training.
  • The Power of Cross-Attention: The paper highlights that cross-attention maps are the most effective "lever" for controlling where a prompt manifests in an image. By optimizing these maps, you can achieve much tighter control than by just manipulating pixels.
  • Semantic vs. Detail Stages: The finding that optimization is only necessary for the first 40-70% of the denoising steps is a crucial "aha moment" for making optimization-based methods practical for real-time use.

Key Results

PILOT consistently outperformed state-of-the-art (SOTA) methods like Blended Diffusion and SD-Inpaint in both qualitative and quantitative tests:

  • Quantitative: PILOT achieved the highest NIMA (visual quality) score of 5.451 and CLIP-T (text alignment) score of 0.201 on the MS COCO dataset.
  • Qualitative: As shown in the spatial control tests, PILOT generates objects that better respect complex constraints (like Canny edges) while maintaining a harmonious appearance with the background.
Figure 6: Qualitative comparison on text guided inpainting with spatial controls.
  • Human Evaluation: In user studies, participants strongly preferred PILOT for both image quality and text matching accuracy.

Limitations and Future Work

Not discussed in the paper. However, one could infer that while the method is efficient (under 10s), it still requires more computation than simple blending methods due to the gradient backpropagation steps required during optimization. Future work might explore even faster optimization techniques or applications in video inpainting.

Summary updated

BibTeX
@misc{pan2024coherent,
  author = {Lingzhi Pan and Tong Zhang and Bingyuan Chen and Qi Zhou and Wei Ke and Sabine Süsstrunk and Mathieu Salzmann},
  title = {{Coherent and Multi-modality Image Inpainting via Latent Space Optimization}},
  year = {2024},
  eprint = {2407.08019},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2407.08019},
}
Figure