Time-lapse Deshake

Automatically aligning hundreds of images to an anchor

It works with just a few clicks - thank you Bruno Postle for your nona-deshake solution!

https://groups.google.com/forum/#!searchin/hugin-ptx/nona-deshake%7Csort:date/hugin-ptx/yFE6VF-mtGk/U8OYAuNYCgAJ

This article details how I implemented it on a Windows machine, using hugin "bin" commands called from an ActiveState Perl script. After a one-time install/config (details below), it takes less than 5 minutes of wall clock time to launch a new align project and walk away - letting the old laptop churn at a rate of 4 seconds per image.

What's the Problem?

For Bruno, it was his webcam shaking in the wind. In my case, the tripod very slowly shifted in the snow bank (next time bring a weight!). In post, when I tried to stack them and use lighten, the foreground blurred.

Figure 1 - image shift of distant buildings during 1hr (500+ images stacked & lightened)

Most software has a limit to the number of images in the stack, requiring the user to do it in batches. But not this way!

Method [once preliminary installs are done]

  • Load image into Hugin, crop, save pto file.
  • Run: c:\Perl64\bin\perl.exe -w C:\Users\xxxxxxx\Documents\perlscripts\nona-deshake_v02.pl -o OI_ deshake.pto *.jpg
  • that's it.

Figure 2 - Fig. 1 after nona-deshake, 500+ images stacked & lightened

Preliminaries required:

  • Hugin. This will put some needed exe in a bin folder.
  • ActiveState Perl to run the loop and modify the pto files. Without perl and the Panotools::Script module (see below), you will have to create your own batch script to read and modify pto (text) files.
  • Minor mod to add file globbing to windows command lines. See below.
  • Minor mod to Bruno's perl script so it can find directories on Windows. See below.

Details:

  • Hugin (free): http://hugin.sourceforge.net/
  • note location of the bin directory. For me it was: C:\Program Files\Hugin\bin
  • copy the entire bin folder to the root of the external drive [if using one]
  • install ActiveState Perl for Windows (free). Run simple "hello world" to check.
  • mine was installed here: c:\Perl64.
  • cd C:\Perl64\bin
  • ppm install Panotools::Script [useful toolbox; required by Bruno's deshake script]
  • ppm install File::Spec [if not already present]
  • enable windows file globbing by wildcard expansion:

[https://docs.activestate.com/activeperl/5.26/perl/lib/Pod/perlwin32.html]

from a command-line window, type:

copy con c:\perl64\lib\Wild.pm [ or where your perl lib is located ]

# Wild.pm - emulate shell @ARGV expansion on shells that don't use File::DosGlob;

@ARGV = map {

my @g = File::DosGlob::glob($_) if /[*?]/;

@g ? @g : $_;

} @ARGV;

1;

^Z [ctrl-z]

  • from a prompt type

set PERL5OPT=-MWild

  • you might want to edit Wild.pm with notepad to see that it contains what you just typed in
  • I copied Bruno's nona-deshake.pl to nona-deshake_v02.pl then edited:
  • new line 9: my $HUGINBIN = "\\bin";
  • new line 56: system("$HUGINBIN\\align_image_stack", [etc.]
  • new line 58: system("$HUGINBIN\\nona", '-m', 'JPEG', '-z', '100', [etc.]
  • The bin change was needed because I was running the scripts on an external drive and simply couldn't figure out a way to call nona from the perl script on C:. The double back-slashes are required on my Windows system in order to pass the backslash through. I changed the -z jpg compression to 100 to suit my purposes. Bruno used 75 for his video project but it was not enough for my stacking
  • cd to the directory containing the images [ my preference]
  • the command-line call is: c:\Perl64\bin\perl.exe -w C:\Users\xxxxxxx\Documents\perlscripts\nona-deshake_v02.pl -o OI_ deshake.pto *.jpg
  • watch out for the case of jpg or JPG!
  • the -o OI_ is the output prefix, so the processed images come out sequentially as OI_000001.jpg OI_000002.jpg etc. in the same directory. Original files are left alone.
  • If any directory in the command has a space in it [C:\Users\xxx\My Docs\perl scripts\non-deshake_v02.pl] put double quotes around it!

Once per project: create simple pto file before running the command

Start the Hugin GUI, drag and drop the first (anchor) image, click on the stitcher tab, click the "calculate optimal size" button, click the panorama preview to graphically crop (though values could be manually input on the stitcher tab. I cropped out 40 pixels on each edge, but could have done it at 15, depends on the amount of shake), then click the stitch button. You will be asked to save a pto file (in this example I chose deshake.pto), which will be the one you input on Bruno's command-line call. It saves it to the directory containing the anchor image. I also delete the image that hugin generates so it does not get included in the big process that follows.

Run the script, wait 30-60 minutes depending on your processors and number of images. It spits out a running count so you can see it is progressing and not hanging. Mine was 4 seconds per image.

Control Points?!

I was also concerned that I did not get to choose the control/match points in advance. For my one case this it did not matter. Might have to use celeste in the future to prevent cloud points.