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

SPHERICALPANO2RECT


Generates a perspective (rectilinear) image from a region of a spherical panorama image.

Download Script

last modified: September 26, 2017



USAGE: sphericalpano2rect [-c coords] [-u units] [-f fov] [-m maxsize] [-b bgcolor] infile outfile USAGE: sphericalpano2rect [-h or -help]

-c ... coords .......... coordinates in the panorama image (cx,cy) to be used as the
........................ center of the output image; floats>=0; default=center of
........................ panorama
-u ... units ........... units for panorama coordinates: degrees or pixels; floats>=0;
........................ default=pixels
-f ... fov ............. field of view of the output image (xfov,yfov) in degrees;
........................ 0<floats<180; default=60,60
-m ... maxsize ......... maximum size of the output image in pixels corresponding to
........................ the larger field of view dimension; default=512
-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 generate a perspective (rectilinear) image from a region of a spherical panorama image.

DESCRIPTION: SPHERICALPANO2RECT generates a perspective (rectilinear) image from a region of a spherical panorama image. The region is identified by a point on the panorama image in pixels or degrees and the specified output field of view.

ARGUMENTS:

-c coords ... COORDS is the coordinates in the panorama image (cx,cy) to be used as the center of the output image (the look point). Values are floats>=0. The default=center of panorama. Two comma separated values are required, if provided.

-u units ... UNITS for specifying the look coordinates. Choices are degrees (d) or pixels (p). VAlues are floats>=0. The default=pixels.

-f fov ... FOV are the fields of view of the output image (xfov,yfov) in degrees. Values are 0<floats<180. The default="60,60". If only one value is supplied, it will be use for both dimensions. Smaller values zoom in (telephoto lens) and larger values zoom out (wide angle lens). For 35 mm film, a 50 mm focal length lens will have a diagonal field of view of about 47 degrees. Values larger than about 120 degrees for the field of view will show distortions.

-m maxsize ... MAXSIZE is the maximum size of the output image in pixels corresponding to the the larger field of view dimension. Values are integers>0. The default=512.

-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 about 10 sec to create a 512x512 perspective output starting from a 2000x1000 pixel spherical panorama. Processing time increases/decreases approximately with the square of the output dimension.

REFERENCES:
https://en.wikipedia.org/wiki/Perspective_projection_distortion
http://mathworld.wolfram.com/SphericalCoordinates.html
https://en.wikipedia.org/wiki/Field_of_view
https://www.nikonians.org/reviews/fov-tables
https://en.wikipedia.org/wiki/Angle_of_view

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 -- Different Locations

Original Image
( source)

(Click For Full Sized Image)
Arguments:
-c 180,90 -u degrees -f 60 -m 512
(defaults)
(center)
Arguments:
-c 0,90 -u degrees -f 60 -m 512
or
-c 360,90 -u degrees -f 60 -m 512
(vertical center; span left and right sides)
Arguments:
-c 180,30 -u degrees -f 60 -m 512
(top center)
Arguments:
-c 180,150 -u degrees -f 60 -m 512
(bottom center)
Arguments:
-c 780,520 -u pixels -f 60 -m 512
Arguments:
-c 1730x500 -u pixels -f 60 -m 512


Example 2 -- Different Fields Of View

Original Image
( source)

(Click For Full Sized Image)
Arguments:
-c 780,520 -u pixels -f 60,60 -m 512
Arguments:
-c 780,520 -u pixels -f 120,60 -m 1024
Arguments:
-c 780,520 -u pixels -f 60,120 -m 1024
Arguments:
-c 780,520 -u pixels -f 120,120 -m 1024
Arguments:
-c 780,520 -u pixels -f 150,150 -m 1024
Arguments:
-c 780,520 -u pixels -f 170,170 -m 1024


Example 3 -- Animation

Original Image
( source)

(Click For Full Sized Image)
Arguments:
phi=90 degrees
theta from 0 to 350 in 10 degree increments



What the script does is as follows:

  • Treats the spherical panorama as if wrapped around a sphere.
  • Puts a plane tangent to the sphere at the look point
    representing the perspective output image.
  • Sequences over the pixels in the perspective image.
  • Computes the theta and phi angles that project
    from the plane to the center of the sphere
  • Then finds the corresponding angular location on the sphere.
  • Then interpolates the pixels in the panorama and
    uses it for the given pixel in the perspective image.

See the script for mathematical and code details.