Summary of AF Autofocus Algorithms and PDAF Working Principles
- 07 Aug, 2020
Definition and Basic Classification of AF Autofocus Algorithms
- AF: Auto Focus.
- Basic definition of autofocus: The image sensor in a camera receives light reflected from an object. Based on internal calculations and processing within the camera, an electric focusing mechanism then adjusts the lens to achieve focus.
- Based on whether the camera needs to actively emit light towards the subject during the autofocus process, autofocus algorithms can generally be divided into active and passive types.
- Active Autofocus: Active methods require emitting a light source, then receiving the reflected echo to measure distance and focus (meaning the lens module needs to actively emit light and measure its echo to assist focusing).
- Typical active autofocus solutions include Laser AF and Infrared AF. The working principle of laser autofocus is that during focusing, a dedicated laser emitter projects a laser beam onto the subject. This laser is then used to measure the subject’s distance, calculating where the lens should be adjusted.
- Passive Autofocus: Passive methods do not require an additional light source. The optical system only receives reflected light from the subject itself for detection and calculation, determining the required lens movement (the lens module does not need to emit light; it solely relies on the light reflected by the subject for focus calculations).
- Common passive autofocus strategies include Contrast AF (Contrast Detection Auto Focus, CDAF) and PDAF (Phase Detection Auto Focus).
- Active Autofocus: Active methods require emitting a light source, then receiving the reflected echo to measure distance and focus (meaning the lens module needs to actively emit light and measure its echo to assist focusing).
- From the above definitions, it can be seen that for general camera products and smartphone cameras currently on the market, the vast majority of cases involve passive autofocus. Among these, the PDAF focusing strategy is a hot application direction in the current market due to its fast focusing speed.
Contrast Detection Based AF Algorithm
- Contrast AF (or Contrast Detection Auto Focus, CDAF) primarily determines focus by detecting the point of highest contrast during the camera’s back-and-forth lens adjustment.
- Its basic principle is: generally, when a camera lens is adjusted to its optimal position, the overall image contrast is highest, and the edges of objects in the image are sharpest. Therefore, by repeatedly adjusting the lens position and calculating the overall image contrast in real-time, the position where the image contrast is highest is considered the camera lens’s in-focus position.
- Overall focusing process for Contrast AF: Contrast-based autofocus involves the sensor continuously imaging the subject during the focusing process. The processor calculates the contrast or sharpness of the captured image (which is essentially the degree of brightness difference within the image; the clearer the image, the greater the brightness difference). Higher contrast indicates sharper focus. However, there will inevitably be a phase where contrast starts to decrease (indicating the lens has overshot the focus point), at which time the lens needs to be adjusted back. Therefore, because this entire process involves continuously capturing and calculating multiple images, and also inevitably requires correcting for overshooting, the overall focusing speed is definitely slow. This is the biggest drawback of this focusing method.
- The entire focusing process is shown in the figure below:

- Pros and Cons:
- No other additional hardware components are needed, leading to lower implementation costs and easier system realization; focusing effect is good.
- As mentioned above, because the lens needs to be driven back and forth to find the optimal focus point, focusing takes a longer time (approximately 1 second). Focusing performance is poor in low-light environments because the overall contrast difference in such environments is not pronounced. Due to its slow focusing speed, it is not suitable for tracking moving objects.
PDAF-based AF Algorithm
- PDAF: Phase Detection Auto Focus, an autofocus solution based on phase detection.
- The implementation of PDAF autofocus solutions relies on the use of specialized PDAF sensors. These sensors contain paired PD Pixels (generally, the number of PD Pixels on a sensor accounts for 5%-10% of the total pixels). These paired PD Pixels, arranged in a specific layout, resemble human left and right eyes:


- PDAF autofocus involves reserving PDAF pixels on the image sensor. These PDAF pixels are specifically used to assist in phase detection, calculating the focus offset through phase difference to achieve accurate focusing. Compared to contrast autofocus, phase detection autofocus does not require repetitive lens movement, thus making the focusing speed inherently faster.
- These PDAF pixels, meticulously arranged and positioned on the Image Sensor, generate real-time “left-looking” and “right-looking” images during the focusing process. The calculation of the “phase difference” is the result of mathematical operations performed on the data from these two images. Then, based on the calculated phase difference, a lookup table is used to determine the lens’s movement direction and distance.

- To implement PDAF focusing: Firstly, the image sensor (CIS) itself must support PDAF. Secondly, the camera needs to calibrate phase data at different distances. This data primarily establishes the correspondence between phase difference and object distance. When taking a photo with a smartphone, phase difference information is obtained. This phase difference information, based on internal calibration data, is used to determine the current lens position and calculate the required direction and distance of movement.
- In other words, the relationship between object distance, lens position, and phase difference needs to be calibrated in advance. In practical applications, the phase difference can be obtained from the image output by the PDAF sensor. This phase difference is then used to look up a table correlating object distance and lens position, determining the required adjustment distance for the lens, and then controlling the electric lens to move to the specified position.
- Pros and Cons:
- Compared to contrast-based autofocus solutions, the focusing speed is faster, completing the focusing process in approximately 0.3 seconds. Due to its faster focusing speed, it can be used for continuous tracking autofocus in scenarios involving moving objects.
- Similar to contrast-based autofocus solutions, focusing performance is poor in low-light environments. It requires a specialized PDAF image sensor, which increases cost, and is generally only used in high-end consumer cameras and smartphones.
- Passive focusing solutions are generally not well-suited for low-light environments. Therefore, for such application scenarios, either a flash or auxiliary light source is needed to assist in focusing in low-light, or active autofocus solutions like infrared or laser focusing must be employed.