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:

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 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:

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 :)


  1. thanks man! all the searching paid off. I owe you one.

  2. ok, is there cubic2erect or some other way to convert it from cubic to equirectangular?

    1. You can do it in PTGUI. Manually or there is a droplet that does a 6 inline cube to Equirect

  3. yes, cubic2erect does also exist, see

  4. great just the kind of info i needed.
    i am trying to make a hi res photographic map of the night sky, have done about 60% percent.
    Will put text/gfx for Hindu Nakshtra(Moon Mansions).
    will ask u some stuff. techie.
    btw. I am a video editor n a photog

  5. fyi ,
    if anyone is looking for a script to automate a batch conversion

    #compensate spaces in name
    IFS=$(echo -en "\n\b")
    #file list
    for f in $FILES
    echo "------------------------------------------------"
    echo "Processing $f file.."starting ... $((i++))"
    rect2cubic --erect=$f --ptofile=cube$i.pto
    nona -o cube00$i cube$i.pto

  6. for f in *.tif; do echo "Converting $f"; convert "$f" "$(basename "$f" .tif).jpg"; done
    will convert the generated files to jpg