views:

554

answers:

4

I want to know the depth of field of a photo, preferably in cm or m.

I know that we can know the camera setting by reading the EXIF tags, but is there a tag directly telling us the depth of field? Or how can we calculate it from some EXIF tags?

Examples would be appreciated. Thanks!

+2  A: 

I'm guessing here, so I'd appreciate if anyone else can confirm this:

I believe you cannot programatically determine the depth of field from the available EXIF data - you must know the f-stop, focal length, and this is crucial: the subject distance.

The fields FNumber and Focal Length will give you the first two. The third would not normally be possible to determine with the camera. You would need some mechanism for ranging - some extra equipment for the camera or some known values for triangulation.

Colin Pickard
The camera can know this. With Canon this information is used with E-TTL 2 flash metering, for example. But the lens has to support this as well, which should be true for most recent Canon EF lenses, third-party ones usually don't or they claim they do and only yield zeroes. Some of my photos have "Focus Distance Lower" and "Focus Distance Upper" fields (at least exiftool reports them).
Joey
Ah, interesting. So it would definitely be possible for some camera/lens combinations.
Colin Pickard
I guess this is the reason why DOF is not in the EXIF data in the first place -- not too many cameras and lenses will have photometry technology that determines subject distance
Jon Limjap
So, can I say that when "Focus Distance Lower" and "Focus Distance Upper" appear in the EXIF data, they are the depth of field of the photo? Say, for http://www.flickr.com/photos/lauws/3864286429/meta/ the focusing rocks are in the range of 1.54 - 1.82 (and the unit is metre, right?)?
Andy Li
+1  A: 

This web page http://www.dofmaster.com/dofjs.html has a straightforward explanation of what is involved in depth of field calculations:

Paul Lydon
+1  A: 

Calculating depth of field:

t = A * (S/1440) * (D - F) / F^2

The near focus distance = D/(1+t)

The far focus distance = D/(1-t)

And the full depth of field is the difference between these.

The variables are:

A = lens aperture (F Number)

S = camera sensor or film plane diagonal size in mm

D = focus distance in mm

F = lens focal length in mm

Of course, the sharpness of focus is subjective, and is adjusted by changing the constant in the calculation of the circle of confusion (CoC). Here, I have used CoC = S/1440 which is a value that is commonly used.

Phil Harvey
You say "D = focus distance in mm", what is focus distance? You mean the subject distance (which is not in EXIF, right?)?
Andy Li
D = the distance at which the lens is focused.Some maker notes report this is "Focus Distance". You can also use the EXIF "Subject Distance" tag assuming that the camera was focused on the subject. But note that this tag is in metres, and must be multiplied by 1000 to get D for use in this formula. - Phil
Phil Harvey
I see. What about "Focus Distance Lower" and "Focus Distance Upper" in EXIF? Are they already the depth of field values?
Andy Li
No. In fact, the FocusDistanceUpper/Lower values are fairly useless because they are so inaccurate.
Phil Harvey
Sorry it's really confusing... Then what is "Focus Distance Lower" and "Focus Distance Upper"?
Andy Li
I can see how this could be confusing. For my EOS 300D, the only possible values for these tags are: 0.26, 0.27, 0.35, 0.46, 0.59, 0.77, 1, 1.19, 1.42, 1.72, 2.22, 3.14, 5.46, 81.91 and -0.01 (the last value representing infinity I think). As you can see, there is not much useful resolution beyond 2 metres or so. For example (and ignoring the accuracy of these values for now), if I had my lens focused at 4 metres then the lower/upper values would be 3.14/5.46 (the low/high values closest to the actual focus distance), regardless of the aperture I used. I hope this makes a bit of sense.
Phil Harvey
I think I get it, thanks! :)
Andy Li
A: 

Hi there. I came across the above formulae while looking for dof calculations and found these ... Many thanks.

Just a couple of points:

  1. The values of t need to be checked in the program. If t = 1, then the focal distances are D/2 and infinity in which case D is actually the hyperfocal distance (hfd). This is easily proved and gives the hfd as (f**2)/(coc*Fnumber) approximately.

  2. If t is greater than 1 your answers will be negative and this is a meaningless result.

Jerry

Jerry