Project

General

Profile

Calculating FocusDistanceUpper and Lower

Added by Dan narsh over 3 years ago

Hi All,

Wondering if anyone could give detail to how the "FocusDistanceUpper" and "FocusDistanceLower" tags are calculated for the Canon ShotInfo information? I've been looking around with no luck...

Thanks for your time!

- DAN


Replies (9)

RE: Calculating FocusDistanceUpper and Lower - Added by Robin Mills over 3 years ago

Dan: Thanks for bringing this to our attention. Can ExifTool recognise this metadata? Please attach an image (or images) and I'll investigate.

RE: Calculating FocusDistanceUpper and Lower - Added by Dan narsh over 3 years ago

Hi Robin,

Thanks for your quick reply, I've attached a sample image here.
I have used exiftool to read this meta data. What I'm really wanting to know is if the lens uses a sensor to return this "FocusDistanceUpper" and "FocusDistanceLower" values or if there is an equation used to determine them based on focal length, aperture, etc...

Thank you again,

Andy

RE: Calculating FocusDistanceUpper and Lower - Added by Robin Mills over 3 years ago

Thanks for your reply and file. Here's what I see:

546 rmills@rmillsmbp:~/Downloads $ curl -O http://dev.exiv2.org/attachments/download/1217/L_084_0117.jpg
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1205k    0 1205k    0     0   519k      0 --:--:--  0:00:02 --:--:--  520k
547 rmills@rmillsmbp:~/Downloads $ exiv2 -pa L_084_0117.jpg  | grep -i foc
Exif.Photo.FocalLength                       Rational    1  28.0 mm
Exif.CanonCs.FocusMode                       Short       1  Manual focus (3)
Exif.CanonCs.FocusType                       Short       1  Not known
Exif.CanonCs.FocusContinuous                 Short       1  (65535)
Exif.Canon.FocalLength                       Short       4  28.0 mm
Exif.CanonSi.AFPointUsed                     Short       1  3 focus points; none used
Exif.Photo.FocalPlaneXResolution             Rational    1  3443.95
Exif.Photo.FocalPlaneYResolution             Rational    1  3442.02
Exif.Photo.FocalPlaneResolutionUnit          Short       1  inch
548 rmills@rmillsmbp:~/Downloads $ exiv2 -pR L_084_0117.jpg  | grep -i foc
         366 | 0x920a FocalLength                  |  RATIONAL |        1 |       934 | 28/1
          1004 | 0x0007 Focus                        |     ASCII |       32 |      1352 | Firmware Version 1.0.4.........
         462 | 0xa20e FocalPlaneXResolution        |  RATIONAL |        1 |      1850 | 3072000/892
         474 | 0xa20f FocalPlaneYResolution        |  RATIONAL |        1 |      1858 | 2048000/595
         486 | 0xa210 FocalPlaneResolutionUnit     |     SHORT |        1 |           | 2
549 rmills@rmillsmbp:~/Downloads $ exiftool L_084_0117.jpg  | grep -i foc
Focal Length                    : 28.0 mm
Focus Mode                      : Manual Focus (3)
Focus Range                     : Not Known
Max Focal Length                : 135 mm
Min Focal Length                : 28 mm
Focal Units                     : 1/mm
Focal Plane X Size              : 23.22 mm
Focal Plane Y Size              : 15.49 mm
AF Points In Focus              : None (MF)
Focus Distance Upper            : 0.71 m
Focus Distance Lower            : 1.21 m
Focal Plane X Resolution        : 3443.946188
Focal Plane Y Resolution        : 3442.016807
Focal Plane Resolution Unit     : inches
Focal Length                    : 28.0 mm (35 mm equivalent: 44.5 mm)
Hyperfocal Distance             : 10.36 m
550 rmills@rmillsmbp:~/Downloads $ 
Our buddy Phil at ExifTool understands/discovers/calculates the upper/lower values. For me this is a puzzle.

Please understand that Exiv2 reports what is stored in the file. Other inspectors such as ExifTool (for which I have the greatest respect) may deduce other properties.

RE: Calculating FocusDistanceUpper and Lower - Added by Dan narsh over 3 years ago

Robin,

Thank you so much for you response and results.
I've been looking on ExifTool's forums as well to see if there is an answer asked by others. And contacted Canon about the parameters, to which they aren't sure where they come from. I'll check in with Phil/ExifTool for further detail.

Thank you again,

Dan

RE: Calculating FocusDistanceUpper and Lower - Added by Robin Mills over 3 years ago

Here's a discussion about this: https://www.dpreview.com/forums/thread/2917509

I'm on vacation at the moment (44th Wedding Anniversary today). I've been contributing to Exiv2 for 10 years. I didn't write the Canon MakerNote decoder and don't know how it works.

And here's some documentation in /usr/local/bin/lib/Image/ExifTool/TagNames.pod

=head3 Canon CameraInfo1DmkIV Tags

CameraInfo tags for the EOS 1D Mark IV.  Indices shown are for firmware
versions 1.0.x, but they may be different for other firmware versions.

  Index1   Tag Name                             Writable
  ------   --------                             --------
      3    FNumber                              int8u
      4    ExposureTime                         int8u
      6    ISO                                  int8u
      7    HighlightTonePriority                int8u
      8    MeasuredEV2                          int8u
      9    MeasuredEV3                          int8u
     21    FlashMeteringMode                    int8u
     25    CameraTemperature                    int8u
     30    FocalLength                          int16uRev
     53    CameraOrientation                    int8u
     84    FocusDistanceUpper                   int16uRev
     86    FocusDistanceLower                   int16uRev
    120    WhiteBalance                         int16u
    124    ColorTemperature                     int16u
    335    LensType                             int16uRev
    337    MinFocalLength                       int16uRev
    339    MaxFocalLength                       int16uRev
    493    FirmwareVersion                      no
    556    FileIndex                            int32u
    568    DirectoryIndex                       int32u
    872    PictureStyleInfo                     Canon PSInfo

RE: Calculating FocusDistanceUpper and Lower - Added by Robin Mills over 3 years ago

Positive Progress. This information is stored in CanonShotInfo:

534 rmills@rmillsmbp:~/gnu/exiv2/v0.26 $ exiftool -verbose ~/Downloads/L_084_0117.jpg | grep -i dis
  | | | | DisplayAperture = 0
  | | | | FocusDistanceUpper = 71
  | | | | FocusDistanceLower = 121
  | | | | 13) SuperimposedDisplay = 0
535 rmills@rmillsmbp:~/gnu/exiv2/v0.26 $ 
  | | | 3)  CanonShotInfo (SubDirectory) -->
  | | | + [BinaryData directory, 54 bytes]
  | | | | AutoISO = 0
  | | | | BaseISO = 224
  | | | | MeasuredEV = 8
  | | | | TargetAperture = 128
  | | | | TargetExposureTime = 96
  | | | | ExposureCompensation = 0
  | | | | WhiteBalance = 0
  | | | | SlowShutter = 3
  | | | | SequenceNumber = 0
  | | | | OpticalZoomCode = 8
  | | | | CameraTemperature = 0
  | | | | FlashGuideNumber = 0
  | | | | AFPointsInFocus = 12288
  | | | | FlashExposureComp = 0
  | | | | AutoExposureBracketing = 0
  | | | | AEBBracketValue = 0
  | | | | ControlMode = 3
  | | | | FocusDistanceUpper = 71
  | | | | FocusDistanceLower = 121
  | | | | FNumber = 128
  | | | | ExposureTime = 104
  | | | | MeasuredEV2 = 90
  | | | | BulbDuration = 0
  | | | | CameraType = 252
I'll have a sniff around the Canon Maker Note Decoder in the debugger.

RE: Calculating FocusDistanceUpper and Lower - Added by Robin Mills over 3 years ago

I know where the information is stored! Here's the documentation: https://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Canon.html#ShotInfo. It's tag 0x0004 in the MakerNote and coded as 27xSHORT (54 bytes)

527 rmills@rmillsmbp:~/gnu/github/exiv2/exiv2 $ exiv2 -pR ~/Downloads/L_084_0117.jpg | grep 27
         222 | 0x8827 ISOSpeedRatings              |     SHORT |        1 |           | 400
         270 | 0x9101 ComponentsConfiguration      | UNDEFINED |        4 |           | ...
         378 | 0x927c MakerNote                    | UNDEFINED |      908 |       942 | ......+........................ ...
           980 | 0x0004 Quality                      |     SHORT |       27 |      1266 | 54 0 224 8 128 ...   <---- It's in here
          1124 | 0x00aa                              |     SHORT |        5 |      1758 | 10 930 1021 1027 789
    3227 | 0xffc4 DHT   |     418 
528 rmills@rmillsmbp:~/gnu/github/exiv2/exiv2 $ 
I've doctored my local copy to dump all 27 SHORTS and:
980 | 0x0004 Quality  |  SHORT |  27 |  1266 | 54 0 224 8 128 96 0 0 3 0 8 8 0 0 12288 0 0 0 3 71 121 128 104 90 0 0 252 

I need to do more work to understand how the decoder works. Positive Progress. I'll probably solve this next week when I get home from vacation.

RE: Calculating FocusDistanceUpper and Lower - Added by Robin Mills over 3 years ago

Here's the CanonShotInfo in exiv2:

549 rmills@rmillsmbp:~/gnu/github/exiv2/exiv2 $ exiv2 --grep CanonSi -pa ~/Downloads/L_084_0117.jpg 
Exif.CanonSi.ISOSpeed                        Short       1  400
Exif.CanonSi.MeasuredEV                      Short       1  5.25
Exif.CanonSi.TargetAperture                  Short       1  F4
Exif.CanonSi.TargetShutterSpeed              Short       1  1/8 s
Exif.CanonSi.WhiteBalance                    Short       1  Auto
Exif.CanonSi.Sequence                        Short       1  0
Exif.CanonSi.AFPointUsed                     Short       1  3 focus points; none used
Exif.CanonSi.FlashBias                       Short       1  0 EV
Exif.CanonSi.SubjectDistance                 Short       1  0.71 m
Exif.CanonSi.ApertureValue                   Short       1  F4
Exif.CanonSi.ShutterSpeedValue               Short       1  1/10 s
Exif.CanonSi.MeasuredEV2                     Short       1  5.25
550 rmills@rmillsmbp:~/gnu/github/exiv2/exiv2 $ 
exiftool output is above. Exiv2 reports FocusDistanceUpper as SubjectDistance and doesn't report FocusDistanceUpper. When I modify the ShotInfo definitions (in src/canonmn_int.cpp, as follows):
    const TagInfo CanonMakerNote::tagInfoSi_[] = {
...
        TagInfo(0x0013, "SubjectDistance", N_("Subject Distance"), N_("Subject distance"), canonSiId, makerTags, unsignedShort, 1, printSi0x0013),
        TagInfo(0x0014, "FocalDistanceLower", N_("Focal Distance Lower"), N_("Focal Distance Lower"), canonSiId, makerTags, unsignedShort, 1, printSi0x0013),
...
    };

The output is:
560 rmills@rmillsmbp:~/gnu/github/exiv2/exiv2/build $ bin/exiv2 --grep distance/i -pa ~/Downloads/L_084_0117.jpg 
Exif.CanonSi.SubjectDistance                 Short       1  0.71 m
Exif.CanonSi.FocalDistanceLower              Short       1  1.21 m
561 rmills@rmillsmbp:~/gnu/github/exiv2/exiv2/build $  

So, almost there. For sure we have a work-around.

There's a sting in the tail. The following code is in src/actions.cpp (which is mostly the exiv2 command line):

        // Subject distance
        {
            printLabel(_("Subject distance"));
            bool done = false;
            if (!done) {
                done = 0 != printTag(exifData, "Exif.Photo.SubjectDistance");
            }
            if (!done) {
                done = 0 != printTag(exifData, "Exif.CanonSi.SubjectDistance");
                done = 0 != printTag(exifData, "Exif.CanonFi.FocusDistanceLower");
                done = 0 != printTag(exifData, "Exif.CanonFi.FocusDistanceUpper");
            }
            std::cout << std::endl;
        }
That code acknowledges the existence of Exif.CanonFi.FocusDistanceLower and Exif.CanonFi.FocusDistanceLower. These tags are defined:
../src/canonmn_int.cpp:        TagInfo(0x0014, "FocusDistanceUpper", N_("Focus Distance Upper"), N_("Focus Distance Upper"), canonFiId, makerTags, signedShort, 1, printFiFocusDistance),
../src/canonmn_int.cpp:        TagInfo(0x0015, "FocusDistanceLower", N_("Focus Distance Lower"), N_("Focus Distance Lower"), canonFiId, makerTags, signedShort, 1, printFiFocusDistance),
Here's the table:
    // Canon File Info Tag
    const TagInfo CanonMakerNote::tagInfoFi_[] = {
        TagInfo(0x0001, "FileNumber", N_("File Number"), N_("File Number"), canonFiId, makerTags, unsignedLong, 1, printFiFileNumber),
        TagInfo(0x0003, "BracketMode", N_("Bracket Mode"), N_("Bracket Mode"), canonFiId, makerTags, signedShort, 1, EXV_PRINT_TAG(canonBracketMode)),
        TagInfo(0x0004, "BracketValue", N_("Bracket Value"), N_("Bracket Value"), canonFiId, makerTags, signedShort, 1, printValue),
        TagInfo(0x0005, "BracketShotNumber", N_("Bracket Shot Number"), N_("Bracket Shot Number"), canonFiId, makerTags, signedShort, 1, printValue),
        TagInfo(0x0006, "RawJpgQuality", N_("Raw Jpg Quality"), N_("Raw Jpg Quality"), canonFiId, makerTags, signedShort, 1, EXV_PRINT_TAG(canonCsQuality)),
        TagInfo(0x0007, "RawJpgSize", N_("Raw Jpg Size"), N_("Raw Jpg Size"), canonFiId, makerTags, signedShort, 1, EXV_PRINT_TAG(canonRawJpgSize)),
        TagInfo(0x0008, "NoiseReduction", N_("Noise Reduction"), N_("Noise Reduction"), canonFiId, makerTags, signedShort, 1, EXV_PRINT_TAG(canonNoiseReduction)),
        TagInfo(0x0009, "WBBracketMode", N_("WB Bracket Mode"), N_("WB Bracket Mode"), canonFiId, makerTags, signedShort, 1, EXV_PRINT_TAG(canonWBBracketMode)),
        TagInfo(0x000c, "WBBracketValueAB", N_("WB Bracket Value AB"), N_("WB Bracket Value AB"), canonFiId, makerTags, signedShort, 1, printValue),
        TagInfo(0x000d, "WBBracketValueGM", N_("WB Bracket Value GM"), N_("WB Bracket Value GM"), canonFiId, makerTags, signedShort, 1, printValue),
        TagInfo(0x000e, "FilterEffect", N_("Filter Effect"), N_("Filter Effect"), canonFiId, makerTags, signedShort, 1, EXV_PRINT_TAG(canonFilterEffect)),
        TagInfo(0x000f, "ToningEffect", N_("Toning Effect"), N_("Toning Effect"), canonFiId, makerTags, signedShort, 1, EXV_PRINT_TAG(canonToningEffect)),
        TagInfo(0x0010, "MacroMagnification", N_("Macro Magnification"), N_("Macro magnification"), canonFiId, makerTags, signedShort, 1, printValue),
        TagInfo(0x0013, "LiveViewShooting", N_("Live View Shooting"), N_("Live view shooting"), canonFiId, makerTags, signedShort, 1, EXV_PRINT_TAG(canonOffOn)),
        TagInfo(0x0014, "FocusDistanceUpper", N_("Focus Distance Upper"), N_("Focus Distance Upper"), canonFiId, makerTags, signedShort, 1, printFiFocusDistance),
        TagInfo(0x0015, "FocusDistanceLower", N_("Focus Distance Lower"), N_("Focus Distance Lower"), canonFiId, makerTags, signedShort, 1, printFiFocusDistance),
        TagInfo(0x0019, "FlashExposureLock", N_("Flash Exposure Lock"), N_("Flash exposure lock"), canonFiId, makerTags, signedShort, 1, EXV_PRINT_TAG(canonOffOn)),
        // End of list marker
        TagInfo(0xffff, "(UnknownCanonFiTag)", "(UnknownCanonFiTag)", N_("Unknown Canon File Info tag"), canonFiId, makerTags, signedShort, 1, printValue)
    };

I suspect this is for use by a different camera. I'll have to think about this and look more at the exiftool documentation.

RE: Calculating FocusDistanceUpper and Lower - Added by Robin Mills over 3 years ago

There was a patch in 2014 about FocusDistanceUpper and FocusDistanceUpper in Canon .CR2 Raw files. http://dev.exiv2.org/issues/0000954

I found a discussion on a Forum: https://www.dpreview.com/forums/post/42411527
This referenced a page of sample images: http://www.imaging-resource.com/PRODS/canon-1dx/canon-1dxA7.HTM
I've downloaded one: https://www.imaging-resource.com/PRODS/canon-1dx/FULLRES/E1DXINBI000050.CR2

590 rmills@rmillsmbp:~/gnu/exiv2 $ exiv2 -pa --grep CanonFi E1DXINBI000050.CR2
Exif.CanonFi.FileNumber                      Long        1  (0)
Exif.CanonFi.BracketMode                     SShort      1  Off
Exif.CanonFi.BracketValue                    SShort      1  0
Exif.CanonFi.BracketShotNumber               SShort      1  0
Exif.CanonFi.RawJpgQuality                   SShort      1  (0)
Exif.CanonFi.RawJpgSize                      SShort      1  Large
Exif.CanonFi.NoiseReduction                  SShort      1  (-1)
Exif.CanonFi.WBBracketMode                   SShort      1  Off
Exif.CanonFi.WBBracketValueAB                SShort      1  0
Exif.CanonFi.WBBracketValueGM                SShort      1  0
Exif.CanonFi.FilterEffect                    SShort      1  (-1)
Exif.CanonFi.ToningEffect                    SShort      1  (-1)
Exif.CanonFi.MacroMagnification              SShort      1  136
Exif.CanonFi.LiveViewShooting                SShort      1  Off
Exif.CanonFi.FocusDistanceUpper              SShort      1  2.13 m  <--- Yes
Exif.CanonFi.FocusDistanceLower              SShort      1  1.73 m  <--- Yes
Exif.CanonFi.FlashExposureLock               SShort      1  Off
591 rmills@rmillsmbp:~/gnu/exiv2 $ 
So the CanonFi (Canon File Information) data structure is for Cameras that support .CR2. I download the equivalent JPG and:
592 rmills@rmillsmbp:~/gnu/exiv2 $ exiv2 -pa --grep dist/i ~/Downloads/E1DXINBI000050.jpg 
Exif.CanonSi.SubjectDistance                 Short       1  0 m
Exif.CanonFi.FocusDistanceUpper              SShort      1  2.13 m
Exif.CanonFi.FocusDistanceLower              SShort      1  1.73 m
593 rmills@rmillsmbp:~/gnu/exiv2 $ 
And that plays perfectly with the code above discovered in actions.cpp:
593 rmills@rmillsmbp:~/gnu/exiv2 $ exiv2 ~/Downloads/E1DXINBI000050.jpg 
File name       : /Users/rmills/Downloads/E1DXINBI000050.jpg
File size       : 8982640 Bytes
MIME type       : image/jpeg
Image size      : 5184 x 3456
Camera make     : Canon
Camera model    : Canon EOS-1D X
Image timestamp : 2012:08:30 14:32:08
Image number    : 
Exposure time   : 0.6 s
Aperture        : F4
Exposure bias   : +2/3 EV
Flash           : No, compulsory
Flash bias      : 0 EV
Focal length    : 70.0 mm
Subject distance: 0 m1.73 m2.13 m  <---------- Yes!  That works.
ISO speed       : 50
Exposure mode   : Aperture priority
Metering mode   : Multi-segment
Macro mode      : Off
Image quality   : Fine
Exif Resolution : 5184 x 3456
White balance   : Custom
Thumbnail       : image/jpeg, 15513 Bytes
Copyright       : 
Exif comment    : 

594 rmills@rmillsmbp:~/gnu/exiv2 $ 
The work-around suggested above (add 0x0014, "FocalDistanceLower") disturbs our test suite because we are reporting data that has been ignored in the past. When I modify "Subject Distance" to be "FocalDistanceUpper" in tagInfoSi_ in src/canonmn_int.cpp, many more exceptions.
    const TagInfo CanonMakerNote::tagInfoSi_[] = {
...
        TagInfo(0x0013, "FocalDistanceUpper", N_("Focal Distance Upper"), N_("Focal Distance Upper"), canonSiId, makerTags, unsignedShort, 1, printSi0x0013),
        TagInfo(0x0014, "FocalDistanceLower", N_("Focal Distance Lower"), N_("Focal Distance Lower"), canonSiId, makerTags, unsignedShort, 1, printSi0x0013),
...
    };
I've looked at exiftool documentation for Canon Tags. I suspect the Exiv2 code which treats 0x0013 as "SubjectDistance" is a long term error. However, I'm bothered that changing to "FocalDistanceUpper" could cause issues for applications that use Exiv2 (such as digiKam and darktable) which may be expecting "Subject Distance" in the metadata for lens correction.

Having investigated this, I also think we should populate other members of CanonSi which have been documented by exiftool. This will cause more ripples in the test suite.

I don't think I'm going to do any more work on this for the moment. I've done enough to answer the original question: Wondering if anyone could give detail to how the "FocusDistanceUpper" and "FocusDistanceLower" tags are calculated for the Canon ShotInfo information? I've been looking around with no luck..

If you feel this must be fixed in Exiv2, please raise an issue on https://github.com/Exiv2/exiv2/issues and it will receive attention.

    (1-9/9)