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

SKETCHING


Applies a sketch effect to an image.

Download Script

last modified: September 26, 2017



USAGE: sketching [-d detail] [-e edge] [-c coloring] [-s saturation] infile outfile
USAGE: sketching [-h|-help]

-d ... detail ....... image detail; float>=0; default=3
-e ... edge ......... edge thickness; integer>0; default=1
-c ... coloring ..... image coloring; float>=0; default=1
-s ... saturation ... color saturation; integer>=0; default=100 (no change).

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

DESCRIPTION: SKETCHING applies a variety of sketch-like effects to an image.

ARGUMENTS:

-d detail ... DETAIL enhancement in image. Values are floats>=0. The default=3

-e edge ... EDGE thickness. Values are integers>0. The default=1.

-c coloring ... image COLORING. Values are floats>=0. The default=1.

-s saturation ... color SATURATION. Values are integer>=0. The default=100 (no change).

REFERENCE: http://www.photoshopessentials.com/photo-effects/photo-to-sketch/

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 Detail

Original
(http://www.photoshopessentials.com/photo-effects/portrait-to-sketch/)

Arguments:
-d 2 -e 1 -c 1 -s 100

Arguments:
-d 3 -e 1 -c 1 -s 100

Animation
-d 4 -e 1 -c 1 -s 100



Example 2 - Variation in Edge

Original
(http://www.photoshopessentials.com/photo-effects/portrait-to-sketch/)

Arguments:
-d 4 -e 2 -c 1 -s 100

Arguments:
-d 4 -e 3 -c 1 -s 100

Animation
-d 4 -e 4 -c 1 -s 100



Example 3 - Variation in Saturation

Original
(http://www.photoshopessentials.com/photo-effects/portrait-to-sketch/)

Arguments:
-d 4 -e 2 -c 1 -s 100

Arguments:
-d 4 -e 2 -c 1 -s 50

Animation
-d 4 -e 2 -c 1 -s 0



Example 4 -- Variation in Detail
(source)

Original

Arguments:
-d 1 -e 1 -c 1 -s 100

Arguments:
-d 2 -e 1 -c 1 -s 100

Arguments:
-d 3 -e 1 -c 1 -s 100

Arguments:
-d 4 -e 1 -c 1 -s 100



Example 5 -- Variation in Saturation
(source)

Original

Arguments:
-d 3 -e 1 -c 1 -s 100

Arguments:
-d 3 -e 1 -c 1 -s 0



Example 6 -- Variation in Detail With Coloring 2
(source)

Original

Arguments:
-d 1 -e 1 -c 2 -s 100

Arguments:
-d 2 -e 1 -c 2 -s 100

Arguments:
-d 3 -e 1 -c 2 -s 100

 

 


Example 7 -- Variations
(source)

Original

Arguments:
-d 1 -e 1 -c 1 -s 100

Arguments:
-d 1 -e 1 -c 2 -s 100

Arguments:
-d 3 -e 1 -c 1 -s 100

Arguments:
-d 3 -e 1 -c 2 -s 0



What the script does is as follows:

  • Reads the input image
  • Make a copy of the input and converts to grayscale
  • Copies the grayscale image and applies a local minimum operation,
    then applies a power law to enhance the coloring
  • Colordodge composes the grayscale image with the modified grayscale
    image to create an edge image, which is enhance with a power law
  • Screen composes the edge image with the original and applies
    desaturation as desired to form the output

This is equivalent to the following IM commands

  • if [ "$detail" != "1" ]; then
    detailing="-evaluate pow $detail"
    else
    detailing=""
    fi
  • if [ "$coloring" != "1" ]; then
    colorizing="-evaluate pow $coloring"
    else
    colorizing=""
    fi
  • if [ "$saturation" != "100" ]; then
    saturating="-modulate 100,$saturation,100"
    else
    saturating=""
    fi
  • edge=$((2*edge+1))
  • convert "$infile" \
    \( -clone 0 -colorspace gray \) \
    \( -clone 1 -negate -statistic minimum ${edge}x${edge} $colorizing \) \
    \( -clone 1 -clone 2 -compose color_dodge -composite $detailing \) \
    -delete 1-2 +swap -compose screen -composite $saturating "$outfile"