by R. Grothmann In this notebook, we compute the formulas for the depth of field (DOF) of an ideal lens. First we know the basic equation.
Here f is the focal length, x is the distance of the film plane to the lens, and d is the distance of the object from the lens. To accomodate for the so-called form factor of modern cameras, we use f/ff instead of f. Most photographers are used to 36mm film, and mutliply the true focal length by ff to get the equivalent focal length. If you do so, use ff=1.5 for compact SLR, and ff=5 for compact digitals.
>beq &= 1/(f/ff)=1/x+1/d
ff 1 1 -- = - + - f x d
f is the focal length computed for 35mm. ff is the factor, such that f/ff is the true focal length. The form factor ff is 1 for 35mm (film), 1.5 for the DX format, 5 for compact digital. In the following, x is the distance of film plane from the lens, where an object in distance d is sharp.
>&solve(beq,x); function x(d,f,ff) &= rhs(%[1])
d f -------- d ff - f
Next we compute the radius of unsharpness. If a light point is mapped, its rays are within a conic behind the lens. The intersections with the film plane are circles (or ellipses off the center). The radius of the circles depend on the object distance od, the focussed distance d, the focal length, the lens factor, and the F-stop (aperture) a. This is simple geometry. Denote by x the distance of the film to the lens (for the set distance d), and xo the focus distance of the object at distance do. Then the lens opening f/a (for ff=1) is multiplied by the factor (xo-x)/xo.
>&factor(ratsimp((x(od,f,ff)-x(d,f,ff))/x(od,f,ff)*(f/ff)/a)); ... function us(od,d,f,ff,a) &= %
2 f (od - d) - ------------------ a ff (d ff - f) od
Let us plot the circle of unsharpness for a 50mm lens with d=1 (film), a=8 for various distances.
>plot2d("us(x,1,0.05,1,8)",0.5,2):
To get the near boundary of the DOF, we solve the equation, that the diameter of unsharpness is equal to some largest admittable diameter. For 35mm this is usually taken as c=0.03mm. But we need to multiply this by the form factor ff, since the image will be magnified by this factor. The function dn (near distance of DOF) will depend on the set distance d, the focal length together with the form factor, the F-stop a, and the maximal accepted radius c for film.
>function dn(d,f,ff,a,c=0.00003) &= rhs(solve(us(od,d,f,ff,a)=c/ff,od)[1])
2 d f --------------------- 2 a c d ff + f - a c f
The same for the far end of the DOF.
>function df(d,f,ff,a,c=0.00003) &= rhs(solve(us(od,d,f,ff,a)=-c/ff,od)[1])
2 d f - --------------------- 2 a c d ff - f - a c f
As an example, we compute the DOF for 50mm film at F8, when the camera is set to 1m.
>[dn(1,0.05,1,8,0.00003),df(1,0.05,1,8,0.00003)]
[ 0.91642228739 1.10035211268 ]
We can plot the DOF for distances from 1m to 5m, 50mm film at F8.
>x=1:0.01:5; ... plot2d(x,dn(x,0.05,1,8)_df(x,0.05,1,8));
We add the DOF for a DX camera. It is much wider.
>plot2d(x,dn(x,0.05,1.5,8)_df(x,0.05,1.5,8),add=1,color=11);
And the focussed distance for reference. The plot does also show that there is always more DOF behind the object, but not twice as much, as the rule of thumb says.
>plot2d(x,x,add=1,color=12,title="DOF at distance"):
Next we compute the hyperfocal distance (HFD). This is the distance we have to focus at to get as much as possible DOF, ending at infinity.
>&solve(df(d,f,ff,a,c)=s,d); ... function hfd(f,ff,a,c=0.00003) &= limit(rhs(%[1]),s,inf)
2 f + a c f ---------- a c ff
E.g., at 50mm film, F8, we have to focus at 10.47m.
>hfd(0.05,1,8,0.00003)
10.4666666667
With a wide angle 18mm lens, we can focus much closer, and still get everything to infinity into DOF.
>hfd(0.018,1,8,0.00003)
1.368
Where does the DOF start, if we use the hyperfocal distance? It is a fact that it starts at 1/2 of the HFD. As a rule, we have to focus on double the distance we want the DOF to start at.
>&ratsimp(hfd(f,ff,a,c)/dn(hfd(f,ff,a,c),f,ff,a,c))
2
We now plot the HFD depending on the focal length for the DX format at F8.
>plot2d("hfd(x/1000,1.5,8)",a=18,b=120,c=0,d=50, ... title="HFD at focal length"):
Or we can plot the HFD for 50mm on DX for various F-stops. Clearly, we need to use higher F-stops, if we want more DOF.
>plot2d("hfd(0.05,1.5,x)",a=2,b=16,c=0,d=60,title="HFD at f-stop"):
Assume, we want a fixed object to fill the frame. Then we need to keep the distance to the object and the focal length in a fixed proportion. Surprisingly, the DOF is almost the same from 30mm to 150mm.
>plot2d("df(x/10,x/1000,1.5,4)-dn(x/10,x/1000,1.5,4)", ... a=30,b=150,c=0,d=20,title="DOF at focal length, fixed object"):
However, if we do this, the unsharpness at infinity increases with the focal length. Since f/od is constant, it increases with the focal length. It does also increase with lower F-stops of course. But is cheaper and more effective to increase the focal length than to buy faster lenses, if the aim is to blur the background.
>&limit(us(od,d,f,ff,a),d,inf)
2 f -------- 2 a ff od
We can also determine, which combinations of focal length and F-stop give 2m HFD. We do that numerically in Euler.
>fcontour("hfd(x/1000,1.5,y)",xmin=18,xmax=50,ymin=2,ymax=16,niveau=2, ... title="2m HDF at focal length and F-stop"):
This can be solved by Maxima exactly.
>&solve(hfd(f,ff,a,c)=hfd,a)
2 f [a = --------------] c ff hfd - c f