Linux script to automatically sort bracketed images

In a previous blog entry (Linux script to generate HDR images from bracketed images) I delivered a script to help creating HDR images out of a series of bracketed images.

But I then found myself facing another problem ... On my last vacation, I returned home with about 1500 images out of which maybe 300 where bracketed images ...
To use my tool, I would have had to manually create roughly 100 directories and figure out the series of 3 images that belonged together to isolate them in those folders ...

Instead of spending hours doing so, I decided to spend one hour writing a script that would automate this task.

So here it is !
Usage: sortBracketed.sh [OPTION] DIR
--quiet -q Quiet
--verbose -v Verbose
--dry-run -d Analyze but don't actually move the files
The script will run two passes. One for JPG files, one for CR2 files.
It checks the images three by three to make sure the numbering is continuous, that the exposure mode is bracketed and that the three images belong together because the progression of the exposure bias is consistent (0 -2 +2, -1 -2 0, etc)
When such image series are found, the script will create a sub-directory HDRx (where x is a number that is incremented automatically) and move the images there.

here's a simple example of a run:

Analyzing JPG files
Checking if file IMG_0003.JPG is bracketed ... NO
Checking if file IMG_0004.JPG is bracketed ... NO
Checking if file IMG_0005.JPG is bracketed ... NO
Checking if file IMG_0050.JPG is bracketed ... YES
Checking if file IMG_0051.JPG is bracketed ... YES
Checking if file IMG_0052.JPG is bracketed ... YES
Checking if file IMG_0053.JPG is bracketed ... YES
4 bracketed images found
Checking if images 0050 0051 0052 go together ... NO
Checking if images 0051 0052 0053 go together ... YES
IMG_0051.JPG \
IMG_0052.JPG |> HDR1 - Exposures: -1.5 0 1.5
IMG_0053.JPG /
Analyzing CR2 files
0 bracketed images found
And voilĂ  ! I end up with a folder HDR1 containing 3 images I can use to build an HDR image.

This is the default verbosity of the output. If you pass -q as a parameter, it will be totally silent. If you pass -v, it will be even more chatty ;-)

I show here a simple example but I actually used the script on my vacation pictures and it created 93 folders and perfectly identified the series of 3 images ! Yeah me !

If you don't trust the script will work on your images, you can invoke the -d option so it will only output the information but will not create folders and move files.

You can download the script here:


sortBracketed.sh

5k


Update (29 Sept 2009): updated the script to v1.1. See changelog in the script itself.
Update (19 Mar 2010): updated the script to v1.2. See changelog in the script itself.

CC-GNU GPL
This software is licensed under the CC-GNU GPL version 2.0 or later.

4 commentaires:

Jose Carlos said...

Thanks for the script. You should add NEF extension to it so it can also be used by people using Nikon cameras.

timetre said...

Thanks Jose; I'm actually in the process of adding NEF support. I needed to borrow a Nikon DSLR to get my hands on a series of breacketed RAW images ;-)
I Will update the code soon.

timetre said...

Just updated the script so it would properly analyse images produced by a Canon 50D

ed mcdonagh said...

On my Nikon D80, the key is in the exif tag Shooting Mode. On my photos where I have bracketed, I have the following:

Name: Exif.Nikon3.ShootingMode
Tag: 0x0089
Value: Continuous, Exposure bracketing

On other photos where I haven't bracketed, the value is simply Continuous. I presume this part can change, but if your script can test for Exposure bracketing, then it should work?

If you could script for Nikon too, that would be lovely! I'm afraid I can't stretch to giving you a Nikon DSLR to test with though!

Thanks.