# Depth-of-field

Depth-of-field (DoF) is one of the most fun things about photography. It is enjoyable on both the technical and artistic levels. Depth-of-field is the extent (“depth”) in a scene that is in focus (“field”) on a photograph. Artistically it is usually used to isolate a subject from the surroundings and can be used to indicate depth. The subjective nature of the out of focus elements (the blur) is called Bokeh and is a marketing term invented by the Japanese to sell lenses with larger apertures that are insanely expensive (I’m kidding, I’m kidding).

There are many, many good technical articles on DoF and many many religious wars on Bokeh. What I want to do here is focus on the values of DoF that you can get at different focal lengths and at different apertures and try and relate that to everyday portraits.

A good place to get started on the geometry of DoF is Wikipedia’s article, which also has a nice derivation for formulae for DoF which I will be using.

Intuitively, DoF exists because lenses bring to focus only an infinitely thin slice of the three dimensional scene onto a two dimensional plane. The parts of the scene in front of, and behind this slice become progressively more and more defocused. Depending on the size at which you view the image you will notice this blur at an earlier (large image) or later (small image) stage. Aperture plays an important role in DoF with larger apertures giving shallower DoF.

Like most things in photography DoF is the one-dimensional shadow of a multi-dimensional creature depending upon focal length (f), aperture (a), subject distance (s) and sensor size. This creature is well expressed by the equation:

$D = \frac{sf^2}{f^2 \pm ac(s-f)}$

Here c is the circle of confusion and is the amount of blur you will tolerate before you say “this is out of focus”. Typically the value for c is given a value based on the resolving power of the sensor. Film with larger grain will have larger c and sensors with smaller sizes will have smaller c. I’m doing the calculations with c = 0.02mm which is the accepted value for APS-C sizes sensors (entry level DSLRS).

As I mentioned, here I’m interested in figuring out DoF for common focal lengths for when I want to take portraits. The general advice given is that for a proper portrait you need fast glass so you can open the aperture up wide and isolate your subject by blurring the background. I was interested in getting some values of what range of apertures to use for different focal lengths in order to create good portraits.

For reasons that will become clear shortly, I need to know how far back I should stand to get the framing I want with each lens. As you can guess, the longer the focal length of the lens the further back I need to stand. I can work out this distance by computing the magnification factor mfor the portrait. This is the ratio of the size of the image on the sensor to the actual size of the subject.

I’m working this out for APS-C sensors, which are 24×16 mm. A person’s head is about 26cm high x 15 cm deep (nose to ears) x 18cm wide (I know it really looks like clueless nerd trying to do ‘art’, but bear with me). I’m going to split portraits into two classes I like:

Close-up: The face fills the frame, every part is in focus (especially the eyes) and any background is blurred as much as possible (generally oriented tall). Here $m = \frac{24.}{260} \simeq \frac{24}{240} = 0.1$.

Environmental: The head and upper body take up about 50% or less of the frame area and the rest comes from the subject’s surroundings which are blurred, but retain enough structure such that you can tell what it is, which gives the subject a context (generally oriented wide). Here $m \simeq \frac{10.}{260} \simeq 0.04$

I can compute the subject distance (how far I need to stand) from the equation $m = \frac{f}{s-f}$ which ultimately results in

$\displaystyle D = \frac{f^3 (\frac{1+m}{m})}{f^2 \pm ac\frac{f}{m}}$

Now we can plot our DoF for a range of focal lengths for our purpose at different apertures for an APS-C sensor:

In the plots, the shaded gray area represents the nose-ear depth, the black lines represent the DoF at the given aperture and subject distance for the indicated focal lengths (given in mm above the shaded area eg. 18,35,50…)

Here’s two interesting things I take away from the plots.

The first is that DoF remains constant whatever focal length you use (as long as you are keeping the size of the subject on your photo constant). Without working this out I would have expected longer focal lengths to have smaller DoFs: this is true for the same subject distance, but since we are keeping image size constant, we get this different result.

The second is, for close-ups you need to go down to f/22 to get a DoF that covers nose-to-ears and even for environmental portraits you need to stop down to at least f/5.6 to get the nose and ears in focus.

For the longest time I was trying portraits with lenses like the 35mm/1.8 and 50mm/1,8 wide open and I was failing miserably (especially with the 50mm, which I manual focus). Then I started getting braver and started to stop down more, 4.0, even 5.6, and I got good results. These calculations show me why.

I would say, you don’t necessarily need fast glass to obtain subject isolation. In some cases it looks cool to have one eye in focus and the other eye and nose and ears not but I prefer to have the whole face in focus, with the environment thrown off. For this, it seems, I can use pretty much any lens since most lenses will give me at least f/5.6 In terms of aesthetics, of course, 35mm and longer is preferred for portraits to avoid distorting the face unpleasantly.

I have studiously stayed away from the ‘artistic’ aspects of Bokeh. If you do want to get into depth in this aspect of the field, all you really need to know, is that the worst insult you can throw in a Bokeh debate is to tell the other fellow his Bokeh looks like donuts.

Code follows:

"""
https://en.wikipedia.org/wiki/Depth_of_field#Derivation_of_the_DOF_formulas.
http://www.dofmaster.com/dofjs.html"""
import pylab

#m - subject magnification
#f - focal length
#a - aperture number
#c - circle of confusion

# Plot the depth of field by focal length and aperture

#D = \frac{f^3 (\frac{1+m}{m})}{f^2 \pm ac\frac{f}{m}}
Dn = lambda m,f,a,c: ((f**3)*(1.+m)/m)/(f**2 + a*c*f/m)
Df = lambda m,f,a,c: ((f**3)*(1.+m)/m)/(f**2 - a*c*f/m)

H = 0.15 #Nose to ears

F = [.018, .035, .050, .085, .105, .135, .2, .3] #Our choice of focal lengths, need to be expressed in m.
A = [22, 16, 8.0, 5.6, 3.4, 1.8, 1.4] #Our choice of f-stops

c = 0.00002 #0.02mm is circle of confusion http://www.dofmaster.com/dofjs.html for D5100 (APS-C)

dn = pylab.empty((len(F), len(A)))
df = pylab.empty((len(F), len(A)))
m = 0.1
#m = 0.04

for i,f in enumerate(F):
for j,a in enumerate(A):
dn[i,j] = Dn(m,f,a,c)
df[i,j] = Df(m,f,a,c)

pylab.figure(figsize=(10,4))