« Back To Vision & Imaging Tech Papers
GeT Cameras Inc Logo

Member Since 2022


We strive to contribute to the development of technology. Thanks to our innovative business strategy we make industrial cameras affordable in our online store. We focus on great support, and selecting the most cost efficient and reliable machine vision products.

Content Filed Under:



How to use depth of field to your advantage

POSTED 12/20/2023


Depth of field is essential for acquiring a sharp image of an object you are inspecting. With the right use of depth of field, you can ensure that the object you inspect is in focus, while the background and foreground are not in focus. That way it is easier for your vision software to recognize the object.

Depth of field is an important factor that you can use to your advantage. This article will explain more about what depth of field is, and how to use it.


The depth of field is the distance between the nearest and furthest object of the image that is in focus during acquisition. In the image below, the working distance is 250mm. The closest object to the lens is 190 mm away. The furthest object is 250mm away and the middle object is 210mm away from the lens. 

If your camera set up has a shallow depth of field, for example 30mm, it would be possible to get the closest, and the second object in focus, but the furthest card would be out of focus. By controlling the depth of field you could get all three items in focus, or two of the three cards.



The aperture of the iris has a great influence on how large the depth of field is. If the iris is wide open, for example, F1.4 of F2.0, the depth of field is relatively small. In some cases (F1.4), the depth of field could be a just a few millimeters. Everything outside of this area is out of focus. If the iris is almost closed, for example F16, the depth of field is larger and most of the image will be sharp. Please note that when you close the aperture, the image will become darker. To avoid this, you need to increase the exposure time, gain or light.
To illustrate the effect of the aperture on the depth of field we set up a test. In the example, we focus on objects at different distances from the camera.

Example F1.4

As mentioned above, a large aperture (low F-number) will result in a small / shallow depth of field. A small depth of field is required if you have objects in the foreground or background that you want to blur.
Pro’s F1.4

  • Very light-sensitive (short exposure time and little to no digital gain required)
  • Blur object in the foreground or background (easier for image processing software)

Con’s F1.4 

  • Small depth of field (important information might not be sharp)

The image below illustrates that the card at 250mm is sharp, the card at 210mm is already not perfectly in focus, and details might not be clear for your image processing software. The card at 190mm is even more blurry and unusable. 


Example F8

As previously mentioned, a small aperture (high F-number) will result in a larger depth of field. A large depth of field is required if your object has different heights that needs to be inspected. Additionally, it is also required, if you have multiple objects that can be closer or further away from the camera. A larger depth of field will allow both objects to be in focus.
Pro’s F8

  • Large depth of field (larger area will be sharp)

Con’s F8

  • Less light-sensitive (longer exposure time or more digital gain required. Adding an extra light source might be necessary)
  • Harder to blur objects in the foreground of the background

The card at 250mm and 210mm are acceptably sharp. The card at 190mm is still blurry but not as blurry as in the F1.4 example. The lost light has been compensated with a longer exposure time and digital gain. A longer exposure time can result in motion blur for moving objects. A high volume of digital gain will result in visible grain.

Images have been compressed for web.


  1. Is the depth of field too small, but closing the aperture is not possible? Try increasing the distance between the object and the camera. By doing this, the pixels per millimeter will decrease. If this becomes an issue,  we would advise you to try a lens with a higher focal length.
  2. Closing the aperture further for a larger depth of field will result in darker images. Make up for this loss by enlarging the exposure time, adding digital gain, or adding an extra light source. 
  3. If your object is not completely sharp, try closing the aperture a bit. The higher F-number will result in a larger depth of field.
  4. If possible, try to keep the aperture below F8. If you close the aperture,  you will also lose image quality due to the optical resolving power of the lens (see image below)

In this example we have used F16. The aperture was almos fully closed. All cards are evenly sharp, but the total image quality is not as good as you would prefer.