Did you ever wonder how your smartphone manage to focus on any place you tap on the camera app? 🙂 Okay, even if u did or didn’t now you gonna find how.
To achieve the correct focus, modern digital cameras have come up with 3 approaches such as, ACTIVE, PASSIVE and HYBRID. In ACTIVE approach they use separate sensor mechanism to detect focus. In PASSIVE approach, it uses algorithmic ways to find correct focus from the input of the optical system. There are few ways doing this, I’m gonna show you, how it is done with “contrast detection” method.
So let’s jump into some facts. 😉
When a region is at its sharpest focus, the adjacent pixels in the region will be at maximum contrast. In other words, the difference between intensity levels in the focused region is higher than the differences between intensity levels in the unfocused region.
What will happen to the image mean when it is focused or blurred? So let us take a sample image, make it blur and calculate the mean of those two. I blurred the image using gimp (gaussian blur radius 10px) and calculated image statics using
min: 0 (0)
max: 255 (1)
mean: 63.7428 (0.249972)
standard deviation: 80.7208 (0.316552)
min: 0 (0)
max: 255 (1)
mean: 63.7887 (0.250152)
standard deviation: 76.3692 (0.299487)
identify -verbose independent-arcade-lightings.jpg command will pull out all image statistics of you image.
So you can see, mean of both original and blurred images is same. 🙂 So image mean does not affect with the focus of the image. Also, you can see that standard deviation is the variable which has changed with the blurring. An image’s standard deviation is directly related to its contrast. (standard deviation expresses by how much the members of a group differ from the mean value for the group)
So we can conclude 2 facts about focus.
- focus does not affect image mean.
- the spread of the pixel intensities (standard deviation) is affected by focusing.
Now we have a great way to measure if a region is focused or not. What we want to do is to implement a mechanical control system for the camera lens to achieve the highest possible contrast of the region. And that is what actually comes with PASSIVE AF digital cameras. The system can be modeled like below.