TL;DR
DiffHarmony adapts pre-trained Latent Diffusion Models (LDMs) to the task of image harmonization, overcoming the inherent blurriness caused by VAE compression. By combining high-resolution inference with a dedicated refinement stage, the authors achieve new state-of-the-art results on the iHarmony4 benchmark, particularly for images with large foreground elements.
What Problem Does This Paper Address?
Image composition—the act of "pasting" a foreground object from one image into a new background—is a staple of photo editing. However, the result often looks unnatural because the foreground’s lighting, color, and contrast don't match the new environment. Image harmonization is the process of adjusting that foreground to make it blend seamlessly.
While recent Diffusion Models have revolutionized image generation, applying them to harmonization is tricky. Training a diffusion model from scratch is prohibitively expensive. Conversely, using a pre-trained Latent Diffusion Model (LDM) like Stable Diffusion introduces a "reconstruction error." Because LDMs operate in a compressed "latent space" (usually 1/8th the resolution of the original image), the final output often loses pixel-level sharpness, resulting in blurry textures or distorted shapes—a dealbreaker for high-quality photo editing.
Methods
The authors propose DiffHarmony, which builds upon a pre-trained Stable Diffusion Inpainting model. Their approach involves three key adaptations:
- Inpainting Variation: They utilize the Stable Diffusion inpainting checkpoint, which is already fine-tuned to generate new content within a mask while keeping the background unchanged. They concatenate the composite image and the foreground mask as the primary conditions.
- Null Text Input: Since harmonization is a purely visual task, they bypass the text-prompting system of Stable Diffusion by using "null" (empty) text tokens during inference.
- Mitigating Distortion: To fix the blurriness caused by the VAE (Variational Autoencoder) compression, they implement two strategies:
- High-Resolution Inference: Instead of the standard 256px, they run the model at 512px or 1024px. This provides more "data" for the VAE to work with, reducing information loss.
- Refinement Stage: They add a lightweight UNet-based model after the diffusion process. This model takes the potentially blurry output, the original composite, and the mask to "repair" textures and sharpen edges. It uses a skip connection to learn the residual (the difference between blurry and sharp), which speeds up training.
Datasets
The model was trained and evaluated on iHarmony4, the industry-standard benchmark for this task. It consists of 73,146 image pairs across four sub-datasets:
- HAdobe5k
- HFlickr
- HCOCO
- Hday2night (focusing on extreme lighting changes)
Key Insights and Ideas
- The VAE Bottleneck: The paper identifies that the primary hurdle for LDMs in harmonization isn't the generative process itself, but the VAE's 8x downsampling. If you input a 256px image, the model is actually "thinking" at a tiny 32px resolution.
- Generative vs. Regressive: Traditional harmonization models are "regressive"—they try to calculate a direct mapping from A to B. DiffHarmony is "generative." This allows it to handle complex lighting and textures that simple mapping models might miss.
- Resolution as a Cure: Simply increasing the inference resolution (even if the final output is downscaled back to 256px) significantly improves performance metrics because it mitigates the VAE's compression artifacts.
- Stability in Randomness: Despite being a generative model (which usually implies high variability), the authors found that DiffHarmony produces very stable results across different random seeds, making it reliable for actual editing workflows.
Key Results
DiffHarmony achieved state-of-the-art (SOTA) performance on the iHarmony4 dataset:
- MSE (Mean Squared Error): Achieved an average score of 14.29, significantly beating the previous SOTA, HDNet (16.55).
- fMSE (Foreground MSE): Achieved 151.42, a massive improvement over HDNet’s 248.86.
- Qualitative Superiority: In visual comparisons, DiffHarmony was notably better at maintaining the structural integrity of faces and complex textures compared to other diffusion-based attempts.
- Performance by Scale: The model performs exceptionally well when the foreground occupies a large portion of the image (15%–100% area), where its generative power can truly shine.
Limitations and Future Work
- Small Foregrounds: The authors noted that for very small foreground objects (0%–5% of the image), their model is slightly outperformed by HDNet. This suggests that even with high-res inference, the VAE compression still struggles with tiny, fine details.
- Computational Overhead: Diffusion models are inherently slower than simple feed-forward UNets. While the authors optimized the process to just 5 inference steps, it still requires more compute than non-diffusion alternatives.
- Future Directions: The authors suggest that using even more advanced pre-trained models (like SDXL) or exploring better latent space representations could further push the boundaries of image harmonization.
Summary updated