Shadow Generation for Composite Image Using Diffusion Model

Qingyang Liu, Junqi You, Jianting Wang, Xinhao Tao, Bo Zhang, Li NiuCVPR 2024

Abstract

In the realm of image composition, generating realistic shadows for inserted foreground objects remains a formidable challenge. Previous works have developed image-to-image translation models trained on paired data; however, these models often struggle to generate shadows with accurate shapes and intensities due to data scarcity and inherent task complexity. In this paper, we leverage foundation models with rich prior knowledge of natural shadow images. Specifically, we adapt ControlNet to the shadow generation task and propose intensity modulation modules to improve shadow realism. Furthermore, we extend the small-scale DESOBA dataset to DESOBAv2 using a novel data acquisition pipeline. Experimental results on both DESOBA and DESOBAv2 datasets, as well as real composite images, demonstrate the superior capability of our model, SGDiffusion, in generating high-fidelity shadows.

Introduction

Image composition—the process of inserting an object from one image into another—is a fundamental task in digital art, e-commerce, and virtual reality. A primary hurdle in achieving seamless composition is ensuring lighting consistency. The human visual system is highly sensitive to lighting discrepancies; when a foreground object is placed into a scene without a corresponding shadow that matches the environment's light source, the result appears unnatural and "pasted-on."

Generating these shadows is complex because they are determined by the 3D geometry of the object, the ground surface, and the specific characteristics of the light source. While previous approaches using Generative Adversarial Networks (GANs) made progress, they often produced blurry, inaccurate shadows and were limited by the lack of diverse training data. This research introduces SGDiffusion, a framework that utilizes the extensive prior knowledge embedded in large-scale diffusion models to bridge the gap between synthetic and realistic shadow generation.

Methodology: The SGDiffusion Framework

SGDiffusion is built upon the architecture of Stable Diffusion and ControlNet, enhanced by three specific technical innovations designed to handle the nuances of shadow physics.

1. Weighted Noise Loss

To ensure the model focuses on the most critical areas of the image, the authors implemented a "weighted noise loss." During training, the model is forced to prioritize the region where the shadow should appear. This targeted approach allows the neural network to refine shadow edges and shapes with greater precision than standard diffusion models, which treat all pixels with equal importance.

2. Shadow Intensity Modulation

A common failure in AI-generated shadows is a mismatch in darkness relative to the rest of the scene. SGDiffusion addresses this through an Intensity Encoder. This module analyzes existing shadows in the background to calculate a "scale and bias" adjustment. By learning from the context of the environment, the model can modulate the generated shadow's intensity to match the ambient lighting perfectly.

3. Post-processing for Background Fidelity

Diffusion models are known for "hallucinating" small changes across an entire image, which can inadvertently alter the original background. To maintain the integrity of the composite, the researchers developed a specialized post-processing network. This step "rectifies" the final output, ensuring that only the new shadow is added while the rest of the background remains pixel-perfect and unchanged.

Data Acquisition: The DESOBAv2 Dataset

A significant contribution of this work is the creation of DESOBAv2, a large-scale dataset that overcomes the limitations of its predecessor. The original DESOBA dataset contained only about 1,000 real images, which is insufficient for training robust diffusion-based models.

The authors developed an automated pipeline to detect object-shadow pairs in real-world images, "inpaint" (remove) the shadows to create a clean background, and then use these pairs for training. This resulted in DESOBAv2, which contains 21,575 real images and 28,573 pairs. This diversity allows the model to learn shadow behavior for a wide array of subjects, including people, animals, vehicles, and complex architectural elements.

Experimental Results

SGDiffusion significantly outperforms previous state-of-the-art models, such as SGRNet and ShadowGAN, across both quantitative and qualitative benchmarks.

  • Quantitative Performance: On the DESOBAv2 dataset, SGDiffusion achieved a Global RMSE of 6.098, a substantial improvement over SGRNet’s 7.184. It also demonstrated superior accuracy in shadow shape, as measured by the Balanced Error Rate (BER).
  • Human Preference: In a user study involving 50 participants, SGDiffusion received a B-T (Bradley-Terry) score of 1.763. This score vastly outperformed the next best model (SGRNet at 0.062), indicating a clear human preference for the realism and integration of the shadows generated by SGDiffusion.
  • Qualitative Success: The model excels in complex scenarios, such as self-occlusion (shadows cast by an object onto itself) and the soft shadows produced by translucent objects.

Discussion and Limitations

While SGDiffusion represents a leap forward, certain edge cases remain challenging. The model occasionally struggles with "floating objects" that do not touch the ground, as the spatial relationship becomes harder to infer. Additionally, internal geometry (e.g., shadows cast through the center of a hollow object) and extreme perspectives can still lead to minor inaccuracies. Future research will likely focus on incorporating 3D spatial awareness to better navigate these complex geometric relationships.

Conclusion

By combining the generative power of diffusion models with specialized intensity modulation and a massive new dataset, SGDiffusion provides a robust solution for realistic shadow generation. This work moves the field of image composition closer to achieving truly indistinguishable synthetic edits, providing valuable tools for creators in digital media and beyond.

Summary updated

BibTeX
@inproceedings{liu2024shadow,
  author = {Qingyang Liu and Junqi You and Jianting Wang and Xinhao Tao and Bo Zhang and Li Niu},
  title = {{Shadow Generation for Composite Image Using Diffusion Model}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2024},
  url = {https://openreview.net/forum?id=H7ibd4EOcw},
}
Figure