Digital camera auto-focus - Page 1
Forum section: electronics / general

author: akis
author_rank: Frequent Contributor
timestamp: November 04, 2015, 08:42:35 am
content: I have asked this question on other forums to be met with derision... I hope I have not asked here tooI have tried this on a number of digital cameras, on phones, tablets, cameras.When I try to focus onto something really close up, you can see, and hear, the lens attempting to auto-focus, and while it is "whirring" trying to get a clean image, it goes something like this:Auto-focus process: Most terrible blur, terrible blur, moderate blur, blur, little blur, PERFECTLY IN FOCUS, little blur, blur, moderate blur.What I am trying to describe here is that while it is auto-focusing, it passes through a setting where the image is perfectly in focus, perfectly clear, but the software that guides the process ignores it, and continues focusing to the opposite direction, so you cannot get a clear picture.I have to say this is for very close up shots most likely beyond the specified minimum distances.But I can see with my own eyes that the lens is perfectly capable of focusing even closer, but why does it not stay focused at the point where the shot is perfectly clear in focus?

author: Kilrah
author_rank: Unknown
timestamp: November 04, 2015, 09:39:54 am
content: Quote from: akis on November 04, 2015, 08:42:35 amThen you're indeed closer than the minimum focusing distance of the lens. It may look on the (low resolution) screen to you like it passes through a point where it's "perfectly in focus", but it actually isn't at the pixel-level the camera AF system is looking at and trying to achieve. The focus motor hit the stop before it actually got good enough for the camera to consider it focused, so it just goes back and tries again, of course always unsuccessfully since the subject is still too close.If you really want to take the shot and the camera won't let you jsut switch to manual focus at the close end and take your shot, but... it won't be in focus and you'll be disappointed when you look at it on a large screen.Depending on the lens moving back and zooming in if not already done might give you greater magnification.Funnily I had that exact situation yesterday when I realised on a new lens that the minimum focus distance was longer than I expected.

author: akis
author_rank: Frequent Contributor
timestamp: November 04, 2015, 10:01:24 am
content: Thanks for your reply.One of the devices is a 1920x1080 screen phone, with an 8MP camera, and I can clearly see it reaching clear focus, it is not an artifact of my display or my eyes. The other device is a 10.5" tablet with 2560x1600 resolution and again I put my fingers very close to the camera lens and again it fails to focus, however while it is trying it goes through a point where the picture is perfect. I am not dreaming this.I would like to propose the idea that in order to focus the software looks for very sharp contrast and tries to maximise this contrast. For example taking a photo of a plain A4 white page maybe problematic, but if you draw a thin, black line on the page it will use this as a focusing point.It may just be than when I try to focus onto something really very close, there are no "thin lines" of contrast to latch on. For example if I try to take a picture of my finger very close to the lens, it will not be able to focus, however if I draw a very very thin black line on my finger it may just be able to do it?

author: Mechatrommer
author_rank: Super Contributor
timestamp: November 04, 2015, 11:22:06 am
content: Quote from: akis on November 04, 2015, 08:42:35 ambecause it does not have a brain like human does... google contrast detection and phase detection focusing method. those are 2 kind of famous camera focusing brain...

author: tooki
author_rank: Super Contributor
timestamp: November 04, 2015, 12:04:05 pm
content: Quote from: akis on November 04, 2015, 08:42:35 amThis phenomenon is called "hunting", and as others have said, it's because it's not actually in focus when you think it is. The reduced resolution of the viewfinder or LCD simply isn't high enough for you to see that it's not in focus. A 1080p phone screen is still only 2MP, so it simply is not adequate to tell you whether it's fully in focus or not. (Close? Maybe. Fully? Nope.) Of course, 1080p in a 5" screen also far exceeds the resolution of the human eye at normal arm's-length viewing distance, so you couldn't tell anyway.Your "proposal" is simply how contrast-detection AF works, and indeed, adding contrast helps. But if the AF system cannot findanythingwith enough contrast between adjacent pixels, it has to give up at some point. ("Enough" contrast is a variable that changes with lighting conditions, etc, not an absolute number.) If you are outside the lens's focusing range, it cannot focus, period. That's what you are running into.Additionally, AF systems are generally programmed to prefer focusing at "normal" shooting distances, so as to avoid accidentally focusing on unwanted foreground objects. That's why, if the AF system finds multiple distances at which there is focus, it generally prefers mid-distance settings (along with looking at which setting gives the highest contrast across the largest area). This is what trips up holding a small object at close range: yes, it finds a small area of contrast at very close range, but it finds a far larger area of contrast at a longer range, so it chooses it. If a camera has a macro mode, you're generally telling it to instead prefer close objects.Quote from: Mechatrommer on November 04, 2015, 11:22:06 amThere's actually a third, which we don't see any more: ultrasonic. This was most commonly seen in Polaroid cameras. This used an ultrasonic transducer to essentially perform sonar to determine the distance of the subject. The big problem with it is that it cannot work through glass at all, for obvious reasons. (My understanding is that a similar concept exists using infrared light, but I don't know of any commercial implementations.)As an aside, why the hell did Sony stop using its laser-holographic AF focusing aid? It used lasers to project a crosshatch pattern in dark situations, so the AF system could focus even in complete darkness. It was brilliant and worked exceptionally well. It baffles me that this has not been widely adopted.

author: tooki
author_rank: Super Contributor
timestamp: November 04, 2015, 12:09:08 pm
content: P.S. Modern cameras actually use very advanced algorithms for focusing, such as performing face-detection and giving priority to them. Nikon even does that in DSLRs, where it uses fairly high resolution RGB metering sensors to decide which phase-detection focusing sensors to use, based on tracking skin tones.

author: dom0
author_rank: Super Contributor
timestamp: November 04, 2015, 05:11:41 pm
content: The most basic contrast AF works by looking at local contrast deltas between focusing steps. When the sign switches, focus is locked. But when the focusing motors hits the end before the sign switches, focus cannot lock. So you see that you always need at least one step (in practice several focusing steps after the sign switch) to actually find the correct focus point with this basic algorithm.This algorithm is used by a lot of firmware, with some minor additions (dynamic step sizing, spurious focus detection etc.)

author: akis
author_rank: Frequent Contributor
timestamp: November 04, 2015, 07:50:47 pm
content: Supposing the steps are numbered thus: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 .... 100Now suppose 0 is the closest the motor can move the lens to. And suppose 100 is at distance inifinity.The focusing process goes something like:10 (ridiculously blurred), 9, 8, 7, 6 (moderately blurred), 5, 4, 3 (almost in focus), 2, 1, 0 (perfectly in focus), 1, 2, 3, 4, 5 an it stops at 5 as "best".Why did it not stop at 0 ? What's wrong with 0?One explanation might be:The lens is heavy.The lens is spring mounted.The motor moves the lens at speed.As the lens moves closer the motor reaches its stop.But the lens being heavy has momentum and pushes onto its spring mounting achieving a position, if only temporarily, which is outside the specs, but in focus, past the motor's "stop".The spring decompresses and brings the lens back into "spec" positions where it cannot focus.This would explain what I am describing.

author: dom0
author_rank: Super Contributor
timestamp: November 04, 2015, 07:52:54 pm
content: QuoteBecause the sign didn't change. If you watch very closely when it successfully focuses that it always goes to perfect focus, then advances slightly out of focus, and then back. That's your sign change.

author: akis
author_rank: Frequent Contributor
timestamp: November 04, 2015, 07:58:50 pm
content: ahh so it would need a -1 and maybe a -2 just to be able to focus to 0...

author: Mechatrommer
author_rank: Super Contributor
timestamp: November 04, 2015, 11:59:25 pm
content: its like asking... how a brain works? go ask the creator... here are bunch of good speculators.

author: Alex Eisenhut
author_rank: Super Contributor
timestamp: November 05, 2015, 12:23:23 am
content: ...focus?http://petapixel.com/2015/11/04/the-lytro-illum-is-on-sale-for-400-as-amazons-deal-of-the-day/

author: RogerRowland
author_rank: Regular Contributor
timestamp: November 05, 2015, 04:56:55 pm
content: Before I start ranting, I'll just say up front that I have not worked on auto-focus routines for digital cameras.However, I have worked - and currently am working, bloody hard - on auto-focus for scanning electron microscopes. There are similarities and differences, so I'll try to stick to the similarities. SEM's have particular problems due to the very large range of magnifications and correspondingly small ranges of adjustment in working distance (effectively the focus) that complicate sweeping to find the sweet spot in the shortest time. There are also hysteresis effects due to the electron optics, but I'm starting to rant here ... back to the point ...The point being, that although a human eye/brain can see clearly when something is in focus, in terms of creating a metric that is suitablein the general casefor assessing image sharpness, it's actually not simple. In particular, where you have a scene with a large depth of field - so some close objects will be sharp at one point and the background sharp at another, you can't just use a global metric because the relative degree of foreground/background content will skew the focus toward whichever is larger. This is why many cameras perform face detection in order to determine where to concentrate the algorithm. Of course, you can only detect faces if you have reasonable focus anyway so there's a bit of chicken and egg there. Earlier, simpler cameras just assumed that whatever was in the centre of the view was the object to focus on. Note that I'm ignoring focusing using range finders here, which is another subject entirely.The next problem is, even if you do develop a quick and reliable sharpness metric, it's never ever going to behave in a monotonic fashion. It does need to be fast too - and many such metrics are calculated in the frequency domain and so are inherently lumbered with some overhead - because you don't want to hunt forever. The need for speed is a trade-off against the quality of the sharpness metric and so you end up trying to find a peak in a very noisy signal. Low contrast, low light levels, noise from the acquisition, lack of image features etc. all contribute to making the sharpness function a difficult thing to follow.This is why you will see that the supposedly ideal focus seems to be found and then lost. In order to find the best peak in the sharpness metric you have to roll over it and then backtrack. This also implies that there are no local maxima to fool you into stopping too soon so you often need to factor in other information - e.g. camera set to portrait mode vs panorama mode - to give you a hint as to where you should be looking.To make things even worse, the characteristics of the peak in the sharpness metric as you sweep through the focus range are not predictable. Different scenes will give you different shaped peaks with different amplitudes and you can't differentiate a good one from a bad one based on something simple e.g. like the index of dispersion (variance over mean) as a measure of the sharpness of the peak.All in all it's a complete nightmare to do this in code, with an unconstrained input, and it's one of those things that's difficult to understand because human brains are so good at it in comparison to computers.I could go on and on .... but I've hopefully gone on enough to flag at least some of the issues .... I hope that's helpful

author: Kilrah
author_rank: Unknown
timestamp: November 05, 2015, 09:25:55 pm
content: Quote from: akis on November 04, 2015, 10:01:24 amThat's exactly what it does. The issue is that it never reaches a point where the contrast is deemed good enough for a picture to be any useful. I.e. "I could take it, but you'd just throw it away afterwards when you see it's blurry".Quote from: akis on November 04, 2015, 10:01:24 amAs said by someone above what you see, suppposing your eyes could distinguish each of these 2MP which likely isn't the case, still only show you 1/4th of the potential image information. It can seem in focus to you but it isn't.Now even itf it isn't it might be good enough of a picture for you to make use of, but the camera can't guess what you're gonna do with it, so it will insteae rather try to meet its specs in a satisfactory manner. If you know what you want you'll want to switch to manual focus and happily shoot away.There's a reason why any sufficiently advanced camera makes a strong point of having manual controls - because no automated system can substitute itself to someone's judgment.

author: Mechatrommer
author_rank: Super Contributor
timestamp: November 06, 2015, 12:09:36 pm
content: Quote from: Alex Eisenhut on November 05, 2015, 12:23:23 ami thought this is a new hope, until i browsed the reviews from the people in the field. its too early of the technology to become practical in professional field where burst or sport shooting and super sharp focus is required.. imho only suitable for hobby purpose when you have extra time and money to play with. thinking of it, i can still get the effect with normal DSLR in burst mode while manually rotating the focusing ring..

author: coppice
author_rank: Super Contributor
timestamp: November 06, 2015, 12:55:30 pm
content: Quote from: Mechatrommer on November 06, 2015, 12:09:36 pmEven Lytro's own demos look quite poor. These cameras must be about 4 or 5 years old now. If they still can't stage an impressive demo things aren't looking good for this technique.

author: eas
author_rank: Frequent Contributor
timestamp: November 06, 2015, 07:56:59 pm
content: A factor that seems to be missed in these other useful explanations: What happens when the camera or subject moves during focusing?If you are operating the camera by pushing the shutter button with your finger, rather than some sort of remote release, then I am sure that the focus point it is hunting for and you may (or may not) be seeing in the preview is shifting faster than it can focus.