Tuesday, May 22, 2012

Looking through a big aperture


The optics equations and diagrams we use in machine vision are all based on the pinhole camera model. Those assume an extremely small aperture, which isn’t practical because we need lots of photons to stream through and impinge on our sensor. So lenses incorporate a variable aperture, the diameter of which can be varied. And as you probably know, the size of the aperture is expressed in terms of F/#.

Now you’ve probably learnt that opening up the aperture, (which lets you reduce the exposure time,) reduces the depth of focus (DOF). If you’re imaging a flat surface that doesn’t matter, but often we need to have parts of an image that are at different heights in focus at the same time. This is when we need to think about the DOF.

The Basler White Paper “Optics Recommendation,” (get it from their download site,) that I mentioned in my last post has this to say about DOF: “The rule of thumb for visible light is: DOF = +/- (pixel size) x F/#”

Well my 5Mp camera uses the Sony ICX625 sensor, which has pixels of 3.45 microns. So plugging that plus an f-number of 2.1 into the Basler equation told me my DOF is +/- 7.245 microns, which didn’t sound quite right.

Puzzled by this, I turned to my favorite lens calculator software, MachVis, and entered the sensor size, working distance and field of view. That told me my 35mm lens should give a DOF of 4.3mm, which passes my gut check, but I still wasn’t convinced.

So I carried out my own tests.

All I did was set a steel rule at 45 degrees under my 35mm lens. Then I put a line profile tool across the millimeter divisions, and got an image like this:



The change in working distance from left edge to right is about 113mm.

I tried to focus on the midpoint – around the 23.5cm point – and set the F/# to the minimum, which was F/2.1. This resulted in the graduations at each end being out of focus. I then grabbed two more images, with f-numbers of 4.0 and 8.0 respectively.

It’s hard to see in the image, so let me show you the data in two charts, one from the 17 to 18cm section, and one from 23 to 24cm.


Conclusions?

Clearly the smaller aperture, F/8.0 produced the best contrast, (which I am equating with focus,) both in the center of the image and out at the end. So smaller aperture equals greater DOF.

The wide open aperture – F/2.1 – produced good contrast at the center of the image, but lousy out at the end. Large aperture equals smaller DOF.

So it’s pretty clear that working distance increases with a smaller aperture. However, if we consider that only with a setting of F/8.0 did we get acceptable focus throughout the image – that is, over a working distance of 113mm, what does that tell us about the Basler equation?

That gives DOF of +/- 27.6 microns. Moving in the same direction as my results but still out by a factor of 1,000.

So what gives? Am I misunderstanding what Basler are saying? (Which is quite possible.) Or is there a misprint in their note? If anyone has thoughts to share I’d love to hear them.

3 comments:

Nick Tebeau said...

My understanding of DOF is that magnification of the image over the pixel size is very important and has to be included in the calculation. The four elements of the calculation are sensor size, Pizel size, FOV, and f/#.

My calculator produced a result of 19.82mm for DOF based on Sensor size of 8.445mm, FOV of 160mm, Pixel size of 3.45mm, and f/8.

If you would've opened up your FOV to say 320mm then you should've seen a much better DOF, again in my calculation it would've been 79.26mm. You obviously trade off pixel resolution to achieve this.

I'm also not sure the basis of Basler's calculation.

Unknown said...

I think you are right Nick:
Baslers formula is true only when you think about the DOF on the image side (where the sensor is) which is quite unusal. Then its really simple geometry: if you draw a triangle from the aperture to a pixel on the sensor you will see that with a F number of 1 (aperture diameter = focal length) the depth of focus is about equal to the pixel size.
So the only thing they forgot, as you say, is the magnification factor. So their formula is true for magnification 1:1 but for 1:10 you have to multiply it with 10.
I hope that helps

Erik Klaas

Anonymous said...

In your post you refer to DOF as depth of focus which is not wrong but it also refers to depth of field which is what you are actually referring to. Depth of field is the range of distances which a given lens at a given aperture can clearly focus on the object side (plane of inspection). Depth of focus is the same thing but on the image side of the lens (toward the image chip). You may want to verify what is meant by pixel size as well; does this mean the size of a pixel on the image chip or is it the size of a pixel in the field of view. From a reliable source Depth of Focus is directly proportional to the Depth of Field by the square of the magnification of the system. From the same source it is the Depth of Focus which is proportional to the f-number times the pixel size; this is on the image side not the object side.