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.

TURBULENCE


Applies a turbulence-like warping of the image.

Download Script

last modified: December 16, 2018



USAGE: turbulence [-m method] [-d distance] [-s smooth] [-c channels] [-v vpmethod] [-b bgcolor] infile outfile
USAGE: turbulence [-h or -help]

-m ... method ..... method of turbulence warping; choices are: displace or distort;
................... default=displace
-d ... distance ... distance amount for turbulence warping; comma separate pair of
................... integers>=0 for x and y distiance; default=20
-s ... smooth ..... smoothing amount of turbulence warping; integer>=0; default=20
-c ... channels ... channel processing; choices are: together or separate;
................... default=together
-v ... vpmethod ... virtual pixel method; any valid IM virtual-pixel method may be
................... specified; default=mirror
-b ... bgcolor .... background color when virtual pixel method is background;
................... any valid IM color may be specified; default=black

PURPOSE: To apply a turbulence-like warping of the image.

DESCRIPTION: TURBULENCE applies a turbulence-like warping of the image. The warping is done via a displacement/distortion mapping from an edge extracted version of the input image. Using channels=together will warp all channels the same. Using channels=separate will warp each channel separately.

ARGUMENTS:

-m method ... METHOD of turbulence warping. The choices are: displace or distort. The default=displace.

-d distance ... DISTANCE amounts for x and y turbulence warping. Values are a comma separated pair of integers>=0. If only one value is supplied, then it will be use for both x and y distances. The default=20.

-s smooth ... SMOOTH is the smoothing amount of turbulence warping. Values are integers>=0. The default=20.

-c channels ... CHANNELS is the channel processing technique. The choices are: together (t) or separate (s). The default=together.

-v vpmethod ... VPMETHOD is the virtual pixel method. Any valid IM virtual-pixel method may be specified. The default=mirror.

-b bgcolor ... BGCOLOR is the background color when virtual pixel method is background. Any valid IM color may be specified. The default=black.

REQUIREMENTS: IM 6.5.3-5 or higher when using method=distort.

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 in Smooth
(source)

Original

Arguments:
-s 20 -d 20
(default)

Arguments:
-s 10 -d 20

Arguments:
-s 5 -d 10

Arguments:
-s 2 -d 20



Example 2 -- Variation in Distance
(source)

Original

Arguments:
-s 20 -d 20
(default)

Arguments:
-s 20 -d 50

Arguments:
-s 20 -d 100

Arguments:
-s 20 -d 20



Example 3

Original

Arguments:
-s 20 -d 20
(default)

Arguments:
-s 20 -d 50

Arguments:
-s 20 -d 100

Arguments:
-s 20 -d 200

Arguments:
-s 20 -d 300

Arguments:
-s 20 -d 500

Arguments:
-s 30 -d 150

Arguments:
-s 50 -d 300



Example 4

Original

Arguments:
-s 20 -d 20
(default)

Arguments:
-s 20 -d 50

Arguments:
-s 20 -d 100

Arguments:
-s 20 -d 500

Arguments:
-s 50 -d 50

Arguments:
-s 50 -d 200



Example 5 - Displace: Together vs. Separate

Original
(source)

Arguments:
-s 20 -d 20 -c together

Arguments:
-s 20 -d 20 -c separate

Arguments:
-s 20 -d 20 -c together

Arguments:
-s 20 -d 20 -c separate

Arguments:
-s 20 -d 50 -c together

Arguments:
-s 20 -d 50 -c separate

Arguments:
-s 20 -d 200 -c together

Arguments:
-s 20 -d 200 -c separate

Arguments:
-s 20 -d 500 -c together

Arguments:
-s 20 -d 500 -c separate



Example 6 - Distort: Together vs. Separate

Original
(source)

Arguments:
-s 10 -d 50 -c together

Arguments:
-s 10 -d 50 -c separate

Arguments:
-s 10 -d 500 -c together

Arguments:
-s 10 -d 500 -c separate

Arguments:
-s 20 -d 50 -c together

Arguments:
-s 20 -d 50 -c separate

Arguments:
-s 20 -d 500 -c together

Arguments:
-s 20 -d 500 -c separate



What the script does is as follows:

  • Applies Sobel edge extraction on the image
  • Uses the edge image as either a diplacement map or a distortion map
  • Applies the distortion map to the image to warp it

This is equivalent to the following IM commands for the case of channels=together

  • convert -quiet -regard-warnings "$infile" +repage $tmpA1
  • distx=`echo "$distance" | cut -d, -f1`
  • disty=`echo "$distance" | cut -d, -f2`
  • distx=-$distx
  • disty=-$disty
  • convert $tmpA1 \
    \( -clone 0 -define convolve:scale='50%!' -bias 50% \
    -morphology Convolve Sobel -colorspace gray -blur 0x$smooth -auto-level \) \
    -virtual-pixel $vpmethod -background "$bgcolor" -define compose:args="$distx,$disty" \
    -compose $method -composite "$outfile"