Sunday, June 19, 2005

Focal-length statistics!

Have you ever wondered how the distribution of focal-lengths among your pictures are? If you have, I have created a tiny piece of script that can help you out! The EXIF data in the pictures are used.

Download img-focalstat. Save the file as img-focalstat.pl or whatever you like.

img-focalstat is a Perl script which takes a directory as input, scan the directory recursively for jpeg's, and check the focal length for each picture using jhead. The script show the number of pictures for each focal length, sorted from shortest to longest.

If you like, a GD bar-plot can be made of the data, with a width of each bar of your choice.

Also, all images for a particular focal length can be showed. This requires gthumb at the moment. May be made configureable on user-request.

To use the script, you need perl with File::Find, Getopt::Std, POSIX, and GD::Graph, as well as jhead and optionally gthumb. Should work on any linux, Mac OS X or other **ix. May work on Window$ as well.

The script is licenced under GPL.

syntax: img-focalstat.pl [directory| [-s focal-length] [-g ] [ -o filename ] [-n integer ] [ -i ] [ -b directory]

Description of options:

-s focal-length: Show all images with the given focal length using gthumb. Focal length should be specified as jhead show it, but without "mm". For instance 24.0 (and not just 24, at least with my jhead...)

-g : Make a GD::Graph bar-plot

-o : Output filename for bar-plot, must be a non-existant file, the script refuse to overwrite. Output will be a PNG image.

-n ingeger : The number of bars to have in the plot. Focal length will be distributed evenly on this number of bars.

-i : Include images with unknown focal length in the count and bar plot, show up as "n/a". For those cases where jhead are unable to detext any focal length in the EXIF data.

-b basedir : The basedirectory to scan. If any options are given, the base directory must be specified with the -b option. If no option is given, the base directory can just be given as the only argument to the script (without the -b)

Feel free to use or abuse or whatever. Comments are welcome :-)

Take care!

3 comments:

Anonymous said...

Hi there. Nice tool.

I made two modifications, both in sub findfocal:
I added quoted " to $filename, so filename with spaces etc. work:
open (EXIF, "jhead \"$filename\"|") or die ("Can't run jhead on file\n");

then, I change the regexp for finding to focal length to support multiple whitespace after the :
My Canon S1 IS formats lengts under 10mm with twoleading spaces to get alignment right.
The line becomes:
/^Focal length :\s*(\d+.\d*).*/ and $focal = $1 and last;

kind regards.

Åsmund Ødegård said...

Thanks for the updates! I'll change my own version accordingly. If you like me to add you as author in the file, just send me the details you like to have listed.

take care!

Anonymous said...

and on my box, the rgb file is at:
/usr/share/X11/rgb.txt