Abstract
Depth-from-focus (DFF) is a technique that infers depth using the focus change of a camera. In this work, we propose a convolutional neural network (CNN) to find the best-focused pixels in a focal stack and infer depth from the focus estimation. The key innovation of the network is the novel deep differential focus volume (DFV). By computing the first-order derivative with the stacked features over different focal distances, DFV is able to capture both the focus and context information for focus analysis. Besides, we also introduce a probability regression mechanism for focus estimation to handle sparsely sampled focal stacks and provide uncertainty estimation to the final prediction. Comprehensive experiments demonstrate that the proposed model achieves state-of-the-art performance on multiple datasets with good generalizability and fast speed.
Introduction
Estimating depth from a single RGB camera is a fundamental challenge in computer vision, with applications ranging from augmented reality to 3D reconstruction. While many approaches rely on motion cues or specialized hardware, Depth-from-Focus (DFF) leverages the inherent focus changes of a camera as it sweeps through various focal distances, known as a "focal stack."
Traditional DFF methods, however, face significant hurdles. They often require dense focal stacks (10–30 frames) to accurately identify the sharpest point, leading to high computational costs. Furthermore, textureless regions—such as plain walls—lack the edges necessary for traditional focus measures to succeed. Finally, many existing deep learning models for DFF are generic adaptations from other domains and do not fully exploit the unique geometry of focal changes.
Proposed Method: Differential Focus Volume
To address these challenges, we propose a specialized CNN architecture designed specifically for the physics of focus.
Architecture Overview
The pipeline begins with a shared 2D CNN (ResNet-18 with a Feature Pyramid Network) that extracts deep features from each image in the focal stack. These features are then organized into a Focus Volume (FV).
Deep Differential Focus Volume (DFV)
The core innovation is the Differential Focus Volume (DFV). Instead of processing a simple stack of features, the network computes the first-order derivative (the difference) between adjacent focal planes. Mathematically, the peak of a focus curve corresponds to where its derivative crosses zero. By explicitly providing these differences, the network can more effectively pinpoint the "zero-crossing" point where a pixel is perfectly in focus.
3D CNN and Probability Regression
A 3D CNN processes the DFV to integrate spatial context, allowing the model to infer depth in textureless regions by leveraging information from surrounding textured areas. Finally, rather than a "winner-take-all" selection of the best frame, we employ a probability regression mechanism. This predicts a probability distribution across the stack, enabling sub-frame accuracy—estimating depth values between captured images—and generating an uncertainty map to indicate prediction confidence.
Experimental Results
The model was evaluated on the synthetic FoD500 dataset, the real-world DDFF-12 light-field dataset, and the Mobile Depth dataset for generalization testing.
Performance and Efficiency
Our model, "Ours-DFV," achieved state-of-the-art results, ranking 1st on the DDFF-12 public leaderboard at the time of submission. The model is highly efficient, processing a 256x256 stack in approximately 18.2 ms on an NVIDIA 1080Ti. This speed, combined with the ability to achieve superior results using only 5 frames (compared to the 30 frames often required by traditional methods), makes it highly suitable for real-time mobile applications.
Qualitative Analysis
Qualitative results demonstrate that our approach preserves object boundaries and fine details significantly better than competing deep learning models like DDFF and DefocusNet. The inclusion of uncertainty estimation provides a reliable measure of where the model's predictions may be less accurate, typically in extremely low-texture or occluded regions.
Conclusion
We have presented a novel CNN-based approach for Depth-from-Focus that utilizes a Differential Focus Volume to enhance focus cues. By combining this with 3D context aggregation and probability regression, our method achieves state-of-the-art accuracy and real-time performance while requiring fewer input images. Future work will focus on integrating alignment modules to handle dynamic scenes and camera motion during the focal sweep.
Summary updated