Energy-Guided Optimization for Personalized Image Editing with Pretrained Text-to-Image Diffusion Models

Rui Jiang, Xinghe Fu, Guangcong Zheng, Teng Li, Taiping Yao, Xi Li

TL;DR

EGO-Edit is a training-free, inversion-free framework for personalized image editing that directly optimizes latent codes using a pretrained diffusion model as an energy function. By combining coarse-to-fine text and image energy guidance with latent-space content composition, it seamlessly swaps objects across different categories while maintaining high background fidelity.

What Problem Does This Paper Address?

Personalized image editing—such as replacing an object in a scene with a specific reference item—is a highly sought-after capability in creative workflows. Existing approaches generally fall into two categories: inpainting-based and sampling-based methods.

However, both approaches suffer from fundamental flaws:

  • Inpainting-based methods typically require extra training or fine-tuning and treat the source mask as a rigid shape prior. If the reference object has a completely different shape than the original object, the output becomes distorted.
  • Sampling-based methods rely on DDIM inversion to preserve the background. This introduces a harsh trade-off: prioritize background preservation, and the target object fails to appear; prioritize the target object, and the background gets ruined.

EGO-Edit eliminates both fine-tuning and inversion by framing personalized editing as a direct optimization problem in the latent space.

Figure 1: Comparisons among different methods in person- alized content editing. (a) Inpainting-based methods usually require fine-tuning the diffusion model with reference im- ages as the condition. (b) Sampling-based methods initialize the noise with inversion to maintain the background infor- mation from the source image. (c) The proposed method it- eratively optimizes the latent code to perform training-free and inversion-free editing.

Methods

Instead of relying on iterative sampling paths, EGO-Edit directly optimizes the edited image's latent code ($x_0$) by treating a pretrained text-to-image diffusion model as an energy function. The pipeline consists of three core components:

  1. Dual Energy Guidance:
  2. Text Energy Guidance (TEG): Uses positive/negative text prompts and an IP-Adapter to provide high-level conceptual and structural guidance.
  3. Image Energy Guidance (IEG): Leverages Discriminative Image Diffusion Features (DIFT) to establish point-to-point correspondences between the edited latent and the reference image, ensuring fine-grained appearance and texture alignment.
  4. Coarse-to-Fine Optimization Strategy: Optimization timesteps are scheduled in descending order. Early iterations use large noise levels where text energy dominates, allowing the object's global shape to transition naturally. Later iterations use smaller noise levels where image energy refines the fine details.
  5. Latent Space Content Composition (CC): At intermediate stages of optimization, the method performs a latent-level "copy-paste" operation based on the established feature correspondences. Because this happens in the latent space, subsequent optimization steps can naturally "heal" the boundaries and harmonize lighting.

To protect the background, the authors also introduce Gradient Scaling techniques, specifically truncating and smoothing gradients outside the editing mask.

Figure 3: Pipeline Overview of the Proposed Method: The illustration above outlines the pipeline for our energy-guided op- timization method. We construct the energy function derived from the diffusion model, aiming to minimize the energy of the edited image, ˜xt, to progressively align its distribution with that of the reference image. The diffusion-based energy function is composed of two key components: Text Energy Guidance (TEG) and Image Energy Guidance (IEG). TEG is applied through- out the entire process, ensuring consistent semantic alignment, while IEG is specifically employed during the N2 optimization step to refine visual details, enhancing the fidelity of the edited image to the reference. The processes for both TEG and IEG are detailed below the main pipeline.

Datasets

The authors evaluated their approach using two primary benchmarks:

  • DreamEditBench: A dataset featuring 22 distinct themes aligned with the DreamBooth framework, used here to evaluate subject-driven image editing across different environments.
  • PIE-Bench: The authors selected 50 images representing distinct conceptual categories and paired them randomly to rigorously test difficult, cross-category object swapping.

Key Insights and Ideas

  • Inversion-Free Flexibility: Bypassing DDIM inversion entirely removes the bottleneck that prevents sampling-based methods from rendering highly distinct target objects.
  • The Power of Descending Timesteps: Randomly sampling timesteps (as standard Score Distillation Sampling does) causes blurry results due to unstable feature matching. Forcing a descending schedule ensures the model locks in global geometry before trying to resolve fine textures.
  • Latent vs. Pixel Blending: Copy-pasting features directly into the latent variables during intermediate optimization steps balances adherence to the reference identity with the flexibility needed to blend the object realistically into the scene.

Key Results

EGO-Edit demonstrates significant quantitative and qualitative improvements over state-of-the-art baselines like Paint-by-Example (PbE), Anydoor, PAIR, and Dragon.

  • Quantitative Performance: On cross-class replacement tasks, EGO-Edit achieved a DINO score of 62.749 (outperforming the closest baseline, Anydoor, at 57.093) and a CLIP-I score of 76.624, proving superior identity preservation and text alignment.
  • Qualitative Performance: As shown in the evaluation, when executing challenging cross-category swaps (e.g., replacing a cat with a dog, or a bicycle with a cake), EGO-Edit respects the scale and boundaries of the scene while perfectly capturing the essence of the reference object.
Figure 2: Performance overview of the proposed method in image customization editing. Our method generates edited images by integrating contextual guidance with a reference image. The first row demonstrates object replacement within the same category, while the second row shows object replacement across different categories.

Limitations and Future Work

The paper does not explicitly detail failure modes or limitations. However, because EGO-Edit relies on an optimization loop (running 50 iterations per image), it is inherently slower than feed-forward, single-pass inpainting networks. A natural direction for future work would be accelerating this optimization process or extending the energy-guided framework to video personalization tasks.

Summary updated

BibTeX
@inproceedings{jiang2025energy,
  author = {Rui Jiang and Xinghe Fu and Guangcong Zheng and Teng Li and Taiping Yao and Xi Li},
  title = {{Energy-Guided Optimization for Personalized Image Editing with Pretrained Text-to-Image Diffusion Models}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2025},
  doi = {10.1609/aaai.v39i4.32424},
}
Figure