Abstract
Inserting photorealistic objects into artistic masterpieces requires bridging a significant "wild domain gap" where the style, texture, and lighting of the reference object differ drastically from the target painting. We present RefPaint, a novel diffusion-based framework designed for painterly inpainting. By employing a specialized ladder-side branch and decomposing CLIP embeddings via Principal Component Analysis (PCA), RefPaint allows for precise control over the balance between an object's semantic identity and the painting's unique style. Our method significantly outperforms existing inpainting baselines in both qualitative harmony and quantitative reference alignment.
Introduction
Traditional image inpainting focuses on filling missing regions using surrounding context. Reference-based inpainting extends this by using a secondary image to guide the content of the filled region. However, a major challenge arises when the reference and target images belong to different domains—for example, inserting a real-world basketball into a Monet painting.
Existing tools often fail in this "wild domain gap." Text-to-image models like Stable Diffusion are often too vague to capture specific visual details from a reference, while standard image-to-image methods frequently produce "sticker-like" results that look pasted onto the canvas rather than integrated into the artistic style. RefPaint addresses this by learning to translate the semantics of a real-world object into the specific brushstrokes and textures of a target artwork.
Methodology
RefPaint is built upon the Versatile Diffusion (VD) backbone, enhanced with architectural innovations to handle localized, cross-domain editing.
Ladder-Side Branch and Masked Fusion
To capture fine-grained conditioning without modifying the core U-Net, we introduce a parallel ladder-side branch. Unlike standard encoders that operate on compressed VAE latents, this branch processes raw pixels to retain structural fidelity. To ensure the model respects inpainting boundaries and avoids global color shifts, a Masked Fusion Mechanism blends features from the original encoder and the ladder-side branch specifically within the masked region.
CLIP Embedding Decomposition
A key innovation of RefPaint is the use of PCA on CLIP image embeddings to disentangle "semantics" (the identity of the object) from "style" (the visual domain). By separating these components, we introduce Disentangled Classifier-Free Guidance. During inference, users can adjust weighting coefficients to navigate the trade-off between making the object look exactly like the reference (high semantic alignment) or blending it perfectly into the painting (high style alignment).
Self-Supervised Training
The model is trained in a self-supervised manner using the LAION-2b dataset. By masking a portion of a single image and treating that portion as the "reference," the model learns to reconstruct complex scenes without requiring a manually labeled dataset of objects-in-paintings.
Experiments and Results
We evaluated RefPaint using WikiArt for artistic backgrounds and COCO Captions for photorealistic reference objects. We compared our method against Stable Diffusion (SD) Inpainting, LaMa, and traditional painterly harmonization techniques.
- Qualitative Performance: RefPaint successfully adapts object textures to match surrounding brushstrokes (e.g., a modern train in a 19th-century landscape), whereas baselines often ignore the reference or produce incoherent shapes.
- Quantitative Performance: Using CLIP image distance to measure reference alignment, RefPaint achieved a score of 0.2568, nearly doubling the performance of SD Inpainting (0.1392) and LaMa (0.1309).
- Ablation Insights: Removing the ladder-side branch resulted in global style manipulations rather than localized edits, while removing the masked fusion block caused severe color distortions.
Conclusion
RefPaint demonstrates that diffusion models can effectively bridge the wild domain gap between photos and art by separating content from style. While the model currently faces challenges with extremely high-frequency textures and inference speed typical of diffusion processes, it provides a powerful new tool for controllable, reference-based artistic editing. Future work will explore multi-object referencing and broader domain gaps beyond the painterly realm.
Summary updated