Converting an equirectangular image to a cylindrical panoramic projection

Written by Paul Bourke
November 2010
Update (Aug 2018): Added panoramic vertical shifting
Update (March 2023): Add remap filters for ffmpeg
Update (March 2025): persp2pano - Mapping a perspective image into a cylindrical panorama

See also: sphere2fish to convert an equirectangular projection to a fisheye projection
and sphere2persp to convert an equirectangular projection to a perspective projection

The source code implementing the projections below is only available on request for a small fee. It includes an invitation to convert an image of your choice to verify the code does what you seek. For more information please contact the author.


In what follows I describe software for extracting a cylindrical panorama from an equirectangular (spherical) projection. There are various reasons why one might want to do this, the driver here is creating images for large scale cylindrical displays. Diagrammatically, for some displays and 360 cameras used by the author this diagram illustrates the geometry.

Usage string

sphere2pano [options] sphericalimagename
Options:
   -t n   vertical FOV of panoramic, 0...180 (default: 60)
   -a n   set antialias level, 1, 2 or 3 typical (default: 2)
   -w n   width of the output panorama image (default: 2048)
   -o s   output file name (default: determined internally)
   -x n   tilt angle (degrees), default: 0
   -y n   roll angle (degrees), default: 0
   -z n   pan angle (degrees), default: 0
   -l     flip in longitude (default: off)
   -f     create remap filters for ffmpeg (default: off)
   -d     enable verbose debugging mode

Like an equirectangular projection, the horizontal axis of a cylindrical panorama is equal steps of longitude. However the vertical axis resembles a perspective projection. As such, while an equirectangular can represent from -90 to 90 degrees in latitude, a cylindrical panorama becomes increasingly inefficient after about 140 degrees vertical field of view (FOV).

The following equirectangular will be used to illustrate the basic transformations.

The following is a 45 degree vertical FOV.


sphere2pano -w 4096 sample.jpg

The following is a 70 degree vertical FOV.


sphere2pano -w 4096 -t 70 sample.jpg

As is usual with such mapping the process is performed in reverse, that is, one considers each pixel in the output cylindrical panorama and computes the best estimate in the input image, the equirectangular in this case. Antialiasing is performed here using a straightforward supersampling of each output pixel.


persp2pano - Mapping a perspective image into a cylindrical panorama

Written by Paul Bourke
March 2025


A few useful relationships when dealing with perspective frames and cylindrical panoramas, specifically how to determine the relationships between the vertical fields of view. Firstly, given a cylindrical display that is 360 degrees around, radius R and height H, the vertical field of view Vfov is given by

Given a perspective projection or width W, height H, the relationship between the horizontal and vertical field of view is

As an example, consider the following perspective image.

Mapped into a full 360 degree cylindrical panorama.

Usage: persp2pano [options] imagefile
Options
   -w n    The panorama image size, default: 4 * perspective image width
           The panorama vertical size will be calculated based upon vertical FOV
   -a n    Antialiasing level, default: 2
   -s n    Vertical fov (degrees) of panorama, default: 60
   -t n    Horizontal fov (degrees) of perspective image, default: 100
   -l n n  Longitude range, default: 0 to 360
           Values can exceed 360 if zero crossing required
   -x n    Tilt camera, default: 0
   -y n    Roll camera, default: 0
   -z n    Pan camera, default: 0
   -o      Save warp mesh as OBJ file for Unityi, default: false
   -d      Debug/verbose mode

For a more details and precise example, consider the following perspective projection of lines of longitude and latitude on a sphere. The horizontal field of view is 90 degrees and the vertical 50 degrees. Each line is 5 degrees apart, vertically and horizontally.

This is to be mapped into 1/4 of a cylinder with a vertical field of view of 36.5 degrees.

As expected, the lines of latitude and longitude are now straight.


Older version: Convert spherical projections to cylindrical projection

Historical interest only
Written by Paul Bourke
February 2006


The following utility was written to convert spherical projections into cylindrical projections. Of course only a slice of the spherical projection is used. The original reason for developing this was to convert video content from the LadyBug-3 camera (spherical projection) to a suitable image for a 360 cylindrical display. This a command line utility and as such straightforward to script to convert sequences of frames that make up a movie.

sph2pan [options] sphericalimagename
Options:
-t n       set max theta on vertical axis of panoramic, 0...90 (default: 45)
-a n       set antialias level, 1 upwards, 2 or 3 typical (default: 2)
-w n       width of the spherical image
-r n       horizontal rotation angle (default: 0)
-v n       vertical rotation angle (default: 0)
-f         flip insideout (default: off)

Sample spherical projection (from the LadyBug-3)


Click for original image (5400x2700 pixels).

As with all such image transformations, one considers a point in the destination image noting that the point may be a sub pixel (required for supersampling antialiasing). This point corresponds to a vector in 3D space, this is then used to determine the corresponding point in the input image. Options such as rotations and flips correspond to operations on the 3D vector.

Sample derived cylindrical projections

The following show example transformations illustrating some of the more important options. In particular the ability to specify the vertical field of view and the vertical offset for the cylindrical image.


sph2pan -w 800 -v -7.5 dervish_sph.tga


sph2pan -w 800 -v -7.5 -t 60 dervish_sph.tga


sph2pan -w 800 -v -7.5 -t 60 -r 90 dervish_sph.tga