Abstract
Harmonizing Attention is a novel, training-free framework that enables the transfer of geometric features—such as cracks, holes, or droplets—from one material to another while perfectly preserving the target material's texture. By modifying the self-attention layers of a pre-trained Stable Diffusion model, the method decouples geometric structure from material texture without requiring fine-tuning or complex prompt engineering.
Introduction
In image composition, "harmonization" typically refers to matching a foreground object's lighting and color to a background. However, Texture-aware Geometry Transfer presents a more complex challenge: decoupling geometric structure from material-specific texture. For instance, carving a knot-hole from wood into brushed metal often results in either a "sticker-like" appearance (retaining the wood texture) or a loss of structural detail. Harmonizing Attention addresses this by isolating "what" an object is from "what it's made of."
Methodology
The framework utilizes a dual-attention mechanism integrated into a pre-trained Stable Diffusion Inpainting model. The process is entirely training-free and follows four distinct stages:
- Editing & Color Shift: The source geometry is masked, transformed (scaled/rotated), and color-shifted to match the target area's average color, facilitating a smoother inversion.
- Inversion (Texture-aligning Attention): During DDIM inversion, a custom attention layer allows the geometry latent to query the target texture. This aligns the geometry's latent representation with the visual domain of the target material.
- Blending: Noisy latents from the target and the aligned geometry are blended using the foreground mask.
- Generation (Geometry-preserving Attention): During denoising, a modified attention layer ensures structural details are preserved, preventing them from being "washed away" while the pixels adopt the target texture.
Experiments and Evaluation
The method was evaluated using the MVTec AD dataset for industrial textures and Pixabay for general images. A quantitative benchmark of 150 composite images was established to compare against state-of-the-art baselines.
Key Results
Harmonizing Attention was compared against Paint by Example, TF-ICON, PHDiffusion, and TF-GPH.
- User Study: In a study with 105 participants, the method consistently outperformed others in background quality (3.44), foreground quality (2.96), and overall composition (3.56).
- Quantitative Metrics: The approach achieved superior scores in LPIPS(bg) (0.266) and DISTS(bg) (0.179), indicating excellent background preservation. It also led in CLIP(fg) (91.352), confirming high semantic consistency.
- Qualitative Performance: Visual results demonstrate successful transfers, such as placing water droplets on rusted metal or wood-grain cracks onto stone, where baselines often failed by blurring geometry or leaving textural artifacts.
Discussion
The core innovation lies in treating Attention as a Query Engine. By concatenating keys ($K$) and values ($V$) from different sources, the model can simultaneously "borrow" texture from one image and structure from another. Furthermore, performing alignment during the inversion phase is critical for preventing textural discontinuities.
Limitations
- Scale Sensitivity: The method can struggle with extremely large or small geometries due to the fixed nature of attention calculations relative to the transfer area.
- Geometric Deviations: Significant differences between source and target textures can occasionally lead to minor shape alterations or artifacts.
Conclusion
Harmonizing Attention provides a robust, prompt-free workflow for complex image editing tasks. By leveraging the internal representations of diffusion models, it achieves high-fidelity geometry transfer that respects the underlying material properties of the target image.
Summary updated