3D-aware Blending with Generative NeRFs

Hyunsu Kim, Gayoung Lee, Yunjey Choi, Jin-Hwa Kim, Jun-Yan Zhu

TL;DR

Seamlessly blending images with different camera angles or object shapes has long frustrated 2D image editing tools. This paper introduces a novel 3D-aware blending framework that leverages generative Neural Radiance Fields (NeRFs) to automatically align and compose images within a geometrically consistent 3D latent space. The result is a highly realistic blend that preserves complex structures (like hair and fur) and can even be rendered from entirely new viewpoints.

What Problem Does This Paper Address?

Traditional image blending methods—whether classic gradient-based approaches like Poisson blending or modern deep learning models—share a common flaw: they operate entirely in 2D. They assume that the foreground object and the background scene are already perfectly aligned in terms of camera pose and 3D shape.

When you try to blend two unaligned images (for instance, pasting a face looking slightly to the left onto a head facing forward), 2D methods inevitably produce unnatural distortions, ghosting artifacts, or perspective mismatches. While some methods try to warp images using 2D affine transformations, they cannot account for out-of-plane rotations or genuine 3D geometric differences. This paper addresses this gap by lifting the image blending problem into 3D space using generative NeRFs as a geometric prior.

Figure 2: Comparison with the existing blending methods. Red lines denote target blending parts. (a) 2D blending. 2D blending methods compose two images without any 3D-aware alignment. (b) 2D blending with 3D-aware alignment. To address misalignment, we apply our 3D-aware alignment method to existing 2D blending methods. (c) Proposed method. We propose 3D-aware blending after applying our 3D-aware alignment. Note that all methods do not use 3D labels or 3D morphable models.

Methods

The proposed method consists of two main stages: 3D-aware alignment and 3D-aware blending.

  1. 3D-Aware Alignment:
  2. Global Pose Alignment: The system first uses a trained CNN encoder to estimate the 3D camera poses of both the original (background) and reference (foreground) images. Using Pivotal Tuning Inversion (PTI), both images are projected into the latent space of a pre-trained generative NeRF (like EG3D). The reference image is then re-rendered from the camera pose of the original image, effectively matching their global orientations.
  3. Local Alignment: For loosely aligned datasets where parts might still differ in scale or position (e.g., different ear or eye sizes in cats), the authors extract 3D meshes using the Marching Cubes algorithm. They then apply the Iterative Closest Point (ICP) algorithm to calculate a 3D transformation matrix that finely aligns the target regions.
  4. 3D-Aware Blending: Instead of mixing pixels directly, the authors optimize a blended latent code ($w_{edit}$) in the NeRF's $W+$ latent space. This optimization is driven by a combination of two losses:

  5. 2D Image-Blending Loss: Matches the color and perceptual features (via LPIPS) of the background to the original image and the foreground to the reference image.

  6. 3D Density-Blending Loss: This is the core innovation. It samples points along camera rays and forces the 3D volume density ($\sigma$) of the edited space to match the reference object's density in the foreground mask and the original object's density in the background.
  7. Poisson Blending Integration: To perfectly preserve high-frequency background details (like earrings or fine textures) that GAN inversion might slightly smooth out, the authors optionally pass the final NeRF-rendered output through a classic 2D Poisson blending step.

Datasets

The authors evaluated their approach across multiple distinct domains using the following datasets:

  • FFHQ & CelebA-HQ: Used for training and evaluating human face blending.
  • AFHQv2-Cat: An animal face dataset used to test the method's robustness against high structural and shape variability (e.g., varying ear shapes and fur textures).
  • ShapeNet-Car: A dataset of rigid 3D vehicles used to demonstrate that the method generalizes well beyond facial data.

Key Insights and Ideas

  • Density is Crucial for Structure: One of the paper's key findings is that optimizing for 2D pixel appearance alone causes complex, highly structured geometries (like hair or animal fur) to become blurry. Incorporating a 3D volume density loss forces the network to respect the underlying geometric boundaries, keeping fine details sharp.
  • Color-Geometry Disentanglement: Because the blending occurs within a generative latent space, the authors show they can control the influence of the reference image's color versus its geometry. By tuning the weight of the reference image's color loss ($\lambda_2$), a user can choose to blend only the shape of a reference object while inheriting the color/style of the original, or vice versa.
  • Free Multi-View Consistency: Because the final output is a fully realized NeRF latent code, the blended result isn't just a static 2D image. The composite object can be rendered seamlessly from entirely novel camera angles with perfect 3D consistency.

Key Results

The method was compared against strong 2D baselines, including SDEdit (diffusion-based), StyleMapGAN, and StyleGAN3.

  • Quantitative Performance: On the CelebA-HQ benchmark, the proposed method combined with Poisson Blending achieved a state-of-the-art Kernel Inception Distance (KID) of 0.002 and a masked LPIPS of 0.188, significantly outperforming all 2D baselines (which suffered from high LPIPS scores due to identity loss or misalignment artifacts).
  • User Studies: Human evaluation via Amazon Mechanical Turk confirmed these results. In pairwise comparisons on unaligned images, users preferred the proposed 3D-aware method over baselines by significant margins (e.g., over 79% preference compared to standard Poisson Blending alone).

Limitations and Future Work

  • Inversion Bottleneck: The framework relies heavily on GAN inversion (PTI) to project real images into the NeRF latent space. This process is computationally slow, taking roughly 44 seconds per image on an NVIDIA A100 GPU, which prevents real-time interactive editing.
  • Out-of-Distribution Failures: If an input image features extreme poses, unusual expressions, or rare accessories that fall far outside the pre-trained 3D GAN's training distribution, the inversion process can fail, leading to distorted or "crushed" geometry.
  • Future Directions: The authors point toward integrating faster, feed-forward encoder-based 3D GAN inversion techniques to accelerate the pipeline for real-time applications.

Summary updated

BibTeX
@inproceedings{kim2023d,
  author = {Hyunsu Kim and Gayoung Lee and Yunjey Choi and Jin-Hwa Kim and Jun-Yan Zhu},
  title = {{3D-aware Blending with Generative NeRFs}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2023},
  doi = {10.1109/iccv51070.2023.02094},
}
Figure