DOF calculation with Canon?

Started by Marsu42, April 09, 2015, 07:32:52 AM

Previous topic - Next topic

Marsu42

I just read about the built-in dof calculation of exiftool, but no can do with my Canon 6d as the appropriate tags for this camera don't seem to be used in the calculation (yet!).

From the tags spec (at https://exiftool.org/TagNames/Composite.html), I tested 'exiftool -FocalLength -Aperture -CircleOfConfusion -FocusDistance -SubjectDistance -ObjectDistance' on the source files. Neither Distance tags are in .cr2 .or (converted) .dng tags, but:

1) .cr2 contains "-Canon:FocusDistanceLower" and -"Canon:FocusDistanceUpper"
2. .dng/.tif/.jpg converted or exported by an Adobe app also contain "-XMP-aux:ApproximateFocusDistance" which seems to be about the mean of the above values. The Canon Maker tags usually don't make it into exported files btw.

Request: Add "XMP-aux:ApproximateFocusDistance" to be used by the dof calculation formula, and if that isn't there check for "-Canon:FocusDistanceLower" and -"Canon:FocusDistanceUpper" and take the mean of these.


Phil Harvey

I'm not sure if adding such an approximate DOF may confuse some people, because the Canon FocusDistance tags aren't very accurate.

Also, what is the ApproximateFocusDistance when the FocusDistanceUpper is 'inf' ?

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Marsu42

Quote from: Phil Harvey on April 09, 2015, 10:06:01 AM
I'm not sure if adding such an approximate DOF may confuse some people, because the Canon FocusDistance tags aren't very accurate.

They aren't? Doesn't that depend on the body-lens combination, too? With my recent model(s) 60d and  6d and better lenses (100L, 70-300L, 17-40L) the ApproximateFocusDistance values seem to be just fine, though I admit I didn't do any actual comparisons to the actual physical length and I don't expect the camera to function as a yard stick anyway.

Imho, if Adobe seem fit to calculate ApproximateFocusDistance, I don't think exiftool would get a bad rep by using this ... it's not like you couldn't add a warning to the "composite tags" spec page in the DOF section about Canon probably not being as precise as other brands.

Last not least, as you know "dof" isn't exact in any case because it depends on so many variables, so some added fuzz from dodgy distances shouldn't rock the boat too much ... much better having a hint about the DOF than having nothing at all like just now.

Quote from: Phil Harvey on April 09, 2015, 10:06:01 AM
Also, what is the ApproximateFocusDistance when the FocusDistanceUpper is 'inf' ?

In that case, ApproximateFocusDistance is broken and shows a fixed 4294967295 value. I nearly forgot, I already check for this bug in my scripts - you might want to code this into exiftool, too.

Phil Harvey

Quote from: Marsu42 on April 09, 2015, 04:49:06 PM
In that case, ApproximateFocusDistance is broken and shows a fixed 4294967295 value. I nearly forgot, I already check for this bug in my scripts - you might want to code this into exiftool, too.

Yes, but what to you use for an ApproximateFocusDistance here?

If I average FocusDistanceLower and infinity, I get infinity, but then the lower end of the DOF is actually larger than the FocusDistanceLower, which seems wrong.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Marsu42

Quote from: Phil Harvey on April 09, 2015, 06:18:56 PM
which seems wrong.

Hmmmyes, I see your predicament, thought about it myself and had no real solution there. Returning some strange, semi random number still doesn't seem like an optimal solution here.

Quote from: Marsu42 on April 09, 2015, 04:49:06 PM
In that case, ApproximateFocusDistance is broken and shows a fixed 4294967295 value. I nearly forgot, I already check for this bug in my scripts - you might want to code this into exiftool, too.
If I average FocusDistanceLower and infinity, I get infinity, but then the lower end of the DOF is actually larger than the FocusDistanceLower

Why's that exactly - because if AverageFocusDistance is calculated as infinity exiftool would return zero as a number instead of a "inf" string like in FocusDistanceUpper?

Phil Harvey

Quote from: Marsu42 on April 10, 2015, 02:26:40 AM
Why's that exactly - because if AverageFocusDistance is calculated as infinity exiftool would return zero as a number instead of a "inf" string like in FocusDistanceUpper?

I'm not sure I understand.  If I treat "inf" as the largest representable number, then the average of "inf" plus anything is very large.  Treating "inf" as zero doesn't make sense.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Marsu42

Quote from: Phil Harvey on April 10, 2015, 07:17:54 AM
Quote from: Marsu42 on April 10, 2015, 02:26:40 AM
Why's that exactly - because if AverageFocusDistance is calculated as infinity exiftool would return zero as a number instead of a "inf" string like in FocusDistanceUpper?
I'm not sure I understand.  If I treat "inf" as the largest representable number, then the average of "inf" plus anything is very large.  Treating "inf" as zero doesn't make sense.

Indeed it doesn't - but in reverse, I was wondering how to understand your sentence "If I average FocusDistanceLower and infinity, I get infinity, but then the lower end of the DOF is actually larger than the FocusDistanceLower, which seems wrong.".

Anyway, if this is "works as designed" than it's quite alright, but imho you should make a comment about this largest possible number idea on the xmp tags spec page... and of course don't let me detain you from adding ApproxFocusDistance to the dof calculation (unless it's indeed infinity) which is the original idea of the thread :-)

Phil Harvey

I just tested this.  Canon's numerical value for infinity is 655.35 metres, so the this gives an average in the 300 m range, and an output like this:

> exiftool ../pics/CanonEOS-1D_MarkIII.jpg -focusdistance'*' -dof
Focus Distance Upper            : inf
Focus Distance Lower            : 10.76 m
Depth Of Field                  : 238.40 m (252.12 - 490.52)


which doesn't really give me a warm fuzzy feeling.

- Phil

...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Marsu42

Quote from: Phil Harvey on April 10, 2015, 08:51:18 AM
I just tested this.

Me, too - and it seems you made a typo, the Adobe tag you want is "-XMP-aux:ApproximateFocusDistance" while you use "AverageFocusDistance" in version 9.92 ?

As for the quality: Yeah, it gets more unreliable the more you focus towards inf, but my observation is that on closer distances (which probably covers most of the images out there you want to check the dof for) the values are ok-ish. The problem seems to be that they're not very "accurate" due to the rough scale, but "precise" enough so it's not hit-or-miss (https://en.wikipedia.org/wiki/Accuracy_and_precision#Terminology_of_ISO_5725). Imho in any case certainly good enough to be used by exiftool, probably with the suggested warning for Canon in the Composite:DoF tag description on your website.

Phil Harvey

Thanks.  I'll fix the ApproximateFocusDistance in the next release.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).