Source-linked AI summary
DiffEdit: Diffusion-based semantic image editing with mask guidance
Guillaume Couairon, Jakob Verbeek, Holger Schwenk, Matthieu Cord
TL;DR
Semantic image editing methods often require a user-provided mask and may discard input-image information, while DiffEdit automatically infers edit regions and preserves content through DDIM encoding. Evaluations on ImageNet, COCO, and Imagen-generated images show excellent edits that improve over previous approaches.
Problem
Existing diffusion-based editing methods typically require a user-provided mask and can discard input-image information that should remain unchanged.
Method
DiffEdit contrasts conditional and unconditional diffusion predictions to infer edit regions, then uses DDIM encoding and mask-guided decoding to preserve the input.
Results
Evaluations on ImageNet, COCO, and Imagen-generated images show excellent edits that improve over previous approaches.
Takeaways & Limitations
DiffEdit conserves more appearance information from the input, producing lighter edits without requiring a user-generated mask.
Takeaways & Limitations
The COCO benchmark has predominant western cultural bias and evaluates transformations on a small subset of mostly western-culture images.
Abstract
from arXiv · showhide
Image generation has recently seen tremendous advances, with diffusion models allowing to synthesize convincing images for a large variety of text prompts. In this article, we propose DiffEdit, a method to take advantage of text-conditioned diffusion models for the task of semantic image editing, where the goal is to edit an image based on a text query. Semantic image editing is an extension of image generation, with the additional constraint that the generated image should be as similar as possible to a given input image. Current editing methods based on diffusion models usually require to provide a mask, making the task much easier by treating it as a conditional inpainting task. In contrast, our main contribution is able to automatically generate a mask highlighting regions of the input image that need to be edited, by contrasting predictions of a diffusion model conditioned on different text prompts. Moreover, we rely on latent inference to preserve content in those regions of interest and show excellent synergies with mask-based diffusion. DiffEdit achieves state-of-the-art editing performance on ImageNet. In addition, we evaluate semantic image editing in more challenging settings, using images from the COCO dataset as well as text-based generated images.
1 INTRODUCTION
Semantic image editing modifies an input image according to a text query while preserving unrelated content. DIFFEDIT addresses the need for localized, mask-guided edits by automatically identifying regions requiring change through diffusion-model predictions.
- Task definition: Semantic image editing changes an input image to satisfy a textual transformation query while keeping unrelated elements similar to the input.The example changes fruits into pears while preserving the bowl and background.
- Motivation: Diffusion models are promising for image editing because iterative denoising can be guided by techniques including CLIP guidance and mask-based inpainting.Prior approaches include inpainting that copies pixel values outside a user-provided mask.
- DIFFEDIT: DIFFEDIT automatically finds regions that should be edited by contrasting conditional and unconditional diffusion-model predictions.A reference text describing the input image and similar to the query can help produce better masks.
2 RELATED WORK
Related work spans broad image-editing tasks, while diffusion-based methods commonly adapt to masked inpainting and text-guided editing. Existing approaches preserve reference content through pixel copy-pasting, latent encoding, or CLIP-based guidance.
- Semantic image editing: Image editing includes colorization, retouching, style transfer, object insertion, image-to-image translation, inpainting, scene graph manipulation, and contextual subject placement.
- Image editing with diffusion models: Diffusion models are readily adapted to inpainting by conditioning iterative denoising on a provided mask.
- Image editing with diffusion models: Existing diffusion editors preserve reference content by copy-pasting pixels during denoising or in estimated final images.
- Image editing with diffusion models: DDIM encoding enables decoding images edited through sketches or semantic segmentation maps.
- Image editing with diffusion models: CLIP-score gradients guide diffusion to match a text query inside a mask in Paint by Word, local CLIP-guided diffusion, and blended diffusion.
3 DIFFEDIT FRAMEWORK
DIFFEDIT automatically identifies image regions requiring semantic edits by contrasting text-conditioned denoising predictions, then combines DDIM encoding with mask-guided decoding to preserve unchanged content. Its theoretical analysis explains why DDIM encoding can remain closer to the input than random-noise editing in SDEdit, with empirical support.
- Step 1: Computing editing mask: DIFFEDIT derives an editing mask from differences between denoising noise estimates conditioned on the query and a reference or empty text.The differing estimates indicate image regions affected by changing the conditioning text.
- Step 2: Encoding: It encodes the input image at timestep r in an implicit latent space using unconditional DDIM encoding.The encoding uses the empty text conditioning ∅ rather than the editing query.
- Step 3: Decoding with mask guidance: During query-conditioned DDIM decoding, DIFFEDIT replaces latents outside the mask with encoded input latents so those regions map back toward the original pixels.The mask therefore guides edits toward the regions identified as needing change while preserving the background.
- Encoding ratio: Larger encoding ratios r produce stronger edits that better match the query but increase deviation from the input image.The encoding ratio controls edit strength and is evaluated experimentally.
- Theoretical comparison with SDEdit: The theoretical analysis gives DIFFEDIT a tighter bound than SDEdit below a certain encoding ratio, while experiments find DDIM encoding produces smaller edits.The argument relies on the generally small average difference K2 between unconditional and text-conditional noise estimates, although the bounds do not guarantee this outcome.
4 EXPERIMENTS
Experiments evaluate DIFFEDIT across ImageNet, Imagen-generated, and COCO images using diffusion-based baselines and task-specific trade-off metrics. DIFFEDIT achieves the strongest reported trade-offs, with masking, DDIM encoding, and reference-text choices shaping performance.
- Experimental setup: Experiments cover ImageNet class-to-class edits, Imagen-generated images with structured prompt changes, and COCO image edits.The study follows the ImageNet protocol of FlexIT and also evaluates more challenging generated-image and COCO settings.
- ImageNet results: DIFFEDIT obtains the best ImageNet trade-offs among the compared methods, outperforming SDEdit, FlexIT, ILVR, and other baselines.The comparison uses shared diffusion models where possible and includes Copy and Retrieve as opposite reference cases.
- Evaluation: ImageNet evaluation uses LPIPS for input-image distance and CSFID for realism and consistency with the transformation prompt, with lower values better.The comparison considers the CSFID-LPIPS trade-off as editing strength varies.
- ImageNet ablations: At encoding ratio 80%, DIFFEDIT’s mask guidance gives LPIPS 30.5 and CSFID 23.6, versus CSFID 26.4 for the GLIDE operator at the same LPIPS.The proposed operator therefore provides the better reported trade-off under this condition.
- Imagen and additional results: On Imagen images, DIFFEDIT provides more accurate edits than SDEdit, FlexIT, and Cross Attention Control, while reference-text masks yield the best overall trade-off.Reference text improves CLIP and FID on Imagen, whereas on the other evaluated setting it does not change the trade-offs and DIFFEDIT reaches a lower maximum CLIP score than SDEdit.
5 CONCLUSION
DIFFEDIT is a diffusion-based semantic image-editing algorithm that infers edit regions from a textual query instead of requiring a user-generated mask. It initializes generation with a DDIM encoding of the input, motivated theoretically and shown experimentally to better conserve appearance, with examples demonstrated on COCO images.
- 5 CONCLUSION: The paper includes examples of edits applied to COCO images.These examples are presented in Figure 11.
- 5 CONCLUSION: DIFFEDIT performs semantic image editing with diffusion models from a textual query.The paper introduces it as a novel algorithm for semantic image editing.
- 5 CONCLUSION: DIFFEDIT infers the relevant regions to edit rather than requiring a user-generated mask.The diffusion model identifies regions associated with the requested edit.
- 5 CONCLUSION: DDIM encoding of the input initializes generation, with theoretical analysis motivating the choice and experiments showing greater appearance conservation.This initialization contrasts with other diffusion-based methods.
7 ETHICS STATEMENT
The paper highlights ethical risks inherited from diffusion-based image generation and limitations in its COCO-based editing benchmark. These include biased or inappropriate web-scraped training data, western cultural bias in COCO, and difficulty identifying relevant transformation prompts.
- Ethical challenges: Diffusion-based image editing inherits ethical concerns from image generation because open-source models train on large web-scraped datasets such as LAION.The passage notes that LAION contains inappropriate content, including violence, hate, and pornography, as well as racist and sexist stereotypes.
- Benchmark limitations: The COCO-based benchmark is limited by predominant western cultural bias and evaluates transformations on a small subset of mostly western-associated images.The authors argue that evaluating image editing models on a less culturally biased dataset is needed.
- Benchmark limitations: Selecting relevant transformation prompts for each image is challenging, even when leveraging existing COCO annotations.The authors identify prompt relevance as a limitation of their benchmark design.
DIFFEDIT: Diffusion-based semantic image editing with mask generation … A.2 CLASSIFIER-FREE GUIDANCE
The supplementary experiments examine DiffEdit’s guidance strength and mask-computation noise, alongside additional experimental details and qualitative examples. Classifier-free guidance above 3 performs best, with λ = 5 used by default.
- DIFFEDIT: Diffusion-based semantic image editing with mask generation: The supplementary material reports additional experiments on guidance strength, reference texts, encoding ratio, qualitative edits, and COCO examples.These analyses extend the methods and experiments presented in the main paper.
- A.2 CLASSIFIER-FREE GUIDANCE: Classifier-free guidance conditions diffusion noise estimation on text and improves generation quality and image-text alignment.The method trains conditional and unconditional models by dropping the conditioning text during training.
- A.1 ANALYSIS OF NOISE USED TO COMPUTE THE MASK: Mask computation is evaluated by varying the noise added to the input image at encoding ratios of 0.7 and 0.8 on ImageNet.Figure 12 studies how input-image noise affects the generated mask.
- A.2 CLASSIFIER-FREE GUIDANCE: Figure 13 shows that at least 3 classifier-free guidance is required on ImageNet to obtain good results.The selected value is 5.
- A.2 CLASSIFIER-FREE GUIDANCE: On ImageNet, classifier-free guidance values above 3 yield the best DiffEdit results, while omitting guidance produces a noncompetitive trade-off.The ablation varies the classifier-free guidance parameter λ.
- A.2 CLASSIFIER-FREE GUIDANCE: λ = 5 is used as DiffEdit’s default classifier-free guidance value.This value is also the default recommended for generation.
A.3 EXPERIMENTS ON COCO FILTERING
The COCO experiments examine why reference text has little overall effect on mask computation. Filtering makes reference text beneficial at high encoding ratios, while COCO queries generally describe scenes close to the input and require editing only part of the image.
- COCO query analysis: COCO queries generally describe scenes similar to their input images, so matching the query can require editing only a fraction of the image.The experiments use editing queries from the BISON dataset.
- COCO query analysis: The experiments investigate why using the reference text to compute the mask makes little difference on COCO queries.The analysis is illustrated with several BISON-derived COCO editing queries.
- Filtering results: Filtering has a small overall impact, but reference text benefits the filtered set, especially at a 90% encoding ratio.Figure 14 compares unfiltered and filtered COCO results and highlights the effect at high encoding ratios.
A.4 VISUALISATION OF THE IMPACT OF ENCODING RATIO
Figure 16 qualitatively shows how mask inference and DDIM encoding affect DiffEdit across encoding ratios from 30% to 80%. Mask inference preserves the background, while DDIM encoding better retains content inside the mask at higher ratios.
- Encode-Decode matches the query better than SDEdit while making fewer modifications to the main object and background, especially at 60%–70%.
- The ablations compare SDEdit, Encode-Decode, DIFFEDIT without encoding, and DIFFEDIT at encoding ratios from 30% to 80%.
- Mask inference maintains exactly the background across the qualitative ablations.
- DDIM inference with mask-based decoding better retains content inside the mask, especially at 70% and 80%.
A.5 ADDITIONAL VISUALIZATIONS AND QUALITATIVE RESULTS
Qualitative results show that DIFFEDIT generally makes targeted, accurate edits while preserving unaffected image content, including in comparisons with other mask-free methods and COCO examples. Its failures reflect both generative-model limitations and mask-based difficulties, especially for object insertion.
- Comparative qualitative results: DIFFEDIT generally produces more targeted and accurate edits than other mask-free methods while preserving original content, such as leaving a guitar unchanged.Figure 17 compares DIFFEDIT with other mask-free editing methods and highlights unnecessary changes made by competing approaches.
- COCO qualitative examples: COCO examples show that imperfect mask size or coverage can still yield good edits, while preserving edited objects’ colors unlike regular inpainting.Examples include a bread → burger transformation with few edits outside the request and a truck edit unaffected by incomplete interior coverage.
- Failure cases: DIFFEDIT failures arise from generative-model weaknesses in spatial understanding, spatial reasoning, and counting, as well as mask-based difficulty inserting objects.For object insertion, the mask often seeks an “anchor” visual element.
A.6 DETAILS ON COMPARISONS WITH OTHER METHODS
The comparisons cover COCO and Imagen, excluding ILVR because its image resampling is incompatible with latent diffusion. Results also highlight limitations of Cross-Attention Control’s prompt-matching assumptions, temporary reimplementation status, and several mask-based failure modes.
- COCO and Imagen benchmark: ILVR is excluded on COCO and Imagen because its required image downsampling and upsampling do not work well in latent diffusion spaces.The authors also do not expect a favorable CLIP-LPIPS trade-off for ILVR, given its high ImageNet editing distance.
- Qualitative comparisons: Figure 17 presents Imagen edits alongside other mask-free editing methods, while Figure 18 provides additional qualitative COCO examples.These figures document the qualitative comparison settings for Imagen and COCO.
- COCO and Imagen benchmark: Cross-Attention Control can yield high LPIPS distances on COCO because it targets prompt-to-prompt edits with nearly matching input and target texts.COCO queries and reference texts have high average edit distance, unlike the setting for which Cross-Attention Control was designed.
- COCO and Imagen benchmark: The reported Cross-Attention Control results are temporary because they rely on an unofficial re-implementation.The authors plan to update the comparison when official code or an official Stable Diffusion adaptation becomes available.
- Failure modes: Failure cases include difficulty inserting objects into smooth regions, missed insertion regions, masks covering multiple similar objects, and unsuccessful spatial-relation changes.These mask errors can cause over-editing when only one object should be edited.
B THEORETICAL RESULTS … B.3 LINKS TO OPTIMAL TRANSPORT THEORY
The appendix proves the theoretical bounds underlying SDEdit and Proposition 2, then relates Encode-Decode to optimal transport while identifying limitations of that interpretation. The proofs use deterministic DDIM dynamics, Lipschitz assumptions, Grönwall’s inequality, and expectation over input images.
- B THEORETICAL RESULTS: The appendix establishes the bounds stated in the main paper and discusses their connection to optimal transport theory.It reuses the notation from Proposition 1 in the main paper.
- B.1 PROOF OF SDEDIT BOUND: Proposition 2 assumes the conditional noise prediction satisfies ∥ϵθ(x, Q, t)∥2 ≤ C for all x ∈ X and t ∈ [0, 1].The proof introduces forward and reverse process variables before applying the stated bound.
- B.1 PROOF OF SDEDIT BOUND: The SDEdit-bound proof controls reconstruction error using xr √αr = x0 + τϵ and concludes ∥x0 − y0∥ ≤ Cτ + τ.The argument applies the triangle inequality to separate the denoising and noise terms.
- B.1 PROOF OF SDEDIT BOUND: Compared with SDEdit’s proof, this analysis adapts from VE-SDE to variance-preserving SDE, from stochastic differential equations to deterministic DDIM, and from tail probabilities to a different control.The supplied passage lists three main differences but truncates the final one’s wording.
- B.2 PROOF OF PROPOSITION 2: Proposition 3 assumes ϵθ(·, Q, t) is K1-lipschitz, defines κ2 and K2 = Ex0κ2(x0), and analyzes a differential system for u and v.The proof bounds conditional and state-dependent prediction differences, then applies Grönwall’s inequality and takes expectation over x0.
- B.3 LINKS TO OPTIMAL TRANSPORT THEORY: The reverse DDIM encoder Er maps image distribution p0 = pD to the distribution pr of images noised at timestep r and has been proposed as an optimal transport map.The proposed transport map minimizes the transport cost Ex0∥x0 − Er(x0)∥2.
- B.3 LINKS TO OPTIMAL TRANSPORT THEORY: Under the hypothesis that pr is very close to pr(·|Q), Encode-Decode can be viewed as composing transport maps from p0 to pr and then to p0(·|Q).This interpretation assigns the unconditional decoder and conditional decoder transport roles between the corresponding distributions.
- B.3 LINKS TO OPTIMAL TRANSPORT THEORY: The composition Dr(·, Q) ◦ Er is not generally an optimal transport solution because Er fails to be optimal for some distributions and optimal-map compositions need not remain optimal.Despite this limitation, experiments and numerical simulations suggest that Er is very close to an optimal transport map.