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.

BUMP


Applies a hemispherical-like bump distortion to an image.

Download Script

last modified: December 15, 2018



USAGE: bump [-t type] [-a amplitude] [-r radius] [-c center] [-m] [-b bgcolor] infile outfile
USAGE: bump [-h or -help]

-t .... type ............. type of bump shaping; choices are:
.......................... 1=sinusoid, 2=triangle; 3=circular; default=1
-a .... amplitude ........ amplitude or elevation of the bump; float;
.......................... positive raises the bump; negative lowers
.......................... the depression; default=10
-r .... radius ........... radius from center point determines the extent of the bump;
.......................... integer>=0; default is half the minimum image dimension
-c .... center ........... center point for the bump; center=cx,cy;
.......................... integer>=0; default is center of image
-m ....................... mask the outside of the radius with background color
-b .... bgcolor .......... background color for the masked area outside the radius

PURPOSE: To apply a hemispherical-like bump distortion to an image.

DESCRIPTION: BUMP applies a hemispherical-like bump distortion to an image. The user can control the amplitude or height of the bump, the radius of the bump, the center point of the bump and the type of displacement profile used to control the shape of the bump. This is a simpler approximation of my bubblewarp script that is much faster due to the use of -distort polar/depolar and a displacement map.

ARGUMENTS:

-t type ... TYPE of displacement profile used to control the shape of the bump. Choices are: 1=sinusoid, 2=triangle; 3=circular; default=1

-a amplitude ... AMPLITUDE or elevation of the bump. Values are floats. Postive values raise the bump and negative values lower the elevation. A value of zero produces essentially no change. The default=10.

-r radius ... RADIUS is the radial distance from the center point which determines the extent of the bump. Values are integers>=0. The default is half the minimum dimension of the image.

-c center ... CENTER=cx,cy are the comma separated coordinates in the image determining the center of the bump. Values are integers>=0. The default is the center of the image.

-m ... Enables a mask around the bump that is set to the desired background color. This gives the result a spherical or bubble effect.

-b bgcolor ... BGOLOR is the color of the masked area outside the bump. Any valid IM color is allowed. See http://imagemagick.org/script/color.php The default=black.

NOTE: Requires IM 6.4.2-8 or higher due to the use of -distort polar/depolar.

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

NOTE: The radial formula has been corrected. But I have not modified the examples. So the radius of the effect may be slightly different if one repeats the examples.

Bump Higher

Original

Arguments:
-a 5

Arguments:
-a 10

Arguments:
-a 15

Arguments:
-a 20

Animation



Bump Higher With Mask --- Shape Type 1

Arguments:
-t 1 -a 0 -m

Arguments:
-t 1 -a 5 -m

Arguments:
-t 1 -a 10 -m

Arguments:
-t 1 -a 15 -m

Arguments:
-t 1 -a 20 -m

Animation



Bump Higher With Mask --- Shape Type 2

Arguments:
-t 2 -a 0 -m

Arguments:
-t 2 -a 5 -m

Arguments:
-t 2 -a 10 -m

Arguments:
-t 2 -a 15 -m

Arguments:
-t 2 -a 20 -m

Animation



Bump Higher With Mask --- Shape Type 3

Arguments:
-t 3 -a 0 -m

Arguments:
-t 3 -a 5 -m

Arguments:
-t 3 -a 10 -m

Arguments:
-t 3 -a 15 -m

Arguments:
-t 3 -a 20 -m

Animation



Depression Lower

Original

Arguments:
-a -5

Arguments:
-a -10

Arguments:
-a -15

Arguments:
-a -20

Animation



Depression Lower With Mask

Arguments:
-a 0 -m

Arguments:
-a -5 -m

Arguments:
-a -10 -m

Arguments:
-a -15 -m

Arguments:
-a -20 -m

Animation



Bump Higher

Original

Arguments:
-a 5 -c 75,75

Arguments:
-a 10 -c 75,75

Arguments:
-a 15 -c 75,75

Arguments:
-a 20 -c 75,75

Animation



Depression Lower

Original

Arguments:
-a -5 -c 75,75

Arguments:
-a -10 -c 75,75

Arguments:
-a -15 -c 75,75

Arguments:
-a -20 -c 75,75

Animation



Bump Wider

Original

Arguments:
-a 10 -r 30 -c 75,75

Arguments:
-a 10 -r 40 -c 75,75

Arguments:
-a 15 -r 60 -c 75,75

Arguments:
-a 20 -r 80 -c 75,75

Animation



Bump In Different Center Point Coordinates

Original

Forehead
Arguments:
-a 20 -r 60 -c 154,86

Eye
Arguments:
-a 20 -r 60 -c 130,109

Chin
Arguments:
-a 20 -r 60 -c 140,174

Nose Raised
Arguments:
-a 20 -r 60 -c 146,132

Nose Lowered
Arguments:
-a -20 -r 60 -c 146,132

Chest Lowered
Arguments:
-a -20 -r 120 -c 140,282



What the script does is as follows:

  • Converts image to polar coordinates
  • Creates a one column linear gradient and convert that to a negative half sinusoidal curve
  • Pads that to fill the height of the image and scales to fill the image width
  • Displaces the image vertically using the sinusoidal image
  • Converts back to rectangular coordinates

This is equivalent to the following IM commands

  • ww=`convert $infile -format "%[fx:w]" info:`
  • hh=`convert $infile -format "%[fx:h]" info:`
  • rad1=`convert $infile -format "%[fx:floor(2*$rad*h/sqrt(w*w+h*h))]" info:`
  • hmr=`convert xc: -format "%[fx:max(1,$hh-$rad1)]" info:`
  • hhh=`convert xc: -format "%[fx:$rad1+$hmr]" info:`
  • convert $infile -distort depolar -1,0,$cx,$cy $infile
  • convert -size 1x${rad1} gradient: -fx "0.5*sin(pi*u)+0.5" -negate $tmp1
  • convert $tmp1 \( -size 1x${hmr} xc:"gray(50%)" \) -append \
    -scale ${ww}x${hhh}! -crop ${ww}x${hh}+0+0 +repage $tmp1
  • composite $tmp1 $infile -displace 0x${amp} $infile
  • convert $infile -distort polar -1,0,$cx,$cy $outfile