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

10 comments:

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

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

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

      Delete
  3. yes, cubic2erect does also exist, see
    http://wiki.panotools.org/Panorama_scripting_in_a_nutshell

    ReplyDelete
  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

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

    #!/bin/bash
    #compensate spaces in name
    SAVEIFS=$IFS
    IFS=$(echo -en "\n\b")
    #file list
    FILES=/path/to/*.jpg
    i=0
    for f in $FILES
    do
    echo "------------------------------------------------"
    echo "Processing $f file.."starting ... $((i++))"
    rect2cubic --erect=$f --ptofile=cube$i.pto
    nona -o cube00$i cube$i.pto
    done
    IFS=$SAVEIFS

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

    ReplyDelete
  7. राकेश गौतम

    ReplyDelete