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

Abstract

Personalized image editing aims to replace specific objects within an image while maintaining background consistency and target identity. Current methods often struggle with significant shape discrepancies or rely on computationally heavy fine-tuning and inversion. We present EGO-Edit, a training-free and inversion-free framework that treats editing as an energy-guided optimization problem in the latent space. By employing a coarse-to-fine schedule and novel energy functions, EGO-Edit achieves high-fidelity object replacement across diverse categories without distorting the target object's shape or identity.

Introduction

Personalized image editing involves replacing an object in a source image with a specific, user-provided target object—for instance, swapping a generic dog in a photo with a specific picture of a user's pet. This task presents a significant challenge for existing diffusion-based models, which typically fall into two categories: inpainting-based and sampling-based methods.

Inpainting-based methods often treat the source object's mask as a rigid shape prior. When the target object has a vastly different silhouette (e.g., replacing a tall vase with a round bowl), these models often produce squished or artifact-heavy results. Sampling-based methods, on the other hand, rely on "inverting" the source image back into noise. This process frequently creates a conflict between maintaining the original background and accurately generating the new object, often failing to capture the target's specific identity.

EGO-Edit addresses these challenges by abandoning the need for retraining or restrictive inversion techniques, instead formulating the editing process as a direct optimization problem.

Methodology

Instead of standard diffusion sampling, EGO-Edit treats image editing as an optimization problem in the latent space. The framework directly updates the latent code of the edited image using a pretrained diffusion model as an "energy function" to guide the generation process.

Energy Guidance Mechanisms

The framework utilizes two primary guidance mechanisms:

  • Text Energy Guidance (TEG): This uses text prompts, enhanced by an IP-Adapter, to push the latent code toward the target's high-level semantic concept.
  • Image Energy Guidance (IEG): By extracting intermediate features from the diffusion model's U-Net, IEG minimizes the point-to-point distance between the reference object and the generated object, ensuring fine-grained appearance alignment.

Coarse-to-Fine Optimization

Unlike standard optimization methods that sample random noise timesteps—which often results in blurry edits—EGO-Edit employs a strictly descending timestep schedule. Early stages (high noise) rely on TEG to morph the overall shape, while later stages (low noise) use IEG to refine textures and details.

The EGO-Edit pipeline, illustrating the energy-guided optimization process and content composition.

Content Composition and Gradient Scaling

To boost identity consistency, EGO-Edit introduces Content Composition (CC), where matched latent features from the reference image are copied and pasted into the edited image at a specific intermediate timestep. Subsequent optimization steps then smooth this transition to ensure a natural blend. Additionally, Gradient Scaling is used to truncate and smooth gradients outside the target mask, preventing unwanted alterations to the background.

Key Results

EGO-Edit was evaluated on established benchmarks, including DreamEditBench and PIE-Bench, for object swapping tasks. The method significantly outperformed competing baselines such as Paint-by-Example, Anydoor, and Dragon across both quantitative and qualitative metrics.

Quantitative Performance

EGO-Edit achieved a DINO score of 62.749 and a CLIP-Image score of 76.624, substantially higher than the next best competitor (Anydoor at 57.093 and 72.133, respectively). These scores demonstrate the model's superior ability to preserve the specific identity of the target object. It also achieved the highest CLIP-Text score (28.764), indicating excellent alignment with user prompts.

Qualitative Superiority

In cross-class replacement tasks, such as replacing a backpack with a duck or a cake with a dog, EGO-Edit successfully managed drastic shape changes that caused other models to fail. While baselines often filled the source mask with irrelevant background or failed to adapt the shape, EGO-Edit produced seamless transitions and high-fidelity details.

Qualitative results of EGO-Edit across various object swapping tasks, demonstrating shape flexibility and identity preservation.

Discussion and Conclusion

A key insight of this work is that masks should not dictate shape; by allowing the new object to define its own boundaries, EGO-Edit avoids the distortions common in prior work. Furthermore, the authors identified a "Goldilocks" timing for feature injection: performing Content Composition in the middle of the optimization process provides the best balance between identity fidelity and natural blending.

While EGO-Edit is computationally more intensive than single-pass methods due to its iterative optimization (50 steps), its ability to perform high-quality, training-free personalized editing represents a significant advancement in the field. Future work may focus on accelerating the optimization process to make the framework more efficient for real-time applications.

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