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

TOON


Applies a cartoon effect to an image.

Download Script

last modified: June 21, 2017



USAGE: toon [-m method] [-g gain] [-b blur] [-s saturation] [-B brightness] [-S smoothing] infile outfile
USAGE: toon [-help]

-m ... method ....... method=1 or 2; default=1
-g ... gain ......... edge gain (i.e. strength); float>=0; default=5
-c ... compose ...... optional compose type for method=1; default no compose
-b ... blur ......... blur amount for method=2; float>=0; default=5
-s ... saturation ... color saturation; integer>=0; default=100 (no change)
-B ... brightness ... brightness; integer>>=0; default=100 (no change)
-S ... smoothing .... smoothing; 0<=integer<=100; default=0 for method=1
..................... and default=30 for method=2

PURPOSE: To apply a cartoon-like effect to an image.

DESCRIPTION: EDGEFX applies a cartoon-like effect to an image.

ARGUMENTS:

-g gain ... GAIN is the edge gain (i.e. strength or intensity). Values are floats>=0. The default=5.

-m method ... METHOD. The choices are: 1 or 2. The default=1.

-c compose ... optional COMPOSE type for method=1. The choices are: overlay, multiply, bumpmap, hardlight, softlight, pegtoplight, pinlight, linearlight, vividlight, linearburn, colorburn. The default is no compose.

-b blur ... BLUR amount for method=2. Values are floats>=0. The default=5.

-s saturation ... color SATURATION. Values are integers>=0. The default=100 (no change). 0 is grayscale and 200 is twice the saturation

-B brightness ... BRIGHTNESS. Values are integers>=0. The default=100 (no change).

-S smoothing ... SMOOTHING. Values are 0<=integer<=100. The default=0 for method=1 and the default=30 for method=2.

REQUIREMENTS: IM 6.6.2.2 due to the use of rotated kernels in -morphology convolve.

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 Method
(source)

Original

Arguments:
-m 1

Arguments:
-m 2



Example 2 -- Variation in Method
(source)

Original

Arguments:
-m 1

Arguments:
-m 2



Example 3 -- Variation in Method
(source)

Original

Arguments:
-m 1

Arguments:
-m 2



Example 4 -- Variation in Smoothing for Method 1
(source)

Original

Arguments:
-m 1 -S 0

Arguments:
-m 1 -S 5

Arguments:
-m 1 -S 10



Example 5 -- Variation in Smoothing for Method 2
(source)

Original

Arguments:
-m 2 -S 10

Arguments:
-m 2 -S 20

Arguments:
-m 2 -S 30



Example 6 -- Variation in Compose for Method 1
(source)

Original

Arguments:
-m 1

Arguments:
-m 1 -c hardlight

Arguments:
-m 1 -c pinlight

Arguments:
-m 1 -c softlight

Arguments:
-m 1 -c pegtoplight

Arguments:
-m 1 -c overlay

Arguments:
-m 1 -c linearlight

Arguments:
-m 1 -c vividlight

Arguments:
-m 1 -c bumpmap

Arguments:
-m 1 -c multiply

Arguments:
-m 1 -c linearburn

Arguments:
-m 1 -c colorburn



What the script does is as follows for method 1:

  • Applies 8-directional Sobel edge extraction
  • Negates the edge extracted image
  • Applies a power to the image to stregthen the extracted edges
  • Applies sigmoidal contrast to increase smoothing
  • Colorize composes the edge image with the original

This is equivalent to the following IM commands

  • convert -quiet "$infile" +repage $dir/tmpI.mpc
  • if [ "$saturation" != "100" -o "$brightness" != "100" ]; then
    modulating="-modulate $brightness,$saturation,100"
    else
    modulating=""
    fi
  • if [ "$smoothing" = "" -a $method -eq 1 ]; then
    smoothing=0
    elif [ "$smoothing" = "" -a $method -eq 2 ]; then
    smoothing=30
    fi
  • convert $dir/tmpI.mpc \
    \( -clone 0 -colorspace gray -define convolve:scale='!' \
    -define morphology:compose=Lighten \
    -morphology Convolve 'Sobel:>' \
    -negate -evaluate pow $gain -sigmoidal-contrast $smoothing,50% \) \
    +swap -compose colorize -composite \
    $modulating \
    "$outfile"