Depth of field calculator
Note: this page is only in part adapted to mobile devices.
This page contains a Java applet that implements a depth of field (DoF) calculator useful for close-up photography, macrophotography and photomacrography with digital cameras. Starting with a set of configuration parameters (e.g., camera model and/or sensor characteristics, lens pupil ratio) the applet generates and displays a table of DoF values and related data, arranged by effective lens aperture (X-axis of table) and magnification (Y-axis). Additional data of each table cell (effective aperture at the given magnification, diameter of the Airy disc and an appropriate slice thickness for focus stacking) is displayed in a tooltip, by hovering with the mouse cursor above the table cell. The applet also generates the same table data in HTML format (e.g., for copying-and-pasting to a text or web editor) and in CSV format (for copying-and-pasting to a spreadsheet program or database).
In addition, the applet can display multiple tables (e.g., for different combinations of camera and lens) simultaneously as part of this web page, adding them below the applet area. It can do the same also with HTML and CSV code for multiple tables. The format of the table(s) displayed on this web page is not meant to be identical to the table displayed within the applet area, and is affected by a number of factors (e.g., the web browser being used). The applet itself and its controls may also display differently, depending on the browser and operating system. The HTML and CSV display/export facility is meant principally to tables in these formats, generated with specific sets of configuration parameters.
Using the data provided by this applet
Using this data correctly for actual photography requires a working knowledge of depth of field (DoF) and of the principles of macrophotography and photomacrography (especially, the difference between nominal and effective lens aperture and the effects of diffraction). The entrance pupil, as defined in this applet, is the diameter of the lens pupil (i.e., the apparent diameter of the lens diaphragm/fixed aperture), as seen through the entrance elements of the lens. The entrance pupil is always measured from the side of the lens where light enters (i.e., the side that faces toward the subject). If you are using a reversed lens, the entrance pupil is on the side that, as meant by the manufacturer, should face toward the camera film or sensor (but now faces toward the subject). These concepts and their consequences are discussed, e.g., in photography books of a technical character (for instance, my book), pages of this web site, Wikipedia and discussions on the www.photomacrography.net web site.
One of the main features of the DoF table produced by this applet is that the background of each table cell is color-coded. Combinations of nominal aperture and magnification that produce images not visibly affected by diffraction are indicated by a green background. A yellow background indicates combinations of settings that cause diffraction to begin to visibly decrease resolution. A red background indicates combinations of factors that should be avoided in actual photography, or used only when the resolution of the final image will be substantially reduced (e.g., for web publishing). In most cases, the "best" compromise between factors is reached by using, at a given magnification, the settings that produce the rightmost green cell on the corresponding table row. Since resolution degrades gradually beyond the critical threshold, changes between green, yellow and red areas are not abrupt.
Note that the principle of resolution "visibly affected by diffraction", as applied to digital images and as used in this applet, differs from the similarly named criterion traditionally applied to images printed on photographic paper. Digital images have no physical size, and therefore their resolution is herein judged as visibly impaired by diffraction when the image, or a portion of the image (regardless of its pixel count) is displayed 1:1 on a monitor (i.e., each image pixel is displayed as a monitor pixel), and the display is observed from a distance that allows individual pixels to be visible, or at least at the limit of visibility. These conditions are fulfilled by most current computer displays observed from their intended distance. As a result, these criteria for a resolution unimpaired by diffraction in digital images are much more stringent than those traditionally applied to photographic prints. In addition, increasing the pixel count of the image (by using a camera with a higher number of sensels) does increase the requirements on image resolution. The traditional resolution criteria applied to photographic prints, instead, involve the visual observation of a print of fixed size from a fixed distance to the eyes. Applying these criteria to prints of digital images would result in the pixel count of these images being largely independent from resolution.
This applet uses the DoF formula as provided by Lefkowitz (1979: The manual of close-up photography) and other well-known formulas (e.g., for Airy disc diameter). The applet and its source code are fully original and copyrighted by the author. Aside from this, the applet only uses well-known physical and optical principles, and I make no claim of having discovered or invented anything new. The code makes a number of reasonable assumptions and simplifications. For instance, the number of sensels/pixels and physical sensor size of the camera models pre-configured in the applet is derived from data published by Internet sources (which, in turn, comes from manufacturer specifications). The specified number of sensels and sensor size are used for calculations, regardless of the fact that a few rows and columns of sensels along the edges of almost every sensor are not directly used for imaging, and that a further area along the edges of the sensor is occupied by other circuits. Other DoF calculators may be based on different sets of assumptions, and therefore their results may differ from those produced by this applet.
The thinnest line-pair visually resolvable by a camera sensor (measured in pixels), is a key configuration setting, but unfortunately, its value can only be a partly subjective estimate by the author. It is very likely to vary among camera models, depending on the strength of the anti-aliasing filter, the aggressiveness of demosaicing and sharpening algorithms and a number of other factors. It is certainly affected by the sensor type (e.g., Bayer vs. Foveon). At present, the applet uses the same value (which can be overridden by the user) for all cameras with Bayer sensors, because no easily quantifiable value for this parameter is provided by manufacturers. This is not a limitation of the applet, which does accommodate individual values of this parameter for each camera model.
In Bayer sensors, each sensel records light in one of the three base colors. The in-camera data processor subsequently interpolates information from adjacent sensels to generate (in a way, to "fake") information in the other two colors, thus producing one full-color pixel from each sensel. This means that the camera cannot actually record true detail in the final image at one-pixel scale, but rather, something closer to an average between a square of four to nine adjacent sensels of data. In my experience, detail resolution is actually better than a mathematical weighted average among a square of adjacent sensels, and I quantify it by saying that the smallest visually resolvable detail is approximately three pixels across (considering not only orthogonal lines but also oblique ones, which are an unfavorable case), or about six pixels in terms of a line-pair. The actual value used in the applet is 6.15, which agrees well with the results I obtained from in-camera JPGs shot with Nikon D200 and D300 DSLRs and Zeiss Luminar lenses. Years after these tests, I have seen results that suggest a value between 3 and 3.5 is more appropriate for raw images shot in optimal conditions, with more modern cameras lacking a hardware anti-alias filter, software presumably using more sophisticated demosaicing algorithms, and more sophisticated optics capable of out-resolving their sensors. The theoretical lowest limit is of course 3. Your results and preferences may be different, and in this case, just enter the desired custom value in the applet.
The calculation of the background color of table cells in the applet is also affected by the wavelength at which resolution is computed (by default, 550 nm, which corresponds to medium-green). A subject that displays fine detail at a substantially different wavelength (e.g., deep red) may require the DoF table to be calculated at the wavelength of interest.
Using the applet
The applet initially displays the Configuration tab. All configuration parameters can be overridden by entering custom values. If you wish to change any of the configuration parameters, do so in the Configuration tab.
Whenever you switch to another tab, the DoF table is recalculated accordingly. You can also refresh the configuration tab by clicking the View updated data button, or restore the default values by clicking the Restore default values button.
You cannot permanently save any of the custom values you entered for subsequent use. However, if you know what you are doing and don't need my help, you can edit the properties files in the applet jar to change the default values.
Some of the configuration text boxes accept only numerical values, some accept only integer values, and some can optionally be left empty. You cannot type extraneous (e.g., alphabetic) characters in boxes that validate their input. If the background of a text box turns pink after you move the focus to another part of the applet, it means that you have entered an unacceptable value.
The resolution in pixels and physical size of the sensor are important parameters. The Sensor settings pane provides a choice of specifying a common camera model or, alternatively, entering these settings manually.
If the drop-down list does not display the required camera model, you can use the second alternative, but you need to obtain the necessary data (for instance, from the manufacturer's specifications or a camera review site).
The Minimum width of resolvable line-pair setting is difficult to estimate with precision. The default value is suitable in the large majority of cases. A camera with an unusually weak anti-aliasing filter, or a modified camera without this filter, may need a slightly lower value.
The CoC settings pane provides a choice between computing the value of the maximum acceptable CoC from the sensor data, or using a supplied value.
Normally you can leave this setting to its default.
The calculation of the maximum CoC depends on the used wavelength. As a standard, the wavelength for medium-green is used. However, it may be necessary to specify a different wavelength, for instance for UV or IR photography.
If you wish to change any of the magnification and/or nominal aperture settings displayed in the table headers, do so in the corresponding controls of the Configuration tab. To remove an existing value from a table header, and its corresponding column or row in the table, delete its value in the Configuration tab and leave its text box empty.
To add one or more new values, use the five empty text boxes at the right end of the Nominal aperture configuration row, or at the bottom of the Magnification (mag.) configuration column.
Whenever you activate another tab or click the View updated data button, the lists of apertures and magnifications are sorted, any duplicate or empty values removed, and the table recalculated.
Use the scroll bar to reach the end of the Magnification column and Nominal aperture row in the Configuration tab.
The pupil ratio of a lens affects the DoF at a given magnification and aperture. The effect of the pupil ratio of a lens has a significant effect, but not a major one. In typical lenses, it corresponds to an aperture change of up to half a stop.
The pupil ratio is the ratio of the diameter of the exit pupil over the entrance pupil. If you don't know the pupil ration but know how to measure the input and output pupils, you can alternatively enter these measurements.
A moderate error in these measurements has no dramatic effect in the computed DoF table.
The Table title text box in the Configuration tab is used to enter a title that will be displayed at the top of the table (both in the DoF table tab and on this web page). You can use different titles to identify multiple tables added to this page.
The Reset default values button deletes any changes you have done to the settings and displays the default values.
The View updated data button is useful when you have made some changes, for example in the magnification column or the effective aperture row. Clicking this button sorts these lists and removes any empty cells where you deleted the original values.
The buttons along the bottom of the DoF Table tab are used to add the current table, its HTML code and/or its CSV code to this web page (below the applet area), or to remove the corresponding items from the page.
New items (e.g., new DoF tables) are added below existing ones in the same category. Extended HTML code specifies a table that displays DoF and all additional data in each table cell (as opposed to a tooltip in the HTML code). Extended CSV does the same thing (as opposed to CSV code, which only displays the DoF).
This functionality allows you to display multiple tables or code panes simultaneously, but may not work in certain browsers, especially old ones, or with certain security settings.
In general, it is not possible to print this web page after adding tables or data to it with the applet. Most browsers will simply reload this page from the server and print it without any of the generated data. To make a permanent record of any data you generated with this applet, you should use the facilities for generating HTML or CSV code provided by the applet, and copy-and-paste this information into a suitable editor or other program. An alternative way to save a graphic image of the table(s) is by making a screen capture and pasting it into a picture editor (the procedure for doing this depends on the operating system).
Running DoF Calc as a Java application
If desired, this page and the accompanying files can be saved locally on your computer and run without a web server. Note that many browsers will not automatically save all the necessary files. To run the applet locally within its page, you need to download and save to your computer, at a minimum, the following files in a corresponding folder structure:
The applet may also be run within an applet viewer instead of this page (but in this case, you will lose the capability of displaying tables and code on the surface of the web page). The technical requirements discussed above apply also in this case.
My current job involves software development, and I decided to acquire some hands-on experience with Java applets and the Swing libraries (neither are part of my current job). Writing this applet was a way to achieve this goal, and at the same time to provide a new addition to my web site. You are welcome to use this applet on my web site, or to save it and run it locally on your computer. Any other use, like making the applet available on another web site, needs my written permission. Note that I am not providing any of the following:
The applet is relatively large (about 180 Kb), albeit smaller than many picture files ordinarily displayed on web pages. It may take some time to download on very slow Internet connections, and may be costly to download on expensive networks (e.g., satellite phones). The download/startup may appear to hang on browsers that do not support Java applets, or when the Java VM hangs or crashes because of browser or memory problems. The applet was neither designed for, nor tested on, smartphones or other devices with limited graphic resolution, memory, processing power and/or Java support. It does not work on Android devices because they support only a limited subset of Java, nor on iPad/iPhone devices because they have no Java support. At this time, I have no plans to provide a specific version for mobile devices.
The snail picture on the About tab and application icons is mostly there for aesthetic reasons, and to fill the available space. Nonetheless, it does have two connections with the DoF applet theme. The first is that the picture of this subject is almost completely in focus, in spite of its deep three-dimensionality. This is a good example of an appropriate use of DoF in photography. The second is that the color pattern on the shell of this species is highly unusual for a land snail, and happens to mimic the color-coding used in the DoF table (green, yellow and red banding, obliquely from top to bottom).
Number of page hits (whole site):
This site is ad-free. If you see any ads here, they are added by your ISP, or by spyware on your computer, or you are visiting this site through frames of another site.