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

SKETCH


Applies a sketch effect to an image.

Download Script

last modified: September 26, 2017



USAGE: sketch [-k kind] [-e edge] [-c con] [-s sat] [-g] infile outfile
USAGE: sketch [-h or -help]

-k ... kind ... kind of grayscale conversion; options are gray(g) or
............... desat(d); default=desat
-e ... edge ... edge coarseness; integer>0; default=4
-c ... con .... percent contrast change; integer>=0; default=125
-s ... sat .... percent saturation change; integer>=0; default=100
-g ............ output grayscale only

PURPOSE: To apply a sketch effect to an image.

DESCRIPTION: SKETCH applies a sketch like effect to an image. If a color image is provided as input, then the output can be either color or grayscale.

ARGUMENTS:

-k kind ... KIND of grayscale conversion. Choices are gray(g) or desat(d). The default=desat.

-e edge ... EDGE coarseness. Values are integers>0. The default=4.

-c con ... percent CONTRAST change. Values are integers>=0. The default=125. Note that con=125 for kind=desat is similar to con=0 for kind=gray.

-s sat ... percent SATURATION change. Values are integers>=0. The default=100.

-g ... output GRAYSCALE only.

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

REQUIREMENTS: Results for -k gray will be nearly identical to those of -k desat for IM versions prior to 6.7.8.3. Starting at this version, grayscale images became linear and thus the different look for -k gray.

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 - Kind=desat; Variation in Contrast

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

Arguments:
-k desat -c 0

Arguments:
-k desat -c 50

Animation
-k desat -c 100

Arguments:
-k desat -c 125

Arguments:
-k desat -c 150

Animation
-k desat -c 175



Example 2 - Kind=gray; Variation in Contrast

Original

Arguments:
-k gray -c 0

Arguments:
-k gray -c 50

Animation
-k gray -c 100

Arguments:
-k gray -c 125

Arguments:
-k gray -c 150

Animation
-k gray -c 175



Example 3 - Variation in Edge

Original

Arguments:
-k desat -c 125 -s 200 -e 1

Arguments:
-k desat -c 125 -s 100 -e 4

Animation
-k desat -c 125 -s 100 -e 8

Arguments:
-k gray -c 0 -s 200 -e 1

Arguments:
-k gray -c 0 -s 100 -e 4

Animation
-k gray -c 0 -s 100 -e 8



Example 4 - Output Grayscale

Original

Arguments:
-k desat -c 125 -g

Arguments:
-k gray -c 0 -g



Example 5 - Desat vs Gray

Original

Arguments:
-k desat -c 125

Arguments:
-k gray -c 0



Example 6 - Desat vs Gray

Original

Arguments:
-k desat -c 125

Arguments:
-k gray -c 0



Example 7 - Desat vs Gray

Original

Arguments:
-k desat -c 125

Arguments:
-k gray -c 0



What the script does is as follows:

  • Converts the image to grayscale or desaturates it
  • Negates the gray image and blurs it
  • Applies a color dodge composition between the gray image and
    its negated and blurred version
  • Optionally applies a level operation to increase contrast
  • Sets the opacity of the previous image and multiplies the two
    so as to adjust the contrast
  • Increases the saturation of original
  • Applies a screen composition between the latter two images

This is equivalent to the following IM commands

  • if [ "$kind" = "gray" ]; then
    grayscaling="-colorspace gray"
    elif [ "$kind" = "desat" ]; then
    grayscaling="-modulate 100,0,100"
    fi
  • if [ $con -le 100 ]; then
    con1=$con
    con2=0
    else
    con1=100
    con2=`convert xc: -format "%[fx:$con-100]" info:`
    fi
  • convert $infile \ \( -clone 0 $grayscaling \) \
    \( -clone 1 -negate -blur 0x${edge} \) \
    \( -clone 1 -clone 2 -compose color_dodge -composite -level ${con2}x100% \) \
    \( -clone 3 -alpha set -channel a -evaluate set ${con1}% +channel \) \
    \( -clone 3 -clone 4 -compose multiply -composite \) \
    \( -clone 0 -modulate 100,$sat,100 \) \
    -delete 0-4 -compose screen -composite $outfile