Learning to Autofocus

Charles Herrmann, Richard Strong Bowen, Neal Wadhwa, Rahul Garg, Qiurui He, Jonathan T. Barron, Ramin Zabih · DOI

Abstract

Autofocus (AF) remains a challenging task in digital photography due to noise, optical aberrations, and inherent ambiguities in blurred images. We present a deep learning-based approach that treats AF as an ordinal regression problem. By training a convolutional neural network (CNN) on a large-scale dataset of focal stacks with ground-truth depth, our model achieves a 3.6x reduction in focus error compared to state-of-the-art heuristic methods. Our approach demonstrates robustness to low-light conditions and hardware-specific artifacts like focal breathing.

Introduction

Traditional autofocus systems rely on contrast-based or phase-based heuristics. Contrast-based methods are often slow and susceptible to noise, while phase-based methods using dual-pixel (DP) data require complex, hand-crafted calibration. This paper introduces a learned AF model that leverages a MobileNetV2 backbone to predict the optimal focal distance from 128x128 image patches.

Methodology

The authors frame autofocus as an ordinal regression task. Instead of a binary classification, the model predicts one of 49 discrete focal distances. An ordinal regression loss is employed, using a Laplacian distribution to penalize predictions based on their distance from the ground truth. The model is evaluated across three primary scenarios: Single-Slice, Focal Stack, and a Multi-Step iterative approach.

Figure 1: Comparison of autofocus scenarios: (a) Single-Slice, (b) Focal Stack, and (c) Two-Step iterative approach, showing the resulting probability distributions across focal indices.

Dataset and Training

A significant contribution is the creation of a realistic AF dataset. Using a custom rig of five synchronized Google Pixel 3 smartphones, the researchers captured 51 diverse scenes. Ground-truth depth maps were generated via multi-view stereo, providing a "gold standard" for focus. The dataset comprises over 440,000 patches, including raw dual-pixel data and capturing real-world effects like sensor noise and focal breathing.

Key Insights: Resolving Ambiguity

A critical challenge in AF is the "front-vs-back" ambiguity, where a single blurred image does not clearly indicate if the subject is in front of or behind the focal plane. The study reveals that while single-slice RGB inputs often result in bimodal probability distributions, the inclusion of dual-pixel data resolves this ambiguity. The phase difference in DP data provides a directional signal that guides the model toward the correct focal plane.

Figure 2: Optical diagrams comparing (a) an ordinary sensor with (b) a dual-pixel sensor, which captures phase information to resolve depth ambiguity.

Results

The learned model significantly outperforms traditional baselines. In the "Single Slice" task, the Mean Absolute Error (MAE) was reduced from 11.3 to 3.1. Notably, the model maintains high accuracy in low-light environments where contrast-based methods typically fail. The inference time is approximately 32.5 ms on a flagship smartphone, demonstrating its feasibility for real-time mobile applications.

Conclusion

This work demonstrates the power of deep learning in solving fundamental computer vision problems like autofocus. While the current model is optimized for specific hardware, future research could explore generalization across different sensor architectures and integration with saliency models to automate subject selection in complex scenes.

Summary updated

BibTeX
@inproceedings{herrmann2020learning,
  author = {Charles Herrmann and Richard Strong Bowen and Neal Wadhwa and Rahul Garg and Qiurui He and Jonathan T. Barron and Ramin Zabih},
  title = {{Learning to Autofocus}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2020},
  doi = {10.1109/cvpr42600.2020.00230},
}
Figure