Abstract
We demonstrate that deep learning methods can determine the best focus position from 1-2 image samples, enabling 5-10x faster focus than traditional search-based methods. In contrast with phase detection methods, deep autofocus does not require specialized hardware. In further contrast with conventional methods, which assume a static "best focus," AI methods can generate scene-based focus trajectories that optimize synthesized image quality for dynamic and three dimensional scenes.
Introduction
Autofocus (AF) is a fundamental component of modern photography and computer vision. However, current implementations often force a compromise between speed and hardware complexity. Standard software-based contrast maximization is hardware-agnostic but slow, requiring the camera to "hunt" through multiple focal positions to find the sharpest point. Conversely, phase detection and active sensing (e.g., LiDAR) provide near-instantaneous focus but necessitate expensive, specialized sensors that can occasionally compromise image quality.
This research addresses two core challenges: achieving phase-detection speeds using only standard image data and efficiently capturing "focus stacks" for all-in-focus images in dynamic 3D scenes.
Methodology
The proposed system utilizes a deep learning pipeline centered on two primary neural networks:
- The Step Estimator ($f_e$): A Convolutional Neural Network (CNN) that analyzes a 512x512 image patch to predict the absolute distance (in motor steps) to the optimal focus position. Crucially, it predicts magnitude rather than direction.
- The Focus Discriminator ($f_d$): A binary classifier that determines if a patch is "in-focus" or "defocused," serving as the algorithm's termination signal.
For full-scene analysis, a Global Step Estimator—a fully convolutional version of the Step Estimator—generates a "focus deviation matrix." This matrix identifies out-of-focus regions across the entire frame and quantifies their deviation. The workflow is efficient: if the discriminator detects blur, the step estimator predicts the distance. The camera then tests the two possible directions and moves to the target position, typically reaching focus in a single step.
Training and Calibration
The models were trained using the DIV2K and CLIC datasets. A synthetic training set of 20,000 images was generated by applying calibrated blur models (Gaussian or disk filters) to sharp images. To bridge the gap between simulation and reality, the researchers performed a brute-force hardware calibration on a specific camera module (Sony IMX274 sensor with an Evetar lens), mapping physical motor positions to specific blur radii and scaling factors.
Key Insights
The central innovation is the realization that a defocused image contains sufficient structural information to calculate the distance to clarity. While traditional AF algorithms search for a peak in contrast through iterative comparisons, this method predicts the destination directly from the image features. This mimics human intuition; we can often tell at a glance if an image is slightly or significantly out of focus without needing to compare it to other frames.
Furthermore, the system moves beyond the concept of a static "best focus." For complex 3D scenes where objects exist at multiple depths, it generates a focus trajectory—a path the lens follows to capture the necessary depth information for a composite, all-in-focus result.
Results and Performance
In comparative testing, the deep learning approach reached optimal focus in just 1–3 steps. In contrast, rule-based search required 40–80 steps, and Fibonacci search required 13 steps. This represents a 5–10x speedup over traditional software methods.
The system is highly efficient, with a processing time of approximately 3.5 milliseconds per frame on a standard CPU, negating the need for a dedicated GPU. It also demonstrated robustness across various lighting conditions (natural, fluorescent, and incandescent) and noise levels, despite being primarily calibrated under specific laboratory lighting.
Limitations and Future Outlook
The main limitation is hardware dependency; the specific relationship between blur and motor steps is tied to the lens and sensor geometry. While the architecture is universal, new hardware requires re-calibration or fine-tuning.
Current iterations of the Step Estimator do not predict direction, necessitating a "check" step. Future work aims to eliminate this by analyzing a sequence of two frames to determine directionality immediately. Additionally, the researchers are exploring more sophisticated fusion techniques for all-in-focus video in high-speed, chaotic environments.
Summary updated