Skip to content

Depth from focusđź”—

Depth from focus (DFF) is a method that enables the reconstruction of 3D surface information from several images taken at different focus distances between camera and object. It allows a highly accurate non-destructive 3D measurement of surfaces.

The example shown in Figure 1 was done using microscopic optics with 10x magnification and reaches an accuracy of about 5 micrometers.

DFF is even more precise than the methods stereo vision and laser triangulation with sheet of light.

Furthermore, the setup requires only a single camera, therefore, it is possibly more compact than, e.g., a stereo setup.

DFF requires, however, cameras with telecentric or microscope lenses in order to achieve a (nearly) parallel projection.

Therefore, DFF is only suitable for small objects. Examples for suitable objects in semiconductors industry are a ball grid array (BGA) (the result of DFF on a single ball of a BGA can be viewed in Figure 1) or solder paste inspection, another application in the engineering sector is the inspection of indexable inserts.

Figure 1: This image shows the 3D surface reconstruction of a single ball on a ball grid array.

About the depth from focus principleđź”—

With depth from focus, you can reconstruct the surface of a 3D object based on the knowledge that object points have different distances to the camera and the camera has a limited depth of field. Depending on the distance and the focus, object points are displayed more or less sharply in the image, i.e., only those pixels within the correct distance to the camera are focused.

Taking images with various object distances, each object point can be displayed sharply in at least one image. Such a sequence of images is called “focus stack”. By determining in which image an object point is in focus, i.e., sharply imaged, the distance of each object point to the camera can be calculated. This principle is clarified in Figure 2.

Figure 2: This figure shows the focus stack of images on the left side and the corresponding focus value, that is determined for each pixel, on the right side. The best focus point is the image where a pixel has the highest sharpness.

Image 0…n \(i_0 ... i_n\)
Depth \(d\)
Focus value for each pixel \(v_f\)

For more information about determining sharpness, please refer to %HALCONEXAMPLES%\hdevelop\Applications\General\determine_sharpness.hdev. In this example, a flat object is imaged, and the global sharpness of the image is determined. In the case of DFF, the sharpness will be determined for each single pixel.

If you need real three-dimensional information, e.g., if you want to further use your DFF results for any 3D measurements or surface-based matching you need to telecentrically calibrate your system.

Depth of field (DOF) is a similar term which, however, is not a method but a technical term concerning the camera. The depth of field is the range of distance within which the image is sharp as opposed to the best focus point, which is the point with perfect sharpness in the image. The DOF depends on the pixel size, the aperture (f-number), the focal length in the case of a non-telecentric lens, and the focusing distance.

A low depth of field means that only a small slice of the object is sharply imaged (see Figure 3), whereas a high depth of field means that a big part or maybe the whole image is sharp. For DFF, a low depth of field leads to a higher precision. In order to obtain a low depth of field, use lenses with a high aperture which is a small f-number on your lens.

Field of depth with different objects

Figure 3: (Top) Only a small slice of the image is sharp. Therefore point P1 is mapped to a single point and is therefore sharp, whereas P2 is mapped to a spot and is consequently blurry. (Bottom) If the object is very flat, the whole object can be sharp at the same time, even if the depth of field is not very high.

CCD sensor \(CCD\)
Lens \(L\)
Object point 1 \(P1\)
Object point 2 \(P2\)
Depth of field \(DOF\)

A method for 3D surface measurement, similar to DFF, is depth from defocus. This method requires one sharp image of the foreground and one sharp image of the background. The distance of all points that lie between foreground and background is interpolated by their amount of blur. As it only depends on two images, it may be faster, but it is also not as precise as depth from focus. Depth from defocus is not available in HALCON.

Performing depth from focus with a standard lensđź”—

Even though not recommended, it is possible to perform depth from focus with standard lenses. Using a non-telecentric lens does, however, require some adaptations of the DFF measuring process to ensure the best results.

Note that the accuracy of DFF measurements with a standard lens instead of a telecentric lens is reduced. For DFF with standard lenses, the focal length needs to be as long as possible in order to keep the perspective shift of the points in the field of view small. Furthermore, the depth of field needs to be small.

If the points shift too much within the field of view, measuring with DFF produces an erroneous result.

Calibrate aberration as described here.

Note that the rules that have been described for DFF with a telecentric lens are also valid for DFF with a standard lens.