Wednesday, November 3, 2010

Converting an Equirectangular Panorama to Cubic Faces

I wanted to convert some equirectangular panoramas (spherical panoramas) to 6 cubic faces (see the images below for an example). After experimenting with various tools and trying out trial versions of various commercially available softwares that let you play around with panoramas, I finally found exactly what I wanted. It's free, open source, runs on the command line and works great. Its "Panotools" along with "Hugin". Here are the installation details and an example usage:

Step 1: Install Panotools

You can download the Panotools source from here:

http://search.cpan.org/~bpostle/Panotools-Script-0.25/

You can do a source installation. But, it is a real pain because Panotools requires other Perl modules and libraries and trying to install the required dependencies leads to further required dependencies...in short, a big mess.

So, the best way to install Panotools is through CPAN (Comprehensive Perl Archive Network). Here are the steps:

$ sudo cpan
cpan[1]> install Panotools::Script

Great! We are half way through.

Step 2: Install Hugin

The installation steps are given here in details:

http://wiki.panotools.org/Hugin_Compiling_ubuntu

If you want, you can read the above document for full details. But in short, the 3 commands below should get the job done.

$ sudo add-apt-repository ppa:hugin/hugin-builds
$ sudo apt-get update
$ sudo apt-get install hugin enblend autopano-sift panini

Done with all installations.

Example Usage:

The 2 commands that we will be using are: "erect2cubic" (which is a part of Panotools) and "nona" (which is a part of Hugin). You can read more about these commands in their man pages. Here is how you use these:

Here is the input image called "input.png":


Run the commands like this:

$ erect2cubic --erect=input.png --ptofile=cube.pto
$ nona -o cube_prefix cube.pto

The "erect2cubic" command will generate a .pto file, which is a Hugin project. The "nona" command takes the Hugin project file as input and generates the cubic face images.

Here are the generated 6 cubic faces:







Thats it folks :)