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

SKETCHER


Applies a sketch effect to an image.

Download Script

last modified: June 27, 2017



USAGE: sketcher [-g gain] [-m method] [-s saturation] [-h hue] [-t thicken] infile outfile
USAGE: sketcher [-help]

-g ... gain ......... edge gain (i.e. strength); float>=0; default=5
-m ... method ....... sketch method; choices are: grayscale, color, screen,
..................... softlight, pegtoplight, hardlight, linearlight, and
..................... vividlight; default=grayscale
-s ... saturation ... color saturation; integer>=0; default=100 (no change).
-h ... hue .......... color hue; integer>=0; default=100 (no change).
-t ... thicken ...... thickening of edges; integer>=0; default=0

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

DESCRIPTION: SKETCHER applies a variety of sketch-like effects 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 of sketch. The choices are: grayscale, color, screen, softlight, pegtoplight, hardlight, linearlight, and vividlight. The default is grayscale.

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

-h hue ... color HUE. Values are integers>=0. The default=100 (no change). 0 is negative 180 degree rotation (toward blue). 200 is positive 180 degree rotation (toward green).

-t thicken ... THICKEN amount for edges. Values are integers>=0. The default=0 (no thickening).

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 grayscale

Arguments:
-m color

Arguments:
-m screen

Arguments:
-m softlight

Arguments:
-m pegtoplight

Arguments:
-m hardlight

Arguments:
-m linearlight

Arguments:
-m vividlight



Example 2 -- Variation in Method
(source)

Original

Arguments:
-m grayscale

Arguments:
-m color

Arguments:
-m screen

Arguments:
-m softlight

Arguments:
-m pegtoplight

Arguments:
-m hardlight

Arguments:
-m linearlight

Arguments:
-m vividlight



Example 3 -- Variation in Method
(source)

Original

Arguments:
-m grayscale

Arguments:
-m color

Arguments:
-m screen

Arguments:
-m softlight

Arguments:
-m pegtoplight

Arguments:
-m hardlight

Arguments:
-m linearlight

Arguments:
-m vividlight



Example 4 -- Variation in Gain
(source)

Original

Arguments:
-m grayscale -g 1

Arguments:
-m grayscale -g 5

Arguments:
-m grayscale -g 10



Example 5 -- Variation in Thickening
(source)

Original

Arguments:
-m grayscale -t 0

Arguments:
-m grayscale -t 1

Arguments:
-m grayscale -t 2

Arguments:
-m grayscale -t 3



Example 6 -- Variation in Thickening
(source)

Original

Arguments:
-m hardlight -t 0

Arguments:
-m hardlight -t 1

Arguments:
-m hardlight -t 2

Arguments:
-m hardlight -t 3



Example 7 -- Variation in Hue
(source)

Original

Arguments:
-m hardlight -h 50

Arguments:
-m hardlight -h 100

Arguments:
-m hardlight -h 150



What the script does is as follows:

  • Applies 8-directional Sobel edge extraction
  • Negates the edge extracted image
  • Applies a power to the image to stregthen the extracted edges
  • Composes the edge image with the original

This is equivalent to the following IM commands

  • convert -quiet "$infile" +repage $dir/tmpI.mpc
  • if [ "$method" = "softlight" -o "$method" = "pegtoplight" ]; then
    swapping="+swap"
    else
    swapping=""
    fi
  • if [ "$method" = "grayscale" ]; then
    graying="-colorspace gray"
    else
    graying=""
    fi
  • if [ "$method" = "grayscale" -o "$method" = "color" ]; then
    composing=""
    deleting="-delete 0"
    else
    composing="-compose $method -composite"
    deleting=""
    fi
  • if [ "$saturation" != "100" -o "$hue" != "100" ]; then
    modulating="-modulate 100,$saturation,$hue"
    else
    modulating=""
    fi
  • if [ "$thicken" != "0" ]; then
    thickening="-morphology dilate octagon:$thicken"
    else
    thickening=""
    fi
  • convert $dir/tmpI.mpc $graying \
    \( -clone 0 -define convolve:scale='!' \
    -define morphology:compose=Lighten \
    -morphology Convolve 'Sobel:>' \
    $thickening \
    -negate -evaluate pow $gain \) \
    $swapping $composing $deleting \
    $modulating \
    "$outfile"