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

TOONIZARRO


Applies a Superman Bizarro-like cartoon effect to an image.

Download Script

file is missing or empty



USAGE: toonizarro [-f filter] [-s sigma] [-g gain] [-t thickness] [-l lothresh] [-h hithresh] infile outfile
USAGE: toonizarro [-help]

-f ... filter ...... filter to adjust the coarseness; integer>0; default=3
-s ... sigma ....... unsharpening sigma; float>0
-g ... gain ........ unsharpening gain; float>=0; default=4
-t ... thickness ... edge thickness; integer>=0; default=0 means no edges
-l ... lothresh .... canny edge detection low threshold; integer>=0; default=20
-h ... hithresh .... canny edge detection high threshold; integer>=0; default=50
-c ... colors ...... color list for colorizing the result; any space-separate list
.................... of valid IM colors allowed; default is no colorization

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

DESCRIPTION: TOONIZARRO applies a Superman Bizarro-like cartoon effect to an image. Edges may be added optionally.

ARGUMENTS:

-f filter ... FILTER to adjust the coarseness. Values are integers>0. The default=3.

-s sigma ... SIGMA for unsharpening. Values are float>0. The default=2

-g gain ... GAIN for unsharpening. Values are float>=0. The default=4.

-t thickness ... THICKNESS of edges. Values are integers>=0. The default=0 means no edges.

-l lothresh ... LOTHRESHOLD is the canny edge detection low threshold. Values are integers>=0. The default=20.

-l hithresh ... HITHRESHOLD is the canny edge detection high threshold. Values are integers>=0. The default=40.

-c colors ... COLORS is a list of colors for colorizing the result. Any space-separate list of valid IM colors is allowed. (No spaces withing rgb color triples). The default is no colorization.

REQUIREMENTS: IM 6.8.9.9 due to the use of the Kuwahara filter. IM 6.8.9-0 to use the Canny edge detection. See:
http://www.imagemagick.org/discourse-server/viewtopic.php?f=4&t=26480
http://www.imagemagick.org/discourse-server/viewtopic.php?f=4&t=25405

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 Filter And Edge Thickness

Original
(source)

Arguments:
-f 1 -t 0

Arguments:
-f 1 -t 1

Arguments:
-f 1 -t 2

Arguments:
-f 2 -t 0

Arguments:
-f 2 -t 1

Arguments:
-f 2 -t 2

Arguments:
-f 3 -t 0

Arguments:
-f 3 -t 1

Arguments:
-f 3 -t 2

Arguments:
-f 4 -t 0

Arguments:
-f 4 -t 1

Arguments:
-f 4 -t 2



Example 2

Original

Arguments:
-f 3 -t 0

Arguments:
-f 3 -t 1

Arguments:
-f 3 -t 2



Example 3

Original
(source)

Arguments:
-f 3 -t 0

Arguments:
-f 3 -t 1

Arguments:
-f 3 -t 2



Example 4

Original
(source)

Arguments:
-f 3 -t 0

Arguments:
-f 3 -t 1

Arguments:
-f 3 -t 2



Example 5

Original
(source)

Arguments:
-f 1 -t 0

Arguments:
-f 3 -t 0

Arguments:
-f 5 -t 0



Example 6 -- Colorization

Original
(source)

Arguments:
-f 3 -t 2 -c "blue yellow red"



Example 7 -- Colorization

Original
(source)

Arguments:
-f 3 -t 2 -c "blue yellow red"



What the script does is as follows:

  • Applies Kuwahara smoothing filter
  • Applies unsharp masking to sharpen the image
  • Optionally applies Canny Edge detection and overlays edges on image

This is equivalent to the following IM commands

  • convert -quiet "$infile" +repage $tmpA1
  • if [ $thickness -gt 1 ]; then
    amt=$((thickness-1))
    thickening="-morphology dilate diamond:$amt"
    else
    thickening=""
    fi
  • if [ $thickness -eq 0 ]; then
    convert $tmpA1 -kuwahara $filter -unsharp 0x${sigma}+${gain}+0 "$outfile"
    else
    convert $tmpA1 -kuwahara $filter -unsharp 0x${sigma}+${gain}+0 \
    \( -clone 0 -colorspace gray -canny 0x${thickness}+${lothresh}%+${hithresh}% \
    $thickening +write tmp1.png -negate \) \
    \( -clone 1 -negate \) \
    -compose over -composite "$outfile" fi