Fred's ImageMagick Scripts



    Licensing:

    Copyright © Fred Weinhaus

    My scripts are available free of charge for non-commercial use, ONLY.

    For use of my scripts in commercial (for-profit) environments or non-free applications, please contact me (Fred Weinhaus) for licensing arrangements. My email address is fmw at alink dot net.

    If you: 1) redistribute, 2) incorporate any of these scripts into other free applications or 3) reprogram them in another scripting language, then you must contact me for permission, especially if the result might be used in a commercial or for-profit environment.

    Usage, whether stated or not in the script, is restricted to the above licensing arrangements. It is also subject, in a subordinate manner, to the ImageMagick license, which can be found at: http://www.imagemagick.org/script/license.php

CUBE2SPHERICALPANO


Transforms 6 cube face images into a spherical panorama image.

Download Script

last modified: September 26, 2017



USAGE: cube2sphericalpano [-d dimensions] [-t tilesize] [-b bgcolor ] [-i interpolation] infile1 infile2 infile3 infile4 infile5 infile6 outfile
USAGE: cube2sphericalpano [-d dimensions] [-t tilesize] [-b bcolor ] [-i interpolation] infile outfile
USAGE: cube2sphericalpano [-h or -help]

-d ... dimensions ...... dimensions of the output panorama; WxH; integers>0;
........................ default=1000x500
-t ... tilesize ........ size of square face tiles in optional single montage image;
........................ default will be computed from the montage input image
........................ dimensions; provided only to override erroneous fractional
........................ dimensions computed from the montage image
-b ... bgcolor ......... background color for virtual pixels; any valid IM color is
........................ allowed; default=black
-i ... interpolation ... intepolation method; any valid IM interpolation method is
........................ allowed; default=bilinear

PURPOSE: To transform 6 cube face images into a spherical panorama image.

DESCRIPTION: CUBE2SPHERICALPANO transforms either 1) six cube face images in order of left, front, right, back, over, under into a spherical panorama or 2) one montage of the six cube face images into a spherical panorama. The over and under images must be as if facing forward and turning up and down, respectively. If not in that orientation, then you must rotate them 90, 180, 270 as needed to orient them as needed.

ARGUMENTS:

-d dimensions ... DIMENSIONS of the output panorama as WxH. Values are integers>0. The default=1000x500.

-t tilesize ... TILESIZE is the size of the square face tile in the optional single montage input image. The default will be computed from the montage input image dimensions as tile_width=montage_width/4 and tile_height=montage_height/3. This is provided only to override erroneous rounding of any fractional pixel dimensions computed from the montage image.

-b bgcolor ... BGCOLOR is the background color for virtual pixels. Any valid IM color is allowed. The default=black.

-i interpolation ... INTEPOLATION method. Any valid IM interpolation method is allowed. The default=bilinear.

NOTE: This script will be slow due to the use of -fx. On my dual core INTEL Mac mini with 2.8 GHz processor and OSX Sierra, it takes 1 min 40 sec to create a 1000x500 pixel spherical panorama from six 500x500 pixel cube face images. Time will increase/decrease approximately by the square of the panorama dimensions.

References: https://en.wikipedia.org/wiki/Cube_mapping http://paulbourke.net//miscellaneous/cubemaps/ https://stackoverflow.com/questions/29678510/convert-21-equirectangular-panorama-to-cube-map http://mathworld.wolfram.com/SphericalCoordinates.html

CAVEAT: No guarantee that this script will work on all platforms, nor that trapping of inconsistent parameters is complete and foolproof. Use At Your Own Risk.


EXAMPLES


Example 1

Original Spherical Panorama Image
( source)

(Click For Full Sized Image)

Six Input Images Created From My Script Sphericalpano2cube

Left
Front
Right
Back
Over
under

Arguments:
-d 2000x1000

(Click For Full Sized Image)


Example 2

Original Spherical Panorama Image
( source)

(Click For Full Sized Image)

Montage Input Images Created From My Script Sphericalpano2cube

(Click For Full Sized Image)

Arguments:
-d 2000x1000

(Click For Full Sized Image)


What the script does is as follows:

  • Treats the output spherical panorama as if wrapped around a sphere.
  • Encloses the sphere in a cube whose 6 faces are the 6 input images
  • Sequences over the pixels in the spherical panorama image.
  • Then finds the appropriate cube face from the panorama angles
    corresponding the the given pixel.
  • The interpolates the pixels in the cube face image and
    uses it for the given pixel in the panorama.

See the script for mathematical and code details.