Principles behind the algorithms

In this figure, f is the focal length, d0 is the distance between the object plane and the lens, and d1 is the distance between the lens and the image plane. Variations in any of the above three parameters, f,d0 and d1, will result in changing the focus.
Since the point p is focused in front of
the image plane, the resultant image q will be blurred. According to
geometric optics, q has the same shape as the lens aperture.
The response of a camera lens system to an ideal point source of light --
point spread function, is defined as
while its fourier transform is
This function is imversely proportional to R.
Since the energy of an image is directly proportional to the
transfer function while the focus is inversely proportional to R, we may
be able to use the image energy to estimate the size of R.
It is found that the high frequency content of the image determines its
sharpness. As such, the energy of the image gradient is often employed for
focus measure.
Assume that
the lens aperture is circular, the image is also a circle of radius R. This
is called a blur circle or a circle of confusion. The smaller the R, the
better the focus.
If it is possible to measure the size of R in the given
image, the autofocus can be done by simply finding the image having the
smallest value of R.
Since this is not possible in reality, we need
alternative quantities which are dependent on R.
Power/Variance Method

Gradient Method - measuring the high frequency component.