NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

MagicEraser: Erasing Any Objects via Semantics-Aware Control

Fan Li, Zixiao Zhang, Yi Huang, Jianzhuang Liu, Renjing Pei, Bin Shao, Songcen Xu

Abstract

MagicEraser is a specialized diffusion-based framework designed for the task of object erasure—removing specific objects and replacing them with seamless, harmonious backgrounds. By integrating a novel data construction strategy with semantics-aware attention control, the framework prevents the common issue of "hallucinating" new objects into the empty space. MagicEraser demonstrates superior performance over existing state-of-the-art academic models and commercial tools like Adobe’s Generative Fill.

Introduction

While image inpainting has been a long-standing research area, the specific sub-task of object erasure presents unique challenges. Traditional GAN-based methods, such as LaMa, are computationally efficient but often struggle with complex textures, leaving behind blurry artifacts. Conversely, modern Diffusion Models (e.g., Stable Diffusion) are frequently "too creative," hallucinating new foreground objects in the masked area instead of generating a clean background. This "foreground bias" often requires complex manual prompting to overcome.

Figure 1: Visual comparison of object erasure challenges, illustrating the progression from masked input to various generative attempts and the final clean background.

Methodology

MagicEraser addresses these issues through a two-phase pipeline that balances structural guidance with high-quality generative refinement.

Stage 1: Content Initialization

To avoid the unpredictability of starting from pure Gaussian noise, MagicEraser utilizes a traditional GAN-based inpainter to generate a rough "draft" of the background. This draft is then partially noised (denoising strength $s=0.9$), providing the diffusion model with a structural prior that acts as a regularizer against unwanted creativity.

Stage 2: Controllable Generation

This stage introduces two key modules to ensure the generated content remains strictly background-oriented:

  1. Prompt Tuning: Using Textual Inversion and LoRA, the model is trained on a learnable embedding $R_*$ representing "background completion." This allows the system to generate contextually appropriate content (e.g., "A photo of $R_*$ sky") automatically.
  2. Semantics-Aware Attention Refocus: This training-free module leverages panoptic segmentation to identify "positive" (background) and "negative" (foreground object) regions. It modifies internal self-attention maps to force the in-mask pixels to attend to background information while ignoring remnants of the erased object.
Figure 3: The MagicEraser architecture, detailing the two-stage pipeline of content initialization and controllable generation with semantics-aware attention refocusing.

Datasets and Evaluation

The authors introduced the Object-Level Removal Dataset (OLRD) to bridge the gap in realistic training data. By shifting segmented objects from the Places2 dataset to new background locations, they created training pairs with known ground truths.

Quantitative evaluations on the RealHM dataset show that MagicEraser achieves a PSNR of 23.620 dB, significantly outperforming Stable Diffusion Inpainting (21.758 dB) and LaMa (19.053 dB). Qualitative results confirm that MagicEraser is superior at maintaining texture consistency without leaving "ghost" remnants of the deleted object.

Conclusion

MagicEraser demonstrates that semantic guidance and structural priors are essential for professional-grade object erasure. While currently limited by the $512 \times 512$ resolution of its base model (Stable Diffusion v1.5), the approach provides a robust framework for suppressing generative hallucinations in image editing tasks.

Summary updated

BibTeX
@inproceedings{li2024magiceraser,
  author = {Fan Li and Zixiao Zhang and Yi Huang and Jianzhuang Liu and Renjing Pei and Bin Shao and Songcen Xu},
  title = {{MagicEraser: Erasing Any Objects via Semantics-Aware Control}},
  booktitle = {European Conference on Computer Vision},
  year = {2024},
  doi = {10.1007/978-3-031-73390-1\_13},
}
Figure