Pragmatism in the real world

Analysing the focal length of my photos

I’m currently thinking about upgrading my camera to an EOS R or Z6 and, as result, I’m thinking about which lenses I should get. While discussing options with Stuart, I wondered which were my favourite focal lengths for the photos that I’ve taken in the past.

To work this out, I decided to use the wonderful exiftool and some scripting. This is the analyse.sh script:

#!/bin/bash

DIR="$1"

if [ "$DIR" == "" ]; then
    echo "Usage: analyse.sh {directory}"
    exit
fi

exiftool -r -T -focallengthin35mmformat -aperture -lens -ext NEF -ext ARW $DIR > analysis.txt

awk '{print $1, $2}' analysis.txt | sort | uniq -c | \
    awk 'BEGIN { OFS = ", " } ; {print $2 $3, $1}' | \
    sort -n > analysis.csv

echo -e "\"Focal length\",count\n$(cat analysis.csv)" > analysis.csv

echo "Created analysis.csv"

There’s a couple of key things going on here. Firstly we use exiftool to generate a list of photo data for each of my raw images:

exiftool -r -T -focallengthin35mmformat -aperture -lens -ext NEF -ext ARW $DIR > analysis.txt

This uses the rather handy EXIF tag Focal Length In 35mm Format which normalises the lens focal lengths by taking into account the sensor size. e.g. my Nikkor 50/1.8 on my D90 behaves as a 75mm lens at 35mm format which was the closest that I could easily get to the 85mm portrait focal length.

The output looks like this:

$ cat analysis.txt
78 mm	6.3 18-135mm f/3.5-5.6
87 mm	9.0 18-135mm f/3.5-5.6
67 mm	5.6 18-135mm f/3.5-5.6
67 mm	5.6 18-135mm f/3.5-5.6
67 mm	5.6 18-135mm f/3.5-5.6
...

It’s just a list of the focal length, aperture and the lens model for each photo taken.

Now that we have the list of all the focal lengths, we want to count them and create a CSV file. We can use awk, uniq & sort for this:

awk '{print $1, $2}' analysis.txt | sort | uniq -c | \
    awk 'BEGIN { OFS = ", " } ; {print $2 $3, $1}' | \
    sort -n > analysis.csv

Let’s break that down.

Firstly we grab just the first two columns (the focal length) using awk and then sort the list to group all the same focal lengths together. This allows us to bin them using uniq -c. This creates a list like this:

$ cat analysis.txt | sort | uniq -c
   4 105 mm
   1 112 mm
   2 120 mm
   2 127 mm
  16 157 mm
...

The first column is the count, and then we have the label. We can use awk to convert this to a two column csv format by piping into:

awk 'BEGIN { OFS = ", " } ; {print $2 $3, $1}'

This sets the field separator (OFS) to a comma and then prints columns 2 and 3 together (the focal length), then the field separator and then column 3 (the count) leaving us with:

$ cat analysis.txt | sort | uniq -c | awk 'BEGIN { OFS = ", " } ; {print $2 $3, $1}'
105mm, 4
112mm, 1
120mm, 2
127mm, 2
157mm, 16
...

We then sort numerically (the -n switch to sort) and store to analysis.csv and we have our data.

Finally, we add a title to each column by prepending using echo with the -e switch so that we can add a new line character:

echo -e "\"Focal length\",count\n$(cat analysis.csv)" > analysis.csv

The net results is a CSV file with titles that can easily be charted using a spreadsheet or gnuplot or similar.

 $ cat analysis.csv
"Focal length",count
24mm, 402
25mm, 26
26mm, 5
27mm, 1396
28mm, 1179
29mm, 118
...

Analysis of my photos

Now that I have a script, I used it on my photo library for all photos taken since 2010:

$ cd Photos
$ analyse.sh 201*

This generates analysis.csv which I can graph. Taking out all focal lengths where I took less than 100 photos, I ended up with this:

Graph of focal lengths

Clearly I have a preference for 50mm and 75mm focal lengths! That’s slightly misleading though as those are also the focal lengths of the best lenses I have owned for the cameras that I’ve been using at the time. Also interesting is that there’s a clump around 27mm which implies that I like that angle of view, even though it’s not my best lens.

My impression is that a 24-70mm f/4 would be a great choice coupled with a 85mm f/1.8 as the initial lenses for my next system. I should probably also analyse the aperture that I most commonly use at 50mm to see if I also need to add a 50mm f/1.8 for the shallow depth of field effects that it would give me over the f/4 of the zoom.

2 thoughts on “Analysing the focal length of my photos

  1. Percentage of all photos taken at particular focal lengths. Data from one summer trip, where I've taken >2000 photos using 24-105 f/4 (only):
    – 24-45mm – 42%
    – 45-75mm – 32%
    – 75-105mm – 26%
    And from two opposite ends exactly (precisely that focal length):
    – 24mm – 20%
    – 105mm – 15%
    It appears that I lean toward the wider angle. But after switching to a more compact LX100 which has 24-75 equiv., I miss the extra reach a lot.

    1. Mike,

      That's really interesting. I feel the same in that I think that I would like to take photos with more reach. Maybe I need a good long lens to find out if it's the quality that makes me shy away.

Comments are closed.