Converting a cylindrical panorama to an equirectangular projectionWritten by Paul BourkeApril 2023 See also: sphere2pano, convert an equirectangular projection to a cylindrical panorama projection Update Oct 2024: Added support for other than 360 degree panoramas, and added ffmpeg remap filter export. 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 -fov n horizontal field of view, default: 360 -180 output only half the equirectangular, default: off -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 -f create PGM files for ffmpeg remap filter, default: off -d debug mode As an example, consider the following cylindrical panorama.
The corresponding equirectangular image is:
The reason why letter-boxing 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 letter-boxed 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. For a more complicated example, the following image is from one of the "panovu" multiple (4) cameras rigs from Hikvision. For reasons only known to them, they stitch the 4 cameras into a cylindrical panorama that is (approximately) 180 degrees horizontally and 90 degrees vertically. In this case the camera rig is additionally tilted by 45 degrees.
The image above correctly mapped into a much more useful equirectangular image is shown below.
The ultimate test is illustrated in this navigable version, all lines are straight. |