News:

2023-08-10 - ExifTool version 12.65 released

Main Menu

Sony Lens Metadata

Started by gregglee, February 29, 2012, 01:55:55 PM

Previous topic - Next topic

gregglee

Does exiftool "specification" include attempting to determine which specific lens for a duplicated lens type value by using other parameters? 

If it does, do you want suggestions for the logic?

Sony 128 is a nasty example where some lenses cannot be determined, at least not at all focal lengths,  because of overlap in max aperture and focal length ranges.  But some could be simply determined from max aperture and focal length, such as three Sigma primes on the list.  Others could be determined over part of their focal length or aperture range.   

e.g.  if ( Max Aperture=1.4 and focal length=50) then name=Sigma 50mm F1.4 EX DG HSM

Current listing
128   = Tamron or Sigma Lens (128)
128.1   = Tamron 18-200mm F3.5-6.3
128.2   = Tamron 28-300mm F3.5-6.3
128.3   = Tamron 80-300mm F3.5-6.3
128.4   = Tamron AF 28-200mm F3.8-5.6 XR Di Aspherical [IF] MACRO
128.5   = Tamron SP AF 17-35mm F2.8-4 Di LD Aspherical IF
128.6   = Sigma AF 50-150mm F2.8 EX DC APO HSM II
128.7   = Sigma 10-20mm F3.5 EX DC HSM
128.8   = Sigma 70-200mm F2.8 II EX DG APO MACRO HSM
128.9   = Sigma 10mm F2.8 EX DC HSM Fisheye
128.10   = Sigma 50mm F1.4 EX DG HSM
128.11   = Sigma 85mm F1.4 EX DG HSM
128.12   = Sigma 24-70mm F2.8 IF EX DG HSM
just submitted above
128.13     = Sigma 18-250mm F3.5-6.3 DC OS HSM                             

Phil Harvey

The Composite tag documentation lists the tags used in the LensID determination.  These are:

LensType
FocalLength
MaxAperture
MaxApertureValue
ShortFocal
LongFocal
LensModel
LensFocalRange

The MaxAperture is definitely very useful.  ExifTool applies a heuristic formula to calculate the expected MaxAperture at the specific FocalLength (for zoom lenses where it changes with focal length), then compares this value to that reported by the lens.  This works well in many cases to differentiate lenses, but you will find that depending on the FocalLength of the zoom lens, the identification may be different.

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

gregglee

I realized this should be in a separate thread rather than discoveries.    I will post new.

gregglee

Quote from: Phil Harvey on March 01, 2012, 02:05:20 AM
Quote from: gregglee on February 29, 2012, 01:55:55 PM
Does exiftool "specification" include attempting to determine which specific lens for a duplicated lens type value by using other parameters? 

If it does, do you want suggestions for the logic? ....

Composite tag documentation lists the tags used in the LensID determination.  These are:
LensType  FocalLength  MaxAperture  MaxApertureValue  ShortFocal  LongFocal  LensModel  LensFocalRange

..... ExifTool applies a heuristic formula to calculate the expected MaxAperture at the specific FocalLength (for zoom lenses where it changes with focal length), then compares this value to that reported by the lens.  ...

The heuristic is what I was asking about improving.  Clearly in many cases for non-sony lenses on Sony cameras, for duplicate id's it just defaults to the first in the list.   Max aperture at focal length should certainly work for the Sigma 50mm f/1.4 in lenstype 128, but it doesn't.  The overlapping telezooms in 128 are another story of course.     

At the risk of duplicating information you already have, I learned in several Dyxum threads that Sony DSLRs except A100 write makernotes lensspec if supplied by the lens.  And that since 2010 Sony cameras write exif 2.3 lensinfo and lensmodel fields, and will construct these fields from an in-camera lookup table for older Minolta and Sony lenses that do not supply lensspec.  They also write these fields for non-Sony lenses that supply lensspec, but the lensmodel is generic - no model specific identifiers.  But could still be usefule to identify lens from a list.  Lens Information in Sony Alpha JPG and ARW files

I see lensmodel in the composite spec list, but not lensspec.  Lensmodel is derived from lensspec, but lensspec is still parsed rather than run together in a text string. 

Exiftool documentation for Sony tags shows the lensspec field, but not the values.   Sony:LensSpec deciphered

   

Phil Harvey

[I have split your previous posts and merged them into a new topic.]

Quote from: gregglee on March 02, 2012, 12:26:39 PM
The heuristic is what I was asking about improving.  Clearly in many cases for non-sony lenses on Sony cameras, for duplicate id's it just defaults to the first in the list.   Max aperture at focal length should certainly work for the Sigma 50mm f/1.4 in lenstype 128, but it doesn't.

I'm open to suggestions.  Here is the current logic:

            # now determine the best match for this aperture
            my $aa; # approximate maximum aperture at this focal length
            if ($sf == $lf or $sa == $la) {
                $aa = $sa; # this is a prime lens
            } else {
                # assume a log-log variation of max aperture with focal length
                # (see http://regex.info/blog/2006-10-05/263)
                $aa = exp(log($sa) + (log($la)-log($sa)) / (log($lf)-log($sf)) *
                                     (log($focalLength)-log($sf)));
            }
            my $d = abs($maxAperture - $aa);
            if (defined $diff) {
                $d > $diff + 0.15 and next;     # (0.15 is arbitrary)
                $d < $diff - 0.15 and undef @best;
            }


The comments will hopefully make it clear what is going on.

QuoteI see lensmodel in the composite spec list, but not lensspec.  Lensmodel is derived from lensspec, but lensspec is still parsed rather than run together in a text string. 

Exiftool documentation for Sony tags shows the lensspec field, but not the values.   Sony:LensSpec deciphered

The Sony LensSpec isn't a simple lookup table so it doesn't appear in the documentation.  It is decoded as follows:

#------------------------------------------------------------------------------
# Print Sony LensSpec value
# Inputs: 0) LensSpec numerical value
# Returns: converted LensSpec string (ie. "DT 18-55mm F3.5-5.6 SAM")
# Refs: http://equational.org/importphotos/alphalensinfo.html
#       http://www.dyxum.com/dforum/the-lens-information-different-from-lensid_topic37682.html
my @lensFeatures = (
    # lens features in the order they are added to the LensSpec string
    # (high byte of Mask/Bits represents byte 0 of LensSpec, low byte is byte 7)
    #  Mask   {  Bits     Name    Bits     Name  } Prefix flag
    # ------    ------    -----  ------    -----   -----------
    [ 0x0300, { 0x0100 => 'DT',  0x0300 => 'E'   }, 1 ],
    [ 0x000c, { 0x0004 => 'ZA',  0x0008 => 'G'   } ],
    [ 0x00e0, { 0x0020 => 'STF', 0x0040 => 'Reflex', 0x0060 => 'Macro', 0x0080 => 'Fisheye' } ],
    [ 0x0003, { 0x0001 => 'SSM', 0x0002 => 'SAM' } ],
    [ 0x8000, { 0x8000 => 'OSS' } ],
);
sub PrintLensSpec($)
{
    my $val = shift;
    # 0=flags1, 1=short focal, 2=long focal, 3=max aperture at short focal,
    # 4=max aperture at long focal, 5=flags2
    my ($f1, $sf, $lf, $sa, $la, $f2) = split ' ', $val;
    my ($rtnVal, $feature);
    # crude validation of focal length and aperture values
    if ($sf != 0 and $sa != 0 and ($lf == 0 or $lf >= $sf) and ($la == 0 or $la >= $sa)) {
        # use focal and aperture range if this is a zoom lens
        $sf .= '-' . $lf if $lf != $sf and $lf != 0;
        $sa .= '-' . $la if $sa != $la and $la != 0;
        $rtnVal = "${sf}mm F$sa";     # heart of LensSpec is a LensInfo string
        # loop through available lens features
        my $flags = hex($f1 . $f2);
        foreach $feature (@lensFeatures) {
            my $bits = $$feature[0] & $flags;
            next unless $bits or $$feature[1]{$bits};
            # add feature name as a prefix or suffix to the LensSpec
            my $str = $$feature[1]{$bits} || sprintf('Unknown(%.4x)',$bits);
            $rtnVal = $$feature[2] ? "$str $rtnVal" : "$rtnVal $str";
        }
    } else {
        $rtnVal = "Unknown ($val)";
    }
    return $rtnVal;
}


But you are correct that this information is not used in the LensID logic, and it probably should be.  This would probably mean writing a Sony-specific lens identification routine.  I have done this for Canon, but not other makes.  Perhaps it would make sense to do this for Sony too.  It would be very helpful if you could provide specific examples of all of the Lens-related tags for a case where this would help.  (The EXIF would be better:  exiftool your.jpg -o out.exif)

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

gregglee

#5
At first glance I think I see a logic problem, however:

Comments define $aa and $d.  But not $sf $lf $sa $la $diff, $maxaperture, $focalLength, so I hesitate to comment.
I can probably guess some but not sure of others.

my guess: 
$sf   min focal length
$lf   max focal length
$sa   aperture at min focal len
$la   aperture at max focal len
$diff    ??
$maxaperture    Max aperture at current focal length         
$focalLength    current focal length

Also which tag id's do the values come from?  More recent cameras write to more tagids.  Older lenses don't supply info for lensspec.  (lensspec Sony 0xb02a is the source the camera uses to write lensinfo exif 0xb02a and lensmodel exif 0xa434, so without lensspec, not lensinfo or lensmodel.  (Correction:  2010+ cameras have an internal lookup table from lenstype to lensinfo and lensmodel for Sony and Minolta lenses only.)  Non-Sony lenses may  supply incomplete or non-standard lesspec (which may be the problem with my Sigma 50mm f1.4 example.)         

If values come from lensinfo or lensmodel which are only written by 2010+ cameras, and for non-Sony lenses only those that supply lensspec correctly,  then I see why the heuristic has lack of data problems.   

And to check perl syntax. 
I am reading if ($sf == $lf) as "if $sf has the same value as $if),
I'm reading $aa = $sa "set value of $aa to current value of $sa."
What is meaning of "defined" in "defined $diff"  (I have found perl reference.  I just didn't find this yet.) 

gregglee

I'm still interested in this, but I do need to correct myself in one regard.  Now that I figured out where the composite tag results display in exiftool, I see that it does get the correct and complete name for the Sigma 50mm f1.4 in the composite tag.  Lenstype displays the generic 128 result.           

Now if I can just convince a couple software to use the composite lensid tag rather than lenstype 

gregglee

Quote from: Phil Harvey on March 03, 2012, 06:56:26 AM
I'm open to suggestions.  Here is the current logic:

            # now determine the best match for this aperture
            my $aa; # approximate maximum aperture at this focal length
            if ($sf == $lf or $sa == $la) {
                $aa = $sa; # this is a prime lens
            } else {   


I confirmed that I interpreted the == and = operators correctly. 
If $sf, $lf, $sa, $la are defined as I guessed above,  then it seems as though as written the test will identify a prime lens as prime, but it will also identify a fixed aperture zoom as prime, because the second condition $sa == $la would be true.

If I am reading all this correctly then "or" should be "and."

Phil Harvey

Sorry, you're right.  I didn't include enough of the subroutine to define $sf, $lf, $sa, $la, etc, but your guess was correct.  Also, your understanding of the numerical equivalence test (==) and assignment (=) operators is correct.

I added the misleading "this is a prime lens" comment when I pasted the code snippet.  It is either a prime or a fixed-aperture zoom as you point out.

The full source code is available in the Exif.pm module of any ExifTool distribution, or you can view it online at CPAN search.  Search the module for PrintLensID.  I think this may answer many of your questions.

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

gregglee

Thanks.  I'll look it up.

One other question.  For Sigma 50mm f1.4 on Sony A900 exiftool gets the composite lens id correct, but I don't understand where it gets the information.    The composite lens id tag uses these values (I added hex id if I could find it)


LensType               0xb027     MakerNotes
FocalLength            0x920a    ExifIFD
MaxAperture
MaxApertureValue       0x9205     ExifIFD
ShortFocal
LongFocal
LensModel              0xa434      ExifIFD
LensFocalRange

The camera does write Lenstype, FocalLength and Maxaperture value.
Camera does not write LensModel, so that's not the source for MaxAperture, ShortFocal, LongFocal, and LensFocalRange,  or for values of $sf, $lf, $sa, or  $la  which it does contain.   

Camera does write  LensSpec  0xb02a in makernotes which could also supply values of $sf, $lf, $sa, and $la, but Lensspec isn't listed in the composite tag sources. 

exiftool results for this combination 

C:\Users\Gregg>exiftool -G -n -H "D:\#My Pictures\2011\2011-11\2011-11-26\a900-11146.ARW"

[EXIF]          0x9205 Max Aperture Value              : 1.4142135623731
[EXIF]          0x920a Focal Length                    : 50
[MakerNotes]    0xb027 Lens Type                       : 128
[MakerNotes]    0xb02a Lens Spec                       : 00 50 0 1.4 0 00
[Composite]          - Lens ID                         : 128
[Composite]          - Focal Length                    : 50


C:\Users\Gregg>exiftool -G  -H "D:\#My Pictures\2011\2011-11\2011-11-26\a900-11146.ARW"

[EXIF]          0x9205 Max Aperture Value              : 1.4
[EXIF]          0x920a Focal Length                    : 50.0 mm
[MakerNotes]    0xb027 Lens Type                       : Tamron or Sigma Lens (128)
[MakerNotes]    0xb02a Lens Spec                       : 50mm F1.4
[Composite]          - Lens ID                         : Sigma 50mm F1.4 EX DG HSM
[Composite]          - Focal Length                    : 50.0 mm (35 mm equivalent: 50.0 mm)


   




 

Phil Harvey

In the list of LensType 128 lenses, I only see the one which is able to achieve 50mm and F1.4.

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

gregglee

Got it.    It doesn't need the detail of lensspec to get this one. 

I'll look at the full logic before I ask any more.  I have found a couple Sigma Lenses (not in 128) that should sort out at least at some focal lengths, but don't.  Maybe I can think of something.                 

Phil Harvey

Adding LensSpec to the logic would be fairly easy.  I'll try this for the next release.

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

gregglee

Yes, lensspec would definitely be useful since it is available in raw files makernotes from cameras that don't write exif 2.3 lensinfo and lensmodel.     
===============
I ran across an example that ought to be resolvable in composite lens id but isn't resolved.  Still in Sony 128.  Using a Sony 580 which does write exif lensmodel and lensinfo as well as makernotes lenstype and lensspec.  For Sigma 10-20mm f3.5 set at 20 mm, exiftool identifies it as either the Sigma 10-20 F3.5 or the Tamron 18-200mm F3.5-6.3.  (below 18mm composite tag id is only the 10-20 f3.5.)     

At 20mm the uniqueness test for fl and maxaperture doesn't differentiate.
But an additional uniqueness test using sf lf sa la would find only the 10-20 at all settings   

Note that lensmodel written by the Sony camera is a generic "10-20mm F3.5" apparently constructed from lensspec not the full name  "Sigma 10-20 F3.5 EX DC HSM."   That's not a surprise since Sony is not going to put Sigma lenses in its internal camera table, even if the Sigma lens supplies a code for the 8th byte, which it probably doesn't.  Sigma lens does not supply the first byte 01 ("DT" =  for crop sensor only) as Sony lens does, or we would have another sort parameter.  (several on the 128 list are for crop sensor only.)