Overpainting

Localized Context-aware Diffusion Image Editing

arXivCodeComing soonModelComing soonTest setAll results
A source image followed by five localized overpainting edits, each with a trimap inset.
A sequence of localized overpainting edits.
Overpainting result for “shaggy purple fur”
Trimap
Overpainting result for “fancy decorative gold strip”
Trimap
An example of Overpainting edits with the same trimap moved to different locations. Hover to interact.

Abstract

We present “overpainting”, an image editing operation which offers both control over the location of the edit and awareness of the previous content in that location. The overpainted area is specified by a trimap, where white-annotated pixels must be edited, gray-annotated pixels may be edited, and black-annotated pixels must not be edited. This enables both precise and loose control, depending on user intent.

We implement overpainting by adapting a pretrained image editing diffusion model by augmenting the pretrained models’ native joint-attention with a variant of Teamwork that performs low-rank adaptation across image-streams and that balances information flow between noise, source, and trimap mask images. Furthermore, we present a novel, automated, training data generation pipeline that (1) generates a set of candidate image pairs leveraging existing language-based editing models, (2) carefully curates those pairs, and (3) extracts a trimap from each usable pair. We demonstrate the versatility of our overpainting model on a wide range of editing tasks.

Trimap control

Specifying an exact editing mask around existing image features is cumbersome and error-prone (e.g., for thin features or precise object boundaries). It is also often ambiguous for edits with ill-defined boundaries (e.g., frost forming on a window or smoke dissipating) and for to-be-created features whose location depends on the target edit itself (e.g., whiskers protruding from an object on which the user asked the model to grow hair). We tackle this challenge by introducing a trimap that marks not only pixels which must be edited and must not be edited , but also pixels that may or may not be edited .

The same source edited with several precise and approximate trimaps.
Adding “shaggy purple fur” to an apple requires a detailed binary mask (2nd column); without a detailed mask, the protruding whiskers of fur will be missing (3rd column). Marking a whole region as may-edit , alleviates the user from specifying a precise mask (4th column). By combining both white and gray regions, the user caan create both precise and loose boundaries in the same image (5th column).

Data Generation

To train our overpainting model we require paired data in the form of an original image, an edited version, a mask, and a prompt describing the edit operation. We follow the well-established process of leveraging VLMs and image diffusion models to generate training data. Specifically, we:

  1. randomly sample freely licensed photographs from pexels.com as source photographs
  2. use Qwen3 Instruct to suggest edit prompts
  3. feed the source images and generated prompts into FLUX.2 Klein or Qwen Image 2.1 to produce edited photographs
  4. filter out over-edited, under-edited, and misaligned results
  5. estimate which pixels were actually edited using an adapted BiRefNet finetune
  6. degrade the precise binary masks into human-like trimaps
Overview of the training data generation pipeline.
Overview of the training data generation pipeline.

Finetuning

We demonstrate overpainting by finetuning Teamwork LoRAs for the FLUX.2 Klein and Qwen Image 2.1 models. The image editing diffusion models accept a prompt, latents for any number of condition images, and noisy latents for the image to generate. We provide both the source image and trimap image as VAE-encoded conditions.

Empirically we found that a naive LoRA-adapted model adhears poorly to the user-provided trimap. By using a Teamwork LoRA, we impose a strong positional bias (i.e., edited image latents at a particular position exchange information directly with the correspoinding source latents and mask latents). On the other hand, Teamwork alone allows limited global reasoning, and so provides poor edit quality. We therefore use both the attention of the base editing model and the aggredation of the Teamwork LoRAs.

Architecture overview.
Architecture overview. We pass the source image and trimap as additional condition images, and communicate across the conditions and the noise using both teamwork and joint attention.

Examples

A range of localized edits from the paper. Browse all 180 comparisons →

Selected overpainting results showing sources, prompts, trimaps, and edited outputs.
Selected overpainting results showing the source, prompt, trimap, and edited output.

Resources

Model outputs on our test set are avalible now. Source code and checkpoints will be made available once published.