Compositing Foreground and Background Using Variational Autoencoders

Zezhen Zeng, Jonathon S. Hare, Adam Prügel-Bennett

Abstract

Generative models often struggle to treat objects and backgrounds as independent entities, a process known as disentanglement. This paper introduces BFVAE (Background and Foreground Variational Autoencoder) and LSR-GAN (Latent Space Renderer-GAN), a two-stage framework that achieves high-quality image compositing. By combining the stable, structured latent space of VAEs with the visual fidelity of GANs, the researchers demonstrate state-of-the-art results on fine-grained datasets with significantly reduced computational overhead.

Introduction

In computer vision, disentanglement is the ability to separate distinct factors of an image, such as a bird's shape from its environment. While humans perform this task intuitively, generative models typically struggle. Existing solutions often rely on complex, hierarchical Generative Adversarial Networks (GANs). Although GANs produce sharp images, they are difficult to train, prone to "mode collapse," and lack a continuous latent space for smooth interpolation. Conversely, Variational Autoencoders (VAEs) offer stable training and structured latent spaces but often produce blurry outputs. This research bridges the gap, aiming for VAE-like stability with GAN-level crispness.

Methods

The proposed architecture consists of two primary components: the BFVAE for disentanglement and the LSR-GAN for high-fidelity rendering.

BFVAE: The Disentangler

The BFVAE utilizes two separate VAE streams. The foreground stream (VAE-F) encodes a masked version of the image into a foreground latent vector ($z_f$). The background stream (VAE-B) takes the full image as input. By feeding both $z_f$ and the background latent $z_b$ into the final decoder, the model is forced to store only background information in $z_b$. To ensure true independence, a $\beta$-VAE framework is used to penalize mutual information between the image and the background latent, effectively forcing the background encoder to "forget" the foreground object.

The BFVAE framework disentangles foreground and background components to enable flexible image compositing.

LSR-GAN: The Renderer

To overcome the inherent blurriness of VAE outputs, the authors introduce the Latent Space Renderer-GAN. Instead of training from scratch, the GAN's generator is trained to map samples into the pre-trained, structured latent space of the BFVAE. This refiner produces sharp images while respecting the disentangled factors learned in the first stage.

The foreground stream (VAE-F) encodes masked objects into a latent representation.

Experiments and Results

The model was evaluated on standard benchmarks including CUB (birds), Stanford Dogs, and Stanford Cars.

Performance and Efficiency

The BFVAE+LSR-GAN achieved superior FID scores compared to established models. On the CUB dataset, it reached an FID of 19.12, significantly outperforming MixNMatch (28.25). Notably, the model is highly efficient; its saved size is only 22.1MB, compared to 336.7MB for MixNMatch.

Qualitative Insights

The model successfully performs "one-shot" compositing, taking the style of an object from one image and placing it into the background of another. Interestingly, the authors noted a "harmony" trade-off: when placing an object in an unnatural setting, the model slightly adjusts the background to improve scene coherence, suggesting it learns semantic relationships between objects and environments.

Conclusion

While the model achieves state-of-the-art fidelity and efficiency, challenges remain. The current implementation is limited to $64 \times 64$ resolution and requires binary masks for training. Future work will focus on scaling to higher resolutions and developing fully unsupervised versions that do not require masks. Despite these limitations, the BFVAE+LSR-GAN framework represents a significant step toward stable and efficient image disentanglement.

Summary updated

BibTeX
@inproceedings{zeng2022compositing,
  author = {Zezhen Zeng and Jonathon S. Hare and Adam Prügel-Bennett},
  title = {{Compositing Foreground and Background Using Variational Autoencoders}},
  booktitle = {ICPRAI},
  year = {2022},
  doi = {10.1007/978-3-031-09037-0\_45},
}
Figure