pondělí 31. ledna 2011

Stereo image alignment in Hugin

 Recently I played with stereoscopic images in Linux. First I tried to use Stereo Photo Maker in Wine, but there were some problems, namely the bad integration with scripts. In the end I decided to use Hugin. The difference from normal workflow is that the control points are added as "horizontal lines", so they are optimized only in vertical direction and the horizontal shift of the camera does not affect the optimization error.

The process described here works with Hugin 2010.4.0 with the patches from bug 679753 and 702135.

Simple usage

Let's start with two images taken from slightly different angle, named left.jpg and right.jpg:
left.jpg

right.jpg
The images are taken by hand and do not exactly match to each other so we have to rotate and crop them:


align_image_stack -p aligned.pto -a aligned -m -i -P -C right.jpg left.jpg

The newly added stereo options are:
-i optimize image center shift - this compensates the perspective distortion when the lens are not parallel.
-P align the "stereo window" and try to create  the "pop-out" effect
-C crop the images to the area covered by both images

The result can be converted for example to anaglyph:

composite -stereo 0 aligned0000.tif  aligned0001.tif  aligned.jpg

aligned.jpg


Interactive adjustment


When we don't like the result, we can open the pto file in hugin and modify it. For example we can improve the pop-out effect. 
On the photos you can see that the closest point is near the lower edge. The automatic process identified it as point 161 and marked it as the only "normal" point. After optimization, this points has zero shift between images and appears at screen level. The rest of the image appears behind it.




We can delete this point and choose another, in this case 137:


Then, after re-optimization, everything in front of point 137 will appear like popping out of the screen. There is still a problem with the lower edge where the stereo window is broken. We can fix it by crop:



Note: there is some problem with reading the optimization parameters into hugin, so for now it is necessary to add New Lens for the second image before running optimizer:




Finally, here is the result: