Sunday, 29 January 2012

The joy of EXIF. Part 3: EXIFtool

EXIFtool is a free piece of software that can be run as a command-line tool, or a GUI is available. I use it as a command-line tool through the MacOSX Terminal app, and, as I'll demonstrate below, send the output from it through standard text processing tools to generate files of data that can be interpreted for drawing wider lessons.

EXIF tool generates plain text files that contain the metadata. Here is an example. One of my raw files (in this case _AJB2756.NEF) can be examined using EXIF tool as follows (note that the % symbol represents the command prompt):

%exiftool _AJB2756.NEF >exif.txt

The resulting file, exif.txt, contains a long list of data. Among these are the basic camera and exposure details: in addition, lots of other stuff that you might not expect to be in there as well is revealed. For example, the camera serial number, the type of lens, as well as data that I have embedded in the file in the process of ingesting raw files from my CompactFlash card onto my hard disk. Here’s a (very) abbreviated look:

ExifTool Version Number         : 8.55
File Name                       : _AJB2756.NEF
Make                            : NIKON CORPORATION
Camera Model Name               : NIKON D300
Usage Terms                     : For consideration only, no reproduction without prior written permission
Rating                          : 3
Exposure Time                   : 1/100
F Number                        : 11.0
Exposure Program                : Aperture-priority AE
ISO                             : 200
Create Date                     : 2010:05:16 10:14:04
Exposure Compensation           : +1/3
Focal Length                    : 50.0 mm
Quality                         : RAW
Lens ID                         : AF-S DX Zoom-Nikkor 18-70mm f/3.5-4.5G IF-ED

So, we’ve immediately got all the basic shooting details – exposure, lens etc. Even the star rating I applied to this image on first pass through ViewNX is revealed.

EXIFtool in batch
But how to learn from this? One of the things about EXIF tool that makes it so useful is that it runs in batch mode. This means it can extract the metadata from a large number of files at once. To extract meaning from the resulting pile of data, it is necessary to do a little bit of mining. Fortunately, since the data comes out as plain text, it is possible to use basic text processing tools to extract any piece of information you want.

Errr... here’s where it gets geeky. It involves Unix-style text processing. So, if you have a folder full of raw images (in my case Nikon NEF files), you might type the following at the command prompt:

%exiftool *.NEF >exif.txt

This generates a plain text file that can be read by Windows Notepad or Apple’s TextEdit etc. But this will probably generate more than you want to go through by hand. So the thing to do is to pick out lines that define relevant information in each image file, by directing the output through a word finder program (e.g. egrep) instead.

A trivial example might be to find out which lenses you use most when travelling, to help make a choice when next going away. For example, only one of the lenses I took with me to Cornwall earlier this year has Nikon's AF-S focusing, so I could search for AF-S using the tool egrep, and then find out how many instances of AF-S were reported by EXIFtool.

%exiftool *.NEF | egrep  AF-S | wc -l

But this simply duplicates what can be done more easily in Lightroom (see my previous piece).

Nevertheless, taking this approach, it's possible to search much further than Lightroom does at present. For instance,there are unique identifiers in the EXIF for each lens. Combining egrep and sed processes in a single line of commands, it is easy to get a listing of the actual focal lengths used (see note at bottom for the actual lines used) with any individual lens. If you feel the need to take this level of analysis further, the data can then go into something like Excel to look at how often ranges of focal lengths are used.

Analysis of the way I use the 18-70mm zoom reveals that I use focal lengths throughout the range, but with a strong bias towards the wide end.Not only that, but analysing the 10-20mm data suggests I like to use the range around 16-20mm a lot. Perhaps not surprising when my favoured very wide angle prime on film was 24mm (equivalent to 16mm on DX).

So why am I writing about this now? 

As I posted previously, I’ve just become the proud owner of a used D700. But that comes with a demand on lenses: the 18-70mm lens I have as a standard zoom on the D300 is a DX lens, and, although it will work on a D700, only yields a 5 MP image. So what to get as the standard zoom on the D700? I kind of know this instinctively anyway, but the closest fit to the way I use lenses is the 24-120mm f4 VR Nikkor. Bloody expensive though. But at least I have good reason for thinking I'd be likely make good use of it.

exiftool *.NEF |egrep "AF-S DX" -B 170 | egrep "^Focal Length  " | sed s/"Focal Length  *: "//g | sed s/" mm"//g >18-70.txt

exiftool *.NEF |egrep "HSM" -B 170 | egrep "^Focal Length  " | sed s/"Focal Length  *: "//g | sed s/" mm"//g >10-20.txt

(And yes, I'm sure that real Unix experts can come up with something much more economical to write and efficient to use, but this worked for me. But if you know of simpler and better code, please feel free to add a comment. Thanks.)

No comments:

Post a Comment