DSPRelated.com
Forums

Lens focusing algorithm?

Started by Sander Vesik February 27, 2004
Does anybody have pointers to algorithms than can be used / 
are used to focus lens given input from a CCD ? 

-- 
	Sander

+++ Out of cheese error +++
"Sander Vesik" <sander@haldjas.folklore.ee> wrote in message
news:1077925317.996659@haldjas.folklore.ee...
> Does anybody have pointers to algorithms than can be used / > are used to focus lens given input from a CCD ?
I don't experience in doing this, but here is my guess on how it might work (at a simple level). You get to pick an area from the CCD image as your 'focus selection point' - this would be a fairly small area on your image. You apply edge detection algorithms to this small area and see if you can detect a sharp edge. If not, then you are out of focus and you change the focal length by a certain step and check for edge sharpness. You can get pretty creative on how you 'hunt' for focus. I'm not sure how much this helps... Cheers Bhaskar
> > -- > Sander > > +++ Out of cheese error +++
Bhaskar Thiagarajan <bhaskart@deja.com> wrote:
> "Sander Vesik" <sander@haldjas.folklore.ee> wrote in message > news:1077925317.996659@haldjas.folklore.ee... > > Does anybody have pointers to algorithms than can be used / > > are used to focus lens given input from a CCD ? > > I don't experience in doing this, but here is my guess on how it might work > (at a simple level). > You get to pick an area from the CCD image as your 'focus selection point' - > this would be a fairly small area on your image. You apply edge detection > algorithms to this small area and see if you can detect a sharp edge. If > not, then you are out of focus and you change the focal length by a certain > step and check for edge sharpness. You can get pretty creative on how you > 'hunt' for focus. > I'm not sure how much this helps...
Thanx - its at least an idea 8-)
> Cheers > Bhaskar >
-- Sander +++ Out of cheese error +++
Sander Vesik <sander@haldjas.folklore.ee> wrote in message news:<1077925317.996659@haldjas.folklore.ee>...
> Does anybody have pointers to algorithms than can be used / > are used to focus lens given input from a CCD ?
If you mean how do you make an autofocusing camera, there are two common techniques. One is echo ranging with an infra red beam. The other is sweeping through the focus range, looking for the maximum contrast in the image. Usually you use just the central area, as that is generally the part you want to be in sharp focus (it cuts the compute load too). If yuo try using some cam-corders in dim light, or in very bland featureless scenes yuo will see them going into this sweeping mode repeatedly, as they cannot find a nice peak on the contrast calculation. The infra red approach may seem crude compared to the fancy signal processing approach, but it does work well in poor light. Regards, Steve
Steve Underwood wrote:

> Sander Vesik <sander@haldjas.folklore.ee> wrote in message news:<1077925317.996659@haldjas.folklore.ee>... > >>Does anybody have pointers to algorithms than can be used / >>are used to focus lens given input from a CCD ? > > > If you mean how do you make an autofocusing camera, there are two > common techniques. One is echo ranging with an infra red beam. The > other is sweeping through the focus range, looking for the maximum > contrast in the image. Usually you use just the central area, as that > is generally the part you want to be in sharp focus (it cuts the > compute load too). If yuo try using some cam-corders in dim light, or > in very bland featureless scenes yuo will see them going into this > sweeping mode repeatedly, as they cannot find a nice peak on the > contrast calculation. > > The infra red approach may seem crude compared to the fancy signal > processing approach, but it does work well in poor light.
Although they tend to vary together, maximizing the high-frequency content is usually more productive than creating the greatest difference between bright and dark. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
You could perform DCTs and use a feedback loop to get the maximize the
high-freq content.  I'm not sure how you decide which element of the picture
you want to focus on, unless you assume it's the middle.
-Kevin

"Sander Vesik" <sander@haldjas.folklore.ee> wrote in message
news:1077925317.996659@haldjas.folklore.ee...
> Does anybody have pointers to algorithms than can be used / > are used to focus lens given input from a CCD ? > > -- > Sander > > +++ Out of cheese error +++
Hi Jerry,

I focussed on the "are used" part of the question. Cameras have been
doing this for over 20 years. The compute power they could bring to
bear on the problem was very limited then. The early ones I saw just
used contrast, yet worked very well. I think this is still how they
work, as the battery consumption of those machines is still very low.

If you focus on what you *could* do, then things are different. I
think an entropy analysis would generally give the best results. Much
more so than a simple peaking of the overall high frequency content,
or a more focussed detection of the sharpest edge transitions. If you
are focussing on a face, there are not too many distinct transitions
to focus on. Entropy works very well, though.

Regards,
Steve


Jerry Avins <jya@ieee.org> wrote in message news:<4040b817$0$3099$61fed72c@news.rcn.com>...
> Steve Underwood wrote: > > > Sander Vesik <sander@haldjas.folklore.ee> wrote in message news:<1077925317.996659@haldjas.folklore.ee>... > > > >>Does anybody have pointers to algorithms than can be used / > >>are used to focus lens given input from a CCD ? > > > > > > If you mean how do you make an autofocusing camera, there are two > > common techniques. One is echo ranging with an infra red beam. The > > other is sweeping through the focus range, looking for the maximum > > contrast in the image. Usually you use just the central area, as that > > is generally the part you want to be in sharp focus (it cuts the > > compute load too). If yuo try using some cam-corders in dim light, or > > in very bland featureless scenes yuo will see them going into this > > sweeping mode repeatedly, as they cannot find a nice peak on the > > contrast calculation. > > > > The infra red approach may seem crude compared to the fancy signal > > processing approach, but it does work well in poor light. > > Although they tend to vary together, maximizing the high-frequency > content is usually more productive than creating the greatest difference > between bright and dark. > > Jerry
Hi Sander,

> Does anybody have pointers to algorithms than can be used / > are used to focus lens given input from a CCD ?
This probably isn't exactly what you're after, but here's a brief description of how auto-focus is done in CD players: http://www.repairfaq.org/sam/laserlia.htm#liarfdm I was involved in a project once that used a similar technique in a non-contact standoff-distance "probe" for a coordinate measurement machine. The system used a CCD camera the way photodiodes are used in CD players (i.e., we just looked at the eccentricity of the laser spot). Worked surprisingly well (_I_ was surprised, at least). Of course, if you don't have a laser handy, this won't work. :) HTH Rick Armstrong (note: reply address is bogus
Steve Underwood <steveu@coppice.org> wrote:
> Hi Jerry, > > I focussed on the "are used" part of the question. Cameras have been > doing this for over 20 years. The compute power they could bring to > bear on the problem was very limited then. The early ones I saw just > used contrast, yet worked very well. I think this is still how they > work, as the battery consumption of those machines is still very low.
It appears to be mostly driven by energy consumed by mechanical processes even in latest cameras.
> > If you focus on what you *could* do, then things are different. I > think an entropy analysis would generally give the best results. Much > more so than a simple peaking of the overall high frequency content, > or a more focussed detection of the sharpest edge transitions. If you > are focussing on a face, there are not too many distinct transitions > to focus on. Entropy works very well, though.
Any pointers to getting more information on this? I didn't manage to turn up too much in a fast search on citeseer.
> > Regards, > Steve >
-- Sander +++ Out of cheese error +++
Hello Sander,

Here is how the Nikon D2H does it. And it currently has the best autofocus
in digital SLRs.

http://www.digitalreview.ca/cams/NikonD2Hpg_2.shtml

Clay

-- 
Clay S. Turner, V.P.
Wireless Systems Engineering, Inc.
Satellite Beach, Florida 32937
(321) 777-7889
www.wse.biz
csturner@wse.biz



"Sander Vesik" <sander@haldjas.folklore.ee> wrote in message
news:1077925317.996659@haldjas.folklore.ee...
> Does anybody have pointers to algorithms than can be used / > are used to focus lens given input from a CCD ? > > -- > Sander > > +++ Out of cheese error +++