Batch Script for aligning/stacking/averaging a folder of photos [Windows]

I took a bunch of night-time photos not long ago, and wanted to stack and average them to improve the SNR. After much experimenting and asking here on the forums, I’ve finally put together a batch script that will take a folder full of RAW photos and output a 16-bit tiff ready for further editing in GIMP or RAWTherapee.

"C:\Program Files\RawTherapee-4.2.539\rawtherapee.exe" -b16 -t -w  -c IMG*.PEF
align_image_stack -m -v -a aligned_ IMG_*.tif
gmic -average_files aligned*.tif -o averaged.tif,ushort
DEL IMG_*.tif
DEL aligned_*.tif
"C:\Program Files\exiftool-10.25\exiftool.exe" -TagsFromFile IMG_0076*.PEF averaged.tif
"C:\Program Files\RawTherapee-4.2.539\rawtherapee.exe" -w averaged.tif
PAUSE

There’s a lot more I could do here, but this is just a very basic script that I can tweak to my liking. It is possible with the first option to have RAWTherapee read a .PP3 file and make adjustments to the RAW file before converting it to .tif

Obviously if you want to copy this script for your own use, you’ll have to change filenames and executable paths to match your system, but this should work pretty much out of the box otherwise!

Of course you’ll need to have all of the necessary software installed.

  • RAWTherapee
  • align_image_stack (from Hugin)
  • G’MIC
  • Exiftool

(Alternatively you could use dcraw for RAW conversion, and ImageMagick for averaging)

I registered the executables needed by following this answer on stackoverflow. That way I don’t have to type the path to the executable every time I want to call it!

If you have any suggestions for improvement, please speak up! I’ve already learned a lot, but I’m definitely open to learning more! :slight_smile:

Related topics:

2 Likes

Looks good.

If you want it be more flexible in the future may I suggest using AutoIt then.

it’s almost as simple as batch script but you have far more options and control this way and you even could compile such scripts into an EXE in the end.

Well AutoIt isn’t open source, it does not cost, except you want to donate. It’s out there for quite a while and used by a wide win user base today.

AutoHotkey is similar but is Free Software.

Congrats on the script @RT-Noob! I remember my first script, it changed the way I thought about doing my computing :slight_smile:

Hey @RT-Noob

Some tips:

  • If possible, use command-line options in the order specified in the --help, /?, man page or docs. This just makes it easier to look them up. Also a general tip though not applicable here, use the long form of the options, as this makes it easier for others to figure out what you did, or for yourself a year from now.
    e.g. use --make-more-awesome instead of -a.
  • Replace those paths with constants defined at the top of the script file, in a “user section”. e.g.:
    rt="C:\Program Files\RawTherapee-4.2.539\rawtherapee.exe"
    (…)
    rt -b16 -t -w -c IMG*.PEF (or whatever works in Windows)
  • For some more image metadata copying options, see
    G'MIC request: keep exif info - #4 by Morgan_Hardwood
  • Use --gpu with align_image_stack.
  • Update your RawTherapee! (it’s not RAWTherapee but RawTherapee)
1 Like

Thanks @anon19818677

Good suggestion, I never thought about using software like that for something like this!

Thank you @paperdigits, I’ve heard of AHK, and tried it briefly, but never really had any need for it.

@Morgan_Hardwood Wow, thanks for all the tips! That’s very good to know!

  • I have heard about using CLI options “in order”, but I never knew how to identify that order!

  • Thanks for the tip on constants too, that’s very useful! After a little online searching I found that for Windows in a batch script, the code is:


%rt% -b16 -t -w  -c EJM*.PEF ````

* I presume the commands you posted there for metadata copying are for Linux? Are there any equivalents for Windows?

* Got it, thanks!

* So I've been writing it wrong all this time! :frowning: I'm almost positive that I learned it correctly! Did it change, or was I deluded all this time? :slight_smile:

If order is important, the documentation should explain that. If it doesn’t, then the order most likely doesn’t matter, but it would make reading the script easier if in that case you went by the same order that the commands are explained in the docs.

The only thing that would change for Windows in those ExifTool examples is replacing exiftool with exiftool.exe or whatever the executable in Windows is called.

It hasn’t changed, so… :wink: