Image Editing As Programs with Diffusion Models

Yujia Hu, Songhua Liu, Zhenxiong Tan, Xingyi Yang, Xinchao Wang

Introduction

Instruction-driven image editing has seen significant progress with models like InstructPix2Pix, which excel at pixel-level attribute changes such as color modification or style transfer. However, these models often struggle with "structurally inconsistent" edits—tasks requiring significant layout changes, spatial reasoning, or the execution of complex, multi-step instructions. Common failure modes include ignoring parts of a prompt or introducing visual artifacts when attempting to perform multiple operations in a single pass.

The IEAP Framework

To address these challenges, we introduce Image Editing As Programs (IEAP), a reductionist framework that decomposes free-form text instructions into a sequence of modular, atomic operations. By treating image editing as a "program" rather than a black-box task, IEAP enables precise control over complex visual transformations.

The framework utilizes a Vision-Language Model (VLM), such as GPT-4o, to act as a "programmer." This agent parses user instructions into a series of five atomic operations:

  1. RoI Localization: Identifying the specific "Region of Interest" (RoI) using segmentation.
  2. RoI Inpainting: Adding or removing elements within the localized region.
  3. RoI Editing: Modifying attributes (e.g., texture, expression) within the RoI.
  4. RoI Compositing: Seamlessly blending edited regions back into the original image using a specialized fusion network and an "annular mask" to prevent visible seams.
  5. Global Transformation: Applying holistic changes like lighting or style across the entire image.
Example of a complex multi-step edit: 'Put the lady in a forest, make her dress white, and add a fox beside her'.

The system is built on the Diffusion Transformer (DiT) architecture (FLUX.1-dev), employing specialized LoRA adapters for each atomic task. This modularity prevents the "forgetting" issue common in end-to-end models, where earlier parts of a complex instruction are lost as the model processes later ones.

Results and Discussion

IEAP demonstrates state-of-the-art performance on benchmarks such as MagicBrush and AnyEdit, outperforming existing baselines like InstructP2P and ICEdit in both CLIP and DINO similarity scores. Qualitative evaluations show that IEAP excels at maintaining the identity of original subjects while executing radical layout changes.

A structurally inconsistent edit demonstrating background replacement and the addition of a Christmas collar while maintaining the cat's identity.

In head-to-head comparisons using GPT-4o as a rater for instruction faithfulness, IEAP achieved a score of 4.41/5.0, significantly higher than competing models. The "aha moment" of this research is that the bottleneck in current diffusion-based editing is not generative capacity, but rather spatial coordination. By isolating layout changes from content edits, IEAP effectively bypasses the combinatorial complexity that hinders single-pass models.

Limitations and Future Work

While IEAP represents a significant step forward, it faces challenges regarding physical consistency, such as the occasional presence of "ghost shadows" when objects are moved. Additionally, the sequential nature of the framework results in higher latency compared to end-to-end models, with each operation taking several seconds on high-end hardware. Future research will focus on physics-aware compositing to improve shadow accuracy and model distillation to enhance real-time performance.

Summary updated

BibTeX
@inproceedings{hu2025image,
  author = {Yujia Hu and Songhua Liu and Zhenxiong Tan and Xingyi Yang and Xinchao Wang},
  title = {{Image Editing As Programs with Diffusion Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=P6PijkA5lz},
}
Figure