Fred's ImageMagick Scripts



    Licensing:

    Copyright © Fred Weinhaus

    My scripts are available free of charge for non-commercial (non-profit) 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

    Please read the Pointers For Use on my home page to properly install and customize my scripts.

PANO2FISHEYE


Transforms a spherical panorama to a fisheye view.

Download Script

last modified: December 15, 2018



USAGE: pano2fisheye [-p projection] [-v viewtype] [-d dimension] [-b bgcolor] [-f fade] [-s smooth] [-n newseed] infile outfile
USAGE: pano2fisheye [-h or -help]

-p ... projection ... fisheye projection type: choices are linear, stereographic, or
..................... orthographic; default=linear
-v ... viewtype ..... type of view; choices are: planet or manhole; planet is a view
..................... looking down from the sky; manhole is a view from the ground up;
..................... default=planet
-d ... dimension .... square dimension of output; integer>0; default is the height
..................... of the input
-b ... bgcolor ...... bgcolor is the color for the area outside the
..................... circle of the fisheye area; any valid IM color is permitted or
..................... the special name of "stars" to create a black background with
..................... random point star field; use none to make the background
..................... transparent; default=white
-f ... fade ......... amount of fade in pixels between the image and background color
..................... at the top of the image for viewtype=planet; integer>=0;
..................... default=0
-s ... smooth ....... amount of smoothing for antialiasing when bgcolor=none;
..................... float>=0; default=0
-n ... newseed ...... random seed for creating the star field when bgcolor=stars

PURPOSE: To transforms a spherical panorama to a fisheye view.

DESCRIPTION: FISHEYE is designed to transform a spherical (equirectangular) panorama to a fisheye view. There are 3 choices for the fisheye format: linear, stereographics and orthographic. The spherical (equirectangular) panorama's pixels represent x=longitude and y=latitude. That is, both x and y are angular units. Longitude corresponds to 360 degree range. Thus the left and right sides must wrap contiguously. Thus a width to height aspect of 2:1. An image can be faked by cropping to w/h aspect of 2:1 (width is twice the height), then mirroring it horizontally, appending horizontally, then cropping the center half and rolling it horizontally 50%.

ARGUMENTS:

-p projection ... PROJECTION is the fisheye projection type. Choices are linear (l), stereographic (s), or orthographic (o). The default=linear.

-v viewtype ... VIEWTYPE is the type of view. Choices are: planet (p) or manhole (m). The choice of planet is a view looking down from the sky. The choice of manhole is a view from the ground up. The default=planet.

-d dimension ... DIMENSION is the square dimension of output image. Values are integers>0. The default is the height of the input.

-b bgcolor ... BGCOLOR is the color for the area outside the circle of the fisheye region. Any valid IM color is permitted or the special name of "stars" to create a black background with random point star field. Use "none" to make the background transparent. The default=white.

-f fade ... FADE is the amount of fade in pixels between the top of the input image and background color for viewtype=planet. This is a preprocessing step so that the outside of the fisheye circular region will fade to the background color. Values are integers>=0. The default=0.

-s smooth ... SMOOTH is the amount of smoothing for antialiasing when bgcolor=none or stars. Values are float>=0. The default=0.

-n newseed .. .NEWSEED is the random seed for creating the star field when bgcolor=stars. Values are integers>=0. The default is totally random star placement from run-to-run.

REFERENCES:
http://en.wikipedia.org/wiki/Fisheye_lens
http://www.bobatkins.com/photography/technical/field_of_view.html
http://www.photographymad.com/pages/view/little-planet-photos-5-simple-steps-to-making-panorama-worlds

NOTE: This script will be slow due to the use of -fx.

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 - Variation Of Projection For Viewtype=planet

Original Image
(source)

Arguments:
-p linear
Arguments:
-p stereographic
Arguments:
-p orthographic


Example 2 - Variation Of Projection For Viewtype=manhole

Original Image
(source)

Arguments:
-p linear
Arguments:
-p stereographic
Arguments:
-p orthographic


Example 3 - Viewtype=planet With Color Fade

Original Image
(source)

Arguments:
-p linear -b #B4F2FE -f 100


Example 4 - Viewtype=planet With Stars

Original Image
(source)

Arguments:
-p linear -b stars


Example 5 - Viewtype=planet Composited On Background Image

Original Image
(source)

Background Image
(source)

Arguments:
-p linear -b none -s 2 -d 200
Compositing
convert nebula_small.jpg \
417327148_158bf17bf1_o_pano2fisheye_linear_planet_none_s2_f0_d200.png \
-gravity +430+195 -compose over -composite nebula_tiny_planet.jpg


Example 5 - Viewtype=planet Pseudo Panorama

Original Image
(source)

Pre-Processing

Mirror, Append, Crop Middle Half, Roll 50% Horizontally

convert depositphotos_13509141-stock-photo-panoramic-view-of-a-disney.jpg \
\( -clone 0 -flop \) +append \
-gravity center -crop 1024x517+0+0 +repage \
-roll +50%+0% \
disneyland_aspect2to1.png

Arguments:
-p linear -b #55B0F1 -f 20


What the script does is as follows:

  • Starts with a spherical panorama (equirectangular) image
  • Transforms it to one a 3 types of fisheye projections

This is equivalent to the following IM commands for the case of a linear fisheye.

  • ww=`convert -ping "$infile" -format "%w" info:`
  • hh=`convert -ping "$infile" -format "%h" info:`
  • ww2=`convert xc: -format "%[fx:floor($ww/2)-1]" info:`
  • hh2=`convert xc: -format "%[fx:floor($hh/2)-1]" info:`
  • wd=$hh
  • ht=$hh
  • xcd=`convert xc: -format "%[fx:floor($wd/2)-1]" info:`
  • ycd=`convert xc: -format "%[fx:floor($ht/2)-1]" info:`
  • px_per_theta=`convert xc: -format "%[fx:$ww/(2*pi)]" info:`
  • px_per_phi=`convert xc: -format "%[fx:$hh/(pi/2)]" info:`
  • xd="xd=(i-$xcd);"
  • yd="yd=(j-$ycd);"
  • rd="rd=hypot(xd,yd);"
  • theta="theta=atan2(yd,xd);"
  • rad_per_px=`convert xc: -format "%[fx:pi/$hh]" info:`
  • phiang="phiang=$rad_per_px*rd;"
  • xs="xs=$ww2+theta*$px_per_theta;"
  • ys="ys=$hh-phiang*$px_per_phi;"
  • convert -size ${wd}x${ht} xc: "$infile" -virtual-pixel background -background $bcolor \
    -monitor -fx \
    "$xd $yd $rd $theta $phiang $xs $ys (rd>$hh2)?$bcolor:v.p{xs,ys}" +monitor \
    -rotate -90 \
    "$outfile"