Tuesday, August 23, 2011

About EXIF lens identification accuracy

While EXIF tags can detect camera models with 100% confidence, the lens information on Sony cameras is a totally different story.
Basically, no tool is super-smart in identifying the lens correctly. Here I will compare only Lightroom and exiftool, which is the de facto standard.

Lightroom seems very conservative: very often it will say "unknown lens", but when it says "lens X-Y fZ" it is always correct (I don't have counterexamples, at least).
Most photos taken by Sony A100 are labeled "unknown lens", even when exiftool can identify correctly 90% of them. While this may look natural (older cameras may fail to write the EXIF tags correctly), it seems also that precision is not entirely camera-related.

From the exiftool documentation, it seems that Sony writes into some specific EXIF tags, which are different from what other manufacturers use. Anyway, I run exiftool on a raw file asking all possible lens-related fields, and the tool will return only what's available:

exiftool -SonyModelID -Lens -LensID -LensModel -LensType -LensMake -LensSerialNumber -FocalLength _DSC0350.ARW

Sony Model ID                   : DSLR-A550
Lens ID                         : Carl Zeiss Vario-Sonnar T* DT 16-80mm F3.5-4.5 ZA
Lens Type                       : Carl Zeiss Vario-Sonnar T* DT 16-80mm F3.5-4.5 ZA
Focal Length                    : 16.0 mm

In this case, Lightroom identified the lens correctly (for some reason, it always strips the brand name from the lens), in fact I look in the corresponding .xmp, which has been generated by Lightroom:

  <aux:Lens>DT 16-80mm F3.5-4.5 ZA</aux:Lens>

exiftool is actually able to extract information from .xmp

exiftool -Lens -LensID _DSC0350.xmp

Lens                            : DT 16-80mm F3.5-4.5 ZA
Lens ID                         : Carl Zeiss Vario-Sonnar T* DT 16-80mm F3.5-4.5 ZA

When Lightroom is unable to identify, there will be no <aux:Lens> at all.

If I repeat the same procedure on some different raw files from different Sony cameras, I get different results:

In the simplest case, a pair <camera body, lens> will give always the same result.
For example: the pair <Sony A100, Zeiss 16-80mm> is always labeled as "unknown lens" by Lightroom and is always identified correctly by exiftool.

Sometimes exiftool is correct, but not precise, as it emits multiple answers (the right one is usually the first or the second, but I can't say if they are ordered by likelihood).
Here the right lens is the old Sony 75-300mm f4.5-5.6:

exiftool -SonyModelID -Lens -LensID -LensType -FocalLength _DSC4200.ARW
Sony Model ID                   : DSLR-A550
Lens ID                         : Minolta AF 75-300mm F4.5-5.6 or Sigma 70-300mm F4-5.6 DL Macro or Sigma AF 170-500mm F5-6.3 APO Aspherical or Tokina AF 730 II 75-300mm F4.5-5.6
Lens Type                       : Minolta AF 75-300mm F4.5-5.6 or Sigma Lens
Focal Length                    : 300.0 mm

exiftool -SonyModelID -Lens -LensID -LensType -FocalLength _DSC4200.xmp
Lens                            : 75-300mm F4.5-5.6
Lens ID                         : Minolta AF 75-300mm F4.5-5.6 or Tokina AF 730 II 75-300mm F4.5-5.6
Focal Length                    : 300.0 mm

Sometimes exiftool is entirely wrong: this photo was taken with a Sigma 18-50 (I don't have a Tamron 18-200mm :).

exiftool -SonyModelID -Lens -LensID -LensType -FocalLength _DSC4251.ARW"
Sony Model ID                   : DSLR-A550
Lens ID                         : Tamron 18-200mm F3.5-6.3
Lens Type                       : Tamron or Sigma Lens (128)
Focal Length                    : 50.0 mm

exiftool -SonyModelID -Lens -LensID -LensType -FocalLength _DSC4251.xmp"
Lens                            : 18-50mm F2.8-4.5
Lens ID                         : Tamron 18-200mm F3.5-6.3
Focal Length                    : 50.0 mm

So summing up, when LR detects the lens, it may more precise than exiftool.
The latter exhibits some variability: from a list of photos taken with the same camera/lens, it will randomly emit some wrong results. I guess it's trying to disambiguate generic lens codes, maybe using focal length, aperture and whatever other parameter: this would also explain why LensID is sometimes different when deduced from .xmp and .ARW (as above).

However exiftool can also write fields in the xmp.
If LR is forced to reload metadata from files, then the lens is identified correctly.
So I used this command (on a mac) to copy the "LensID" field into the .xmp file, precisely when the lens is unidentified:

exiftool -if 'not $xmp:Lens' -xmp:Lens="$(exiftool -s3 -LensID [file.ARW])" [file.xmp]

this version will process an entire directory tree:
(it's a bit slow, but you usually run it only once)

find . -iname '*.xmp' -print0 | while read -d $'\0' i; do exiftool -if 'not $xmp:Lens' -xmp:Lens="$(exiftool -s3 -LensID "${i%.xmp}.ARW")" "${i}"; done

Since exiftool may return wrong results, I often have to perform some manual corrections.
For that I mostly use this command line (which runs much faster, because it's a single command working recursively):

exiftool -r -ext xmp -if '$Lens =~ /Tamron 18-200/' -Lens="18-50mm F2.8-4.5" *

This reads: for the entire directory tree, process all xmp files, if "Lens" contains "Tamron 18-200" replace it with "18-50mm F2.8-4.5".
You can use any regular expression between slashes and case-sensitive matching occurs with the =~ operator.
The operator !~ is used for spotting a non-match.

No comments:

Post a Comment