Converting a cylindrical panorama to an equirectangular projectionWritten by Paul Bourke
See also: sphere2pano, convert an equirectangular projection to a cylindrical panorama 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.
The following describes a command line application that maps a cylindrical panorama into the correct location within an equirectangular projection. For a cylindrical panorama with a narrow vertical field of view it is sometimes acceptable to just letterbox the image to the 2:1 aspect ratio of the equirectangular. But for a correct mapping and in cases where the mapping needs to be correct irrespective of the vertical field of view, the mathematics of the mapping used here is required.Usage string
Usage: pano2sphere [options] imagefile Options -w n sets the output image size, default: input image width -a n sets antialiasing level, default: 2 -x n tilt camera, default: 0 -y n roll camera, default: 0 -z n pan camera, default: 0 -bg r g b a set background colour, default: grey or black for blending -d debug mode
As an example, consider the following cylindrical panorama.
The corresponding equirectangular image is:
The reason why letterboxing is not sufficient is because in an equirectangular projection the vertical axis scale is proportional to latitude. Whereas for a cylindrical panorama the vertical scale follows the same relationship to latitude as for a perspective projection, namely proportional the tan of the latitude. For example, the maximum latitude range is 180 degrees, the same limits as a perspective projection. Although in practice a cylindrical panorama becomes an inefficient projection above 140 degrees.
The vertical field of view of a cylindrical panorama can be calculated from the aspect ratio as follows, where H is height and W is width of the panorama.
In the above example the vertical field of view is almost 60 degrees, and so the panorama occupies about 1/3 of the vertical 180 degrees of the equirectangular. Whereas if the panorama was simply letterboxed to a 2:1 aspect then it would occupy a greater proportion of the vertical, and objects would appear stretched when viewed with software expecting an equirectangular.