Last active
February 11, 2017 19:02
-
-
Save thcipriani/2422549292212a722044a37b84805d42 to your computer and use it in GitHub Desktop.
Quick(ish) awk script to find some stats about the focal length of pictures I've taken.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/awk -f | |
BEGIN { | |
FL_SUM = 0 | |
FL_CUR = 0 | |
FL_TOTAL = 0 | |
} | |
{ | |
getFocalLength($0) | |
FL_ARR[FL_CUR]++ | |
FL_SUM += FL_CUR | |
FL_TOTAL++ | |
} | |
function getFocalLength(file) { | |
if ( system("[ -e \"" $0 "\" ]") != 0 ) { | |
next | |
} | |
cmd = "exiftool -FocalLengthIn35mmFormat \"" file "\"" | |
cmd | getline focalLengthOut | |
close (cmd) | |
n = split(focalLengthOut, focalLength, ":") | |
eq = " (35mm)" | |
# Couldn't find 35mm equivalent, fallback to regular focallength | |
if (n == 0) { | |
cmd = "exiftool -FocalLength \"" file "\"" | |
cmd | getline focalLengthOut | |
close (cmd) | |
n = split(focalLengthOut, focalLength, ":") | |
# No focal length, give up :( | |
if (n == 0) { | |
next | |
} | |
eq = "" | |
} | |
FL = focalLength[2] | |
gsub(/^ +/, "", FL) | |
gsub(/\.[0-9]+ mm/, "", FL) | |
gsub(/ +mm$/, "", FL) | |
# Lens wasn't attached #MacroThings | |
if (FL == 0) { | |
next | |
} | |
print "Focal Length" eq ": " FL " mm" | |
FL_CUR = FL | |
} | |
END { | |
print "Focal Length Stats" | |
print "------------------" | |
print "Mean: " FL_SUM/FL_TOTAL " mm" | |
n = asort(FL_ARR, FL_DEST) | |
MODE_VAL = FL_DEST[n] | |
n = length(FL_ARR) | |
i = 0 | |
for (x in FL_ARR) { | |
if (i == int(n/2)) { | |
print "Median: " x " mm" | |
} | |
if (FL_ARR[x] == MODE_VAL) { | |
print "Mode: " x " mm" | |
} | |
i++ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ls ./*/*/*/*.{NEF,nef,jpg,jpeg} | awk -f focal_length_stats.awk |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have 1700ish pictures on my local computer.
I used to take a lot of pictures with my crop-body Nikon DX 35mm f/1.8. Now I take a lot of pictures with my full frame Nikon 50 mm f/1.8. Hence these boring stats: