Time lapse stabilization
Time Lapse stabilization
Remember the shaky videos of rockets being launched from the old days?
Did you see the modern NASA videos , where the FRAME bounces around the object being filmed, while the rocket remains perfectly stable in view? Thats' what you'll be able to do after reading this tutorial.
Why and when?
Sometimes you find yourselves with some time on your hand, a nice camera, a nice scene that would look nice in a time lapse movie, but no tripod and/or computer to take shots in exactly the same position in an exact time-sequence.
Just point the camera at what you want in your timelapse, and take shots, at regular intervals, as consistent in time delay and direction as you want/can.
You can play a sequence of jpgs using mplayer with:
mplayer -mf fps=12 mf://\*.jpg
If you put the shots together like this the image will bounce and shake a lot, because you didn't point the camera in exactly the same direction every time.... This is where tripods excel above humans.
So, hugin to the rescue!
preparing the images
First, I reduced the size of all the jpgs by a factor of 4 in each direction. This gave me frames of about video quality, greatly reducing the amount of CPU time required to process the many images.
mkdir small for i in *.jpg; do echo "$i " djpeg $i | pnmscale 0.25 | cjpeg > small/$i done cd small
Steps in hugin
I then started up hugin and loaded all the images.
Now to match all the images I have to do the control points manually, because this is not the "normal" use of hugin. However, for someone intimate with the workings of Hugin and the surrounding tools, it should be quite possible to modify one of the tools to allow doing this automatically in the future.
On the control-points tab, select image 0 on the left, and image 1 on the right. Now match two or three points in the image.
Next, you would normally match image 1 to image 2, and so on. In this case I recommend you match every image to image 0. So next you create several controlpoint matches on images 0 against image 2.
Next, I selected "equirectangular" for both the source images (under the "camera and lens" tab) and the destination (under the "stitcher" tab) (this may acutally not be the best selection, as hugin might also correct for lens distortion on the way. But at least it keeps things simple...)
Next, click "optimize now".
Next, I selected "high quality tiff" and "nona" as the stitcher. This triggers the creation of intermediate TIFF files which we're interested in.
Next click: "calculate field of view" in the stitcher tab, and "calculate optimal size".
Next, click "stitch now". In my case, the final enblend step crashed due to an installation error. This is ideal: We don't need it. Consider making the binary not executable for the duration of this project, or putting another program of the same name in your path, or configuring hugin to call some program that doesn't exist.
After entering the name "test.tif" as the output file, you will be left with realigned tiff files called test????.tif! You can then convert these to jpeg with:
for i in test????.tif ; do tifftopnm $i | cjpeg > $i.jpg done
now you can play them with:
mplayer -mf fps=12 mf://\test\*.tif.jpg
The bouncing should be greatly reduced!
This tutorial was written in a few minutes, while I had done this myself a few days earlier. So it might be slightly inaccurate in some points. If you find a problem, or for example a step I forgot to describe, please report it so that I can fix this tutorial.
The inline scripts in this page are written in "bash". If you use tcsh, the syntax is slightly different. If you're on MS Windows, I don't know how you achieve such operations.
This tutorial will be updated with the sample images and movies in a few days.
Todo for the programmers: Autopano should have "time lapse stabilizing" mode. This should, given a few control points on the first image try to find the same points on the other images. This should be alot faster than normal, as much less match candidates need comparing..... Or Hugin can aid by greatly reducing the number of clicks required by, in time-lapse mode, leaving the "left" control points in place when I click to the next image. And the right image can be auto-guessed, as just placing the control points in the same spot and then "auto fine-tune" should simply work!
If you add more control points than two per image-pair, the distortions of the lens might be corrected for as well. I haven't tried this yet.