NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Bridging Unsupervised and Supervised Depth from Focus via All-in-Focus Supervision

Ning-Hsu Wang, Ren Wang, Yu-Lun Liu, Yu-Hao Huang, Yu-Lin Chang, Chia-Ping Chen, Kevin Jou

TL;DR

This paper introduces a novel deep learning method that jointly estimates a scene's depth map and an all-in-focus (AiF) image from a sequence of differently focused photographs (a focal stack). By leveraging a shared architecture with a clever dual-normalization strategy, the network can be trained unsupervisedly using only ground-truth AiF images, bypassing the need for hard-to-acquire ground-truth depth data.

What Problem Does This Paper Address?

Traditional depth estimation methods often assume images are entirely sharp (all-in-focus), which isn't always true in real-world photography where background blur (defocus) occurs. "Depth-from-focus" (DfF) techniques exploit this blur to calculate depth from a "focal stack"—a series of images taken at different focus distances.

However, training deep learning models for DfF typically requires high-quality ground-truth depth maps. Collecting these maps in the real world requires expensive, power-hungry hardware like Time-of-Flight (ToF) sensors, which are often noisy and imperfect. While synthetic datasets can provide perfect depth maps, models trained on them struggle to generalize to real-world optics. The authors address this bottleneck by finding a way to train DfF models unsupervisedly using only AiF images, which are significantly easier to capture (e.g., by using a small aperture and a long exposure).

Methods

The authors propose AiFDepthNet, an encoder-decoder network built on 3D convolutions (specifically using an Inception3D backbone). Unlike 2D convolutions, 3D convolutions natively process the stack dimension, allowing the network to effectively track how blur changes across different frames.

Figure 1: An overview of the proposed method. Given a stack of images with varying focus positions, i.e., focal stack, our model first produces an intermediate attention map M. The intermediate attention map can be shared between depth estimation and all-in-focus (AiF) image reconstruction. With different normalization functions, the attention map can be further manipulated to generate either depth or AiF results.

The core innovation lies in how the network handles its intermediate representation:

  1. Shared Attention Map ($M$): The network outputs a single intermediate attention map $M$ that represents the probability of each focus position yielding maximum sharpness.
  2. Asymmetric Normalization: To split this map into two distinct tasks, the authors apply two different mathematical functions:
  3. For AiF Image Reconstruction (Softmax): A softmax function is applied to create a sharp, "peaking" distribution. This forces the network to select only the single sharpest pixel across the focal stack.
  4. For Depth Estimation (Softplus): A softplus normalization creates a flatter, smoother probability distribution. This allows the network to interpolate between sparse focus positions, yielding highly accurate, continuous depth values rather than quantized steps.
Figure 2: The effect of normalization on attention maps. The first row shows that if we adopt the same softmax nor- malization for depth and AiF attention, both of them tend to be a flatter distribution in supervised learning and face a peaking phenomenon in unsupervised learning (AiF su- pervision). The second row shows that with separate nor- malization as described in Sec. 3.3, each of depth and AiF attention becomes a proper distribution in both supervised and unsupervised learning.

For unsupervised training, the model minimizes the $L_1$ loss between the reconstructed AiF image and the ground-truth AiF image, combined with an edge-aware smoothness loss to ensure spatial consistency in the depth map.

Datasets

The method was evaluated across five distinct datasets:

  • DefocusNet Dataset: A synthetic dataset rendered using physically based rendering (PBR) shaders.
  • DDFF 12-Scene: A real-world dataset captured using a light-field camera.
  • 4D Light Field Dataset: A synthetic dataset that simulates large synthetic apertures and shallow depths of field.
  • Middlebury Stereo Datasets: A classic real-world stereo dataset used here to evaluate cross-dataset generalization.
  • Mobile Depth: A real-world dataset consisting of focal stacks captured directly with mobile phones.

Key Insights and Ideas

  • The Normalization Paradox: The most compelling insight is that the same attention map requires completely different mathematical treatments depending on the task. Using softmax for depth causes severe quantization errors because it snaps to the nearest discrete focal plane. Conversely, using softplus for image fusion creates ghosting artifacts by blending blurry pixels. Splitting them solves both problems simultaneously.
  • AiF Images as Depth Supervisors: The paper proves that an image reconstruction task (making a sharp picture) contains enough implicit geometric constraints to train a highly accurate depth estimator without ever showing the network a true depth map.

Key Results

  • State-of-the-Art Performance: When trained with full supervision, AiFDepthNet outperformed existing state-of-the-art methods (like DefocusNet and DDFF) across multiple benchmarks. On the 4D Light Field Dataset, it achieved a Mean Squared Error (MSE) of 0.0472, beating DefocusNet's 0.0593.
  • Strong Unsupervised Baseline: Even when trained without depth data (unsupervised), the model performed comparably to, and sometimes better than, older fully supervised methods.
  • Robustness to Stack Size: Thanks to the 3D convolutional architecture, the model can handle arbitrary focal stack sizes at test time, showing improved depth quality as more images are added to the stack.
  • Efficiency: The model achieves faster inference times than competing deep learning methods because it avoids architectural bottlenecks like global pooling layers.

Limitations and Future Work

The authors note a prominent real-world challenge: focus breathing. When a physical camera lens shifts focus, its field of view changes slightly, causing a zooming effect across the focal stack. While the synthetic training data assumes a perfect pinhole camera without this effect, real-world testing requires an explicit pre-calibration step to align the images. Integrating focus-breathing compensation directly into the neural network architecture remains an open avenue for future research.

Summary updated

BibTeX
@misc{wang2021bridging,
  author = {Ning-Hsu Wang and Ren Wang and Yu-Lun Liu and Yu-Hao Huang and Yu-Lin Chang and Chia-Ping Chen and Kevin Jou},
  title = {{Bridging Unsupervised and Supervised Depth from Focus via All-in-Focus Supervision}},
  year = {2021},
  eprint = {2108.10843},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2108.10843},
}
Figure