Thursday, July 9, 2015

How Does Autofocus Actually Work?


Autofocus is a feature of modern cameras that’s easy to take for granted. But have you ever stopped to ask yourself how it works? Focusing a manual lens can be a painstaking and frustrating process, especially for amateurs — so how does your smartphone do it so easily?
It turns out that that there are actually several technologies that are used to achieve an autofocus effect. Let’s start by explaining what focus is, and then how the computer in your phone can manipulate it to get a sharp image.

How Focus Works


The lens in your smartphone camera serves the same purpose as the lens in your eye: to take the light that hits it and project it onto a sensor so that an image can be recorded.
The exact curvature of the lens dictates how far away the sensor has to be to produce a clear image. If you’ve ever used a magnifying glass to burn wood on a sunny day, you know that it must be held at exactly the right distance to focus the light.
The same happens with cameras: if the distance is wrong, the image is out of focus and therefore blurry. This distance is known as the lens’s “depth of focus”.
To complicate matters, the angle at which light hits a lens changes its depth of focus. A flatter lens focuses parallel light rays from a far-off source but blurs the angled light coming from peripheral objects. A more curved lens would do the opposite.
The video below goes into a detailed explanation of how lenses work, if you’re interested:

You can see this effect yourself by holding up two thumbs, one near your face and the other at arm’s length. If you shut one eye, you’ll find that you can shift your focus between the thumbs. When the far one is clear, the near one becomes blurry, and vice-versa.
In the case of your eye, the change in focus is done by using tiny muscles to physically alter the shape of the lens. Over-working these muscles tires them, which is why you get eyestrain from looking at close-up objects for too long.
In cameras, which use rigid plastic or glass lenses, the whole lens is mounted on a motor, which can change its distance from the sensor to achieve the desired focus. Objects that are at the correct focal distance will be sharp while objects that are too near or too far will be blurry.
The question is, how does the camera know the right distance for its lens?

Methods of Active Autofocus

Samsung_Galaxy_S5
The simplest method of autofocus is to use a mechanical system that finds the distance to the subject of the image, then uses that to dictate the focus.
The earliest patent, filed by Polaroid in 1986, used sonar. It pulsed the target with ultrasound and used the echo to determine distance. This works, but can fall afoul when shooting through clear-but-solid surfaceslike glass. If you try to take a picture out a window, the autofocus feature will detect the echo from the glass and focus on that, leaving the image beyond it a blur.
More modern systems use light, specifically infrared light. They produce a pulse of IR light and either measure the amount that is reflected back or the time it takes for the light to return, then use this information to determine distance. If you look at your phone’s camera and see two small diodes next to it, this is probably how your phone computes focus.
This approach is simple and tends to work reasonably well, but it has drawbacks. Some surfaces absorb infrared light, which can lead to an inaccurate distance reading. Beyond that, any IR source (such as an open flame or a bright incandescent light) can overwhelm the returning light and render the autofocus inoperable. Try to avoid these scenarios if you want to get good photos with an active autofocus camera.
So, what’s the alternative?

Methods of Passive Autofocus

Passive autofocus can be a good deal more expensive to implement, so you tend to see it primarily on SLR cameras (both digital and analog). Passive autofocus works by performing a mathematical analysis on the raw image data itself to determine whether or not it is in focus.
Cut-away_Minotla_SLR_IMG_0377
The most common form of passive autofocus is “contrast detection”, which samples one or more strips of pixels from the center of the image and measures the pixel-to-pixel contrast, adjusting the lens to try to find the configuration that maximizes this contrast.
This works because blurry image regions inherently have less contrast, and since this method isn’t confused by IR light sources or material surfaces, it’s a more robust than active autofocus. In one sense, this is the most accurate way to judge focus because it is directly measuring the sharpness of the image.
In fact, it is so effective that it can even focus through a lens that changes the focal properties of the camera — a scenario in which every other approach fails. On the downside, contrast detection can take a while to find a good focus (because it has to test many possibilities) and it can have trouble in scenes that lack high-contrast (like in low light photography).
E-30-Cutmodel
A different approach to passive autofocus is called “phase detection”, which uses two microlenses to capture samples of incoming light and project them onto two sensors. By analyzing the difference between these images, the camera can very accurately determine how parallel the light rays entering the camera are and use this information to achieve the correct focus.
This is a very fast way to determine optical focus but is expensive due to the need for additional lenses, mirrors, and sensors, so you’ll see it more in high-end rather than entry-level DSLR cameras. Not only that, but it can be less accurate than contrast detection, especially for complicated subjects that have components at several depths.

More recently, we’ve begun to see “hybrid” passive autofocus systems crop up, which use phase detection to jump to a good focus, then use contrast detection to make small refinements for best possible focus. In a lot of ways these cameras offer the best of both worlds (speed and accuracy) but they are currently very expensive. Hopefully, costs will come down over the next several years.

Autofocus and You

These are the four main approaches to autofocus in common use today. In the future we may see “light field cameras” become more popular, which capture images at every possible focus and choose the best one. Until then, we have to work around the limitations of the available technology.
So how do you get good pictures out of an autofocus camera?
  • The most important thing is to hold the camera steady and make sure the focus has totally converged. That goes double if you’re using a contrast or range-based autofocus system that may need a few seconds to find the right focus.
  • You also need to make sure that your subject is at the proper autofocus point, usually the center of the viewfinder but not always. This is something that pretty much all autofocus systems depend on.
  • Finally you need to be aware of the technology you’re using and make sure your scene is a good match for it. Don’t try to directly focus on a bright IR light source using an active system. If you’re using a contrast-based system, avoid taking photos that are a single color (like a blank wall) and avoid taking photos at night.
Aside from that, you pretty much don’t have to think about it. In a way, that’s sort of the point.
Are you a photographer? Have any tips to share for dealing with autofocus? What’s your favorite camera? Let me know in the comments!
Image credits: “Samsung Galaxy S5“, “SLR“, “DSLR“, by Wikimedia  Source: www.makeuseof.com

No comments:

Stream for free

I was written to because I cited Roku on  this page  at Balunywa Bytes.  Here at KillTheCableBill.com, we're helping people beat inflati...