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

POSTEREDGES


Applies posterized edges to an image.

Download Script

last modified: September 26, 2017



USAGE: posteredges [-w width ] [-a amount] [-m method] [-n number] [-b blur] [-s sat] infile outfile
USAGE: posteredges [-help]

-w ... width .... width of edges; float>0; default=3
-a ... amount ... amount (strenght) of edges; float>0; default=5
-m ... method ... method of reducing colors; choices are: posterize (p) or
................. colors (c); default=posterize
-n ... number ... number of colors; integer>=2; default is no color reduction
-b ... blur ..... blurring (smoothing) of result; float>=0; default=0.5
-s ... sat ...... saturation amount; integer>0; default=100 (no change)

PURPOSE: To apply posterized edges to an image.

DESCRIPTION: POSTEREDGES applies posterized edges to an image. The width and amount of edges may be varied. Color reduction is optional. This script attempts to duplicate some of the features of Photoshop's Posterized Edges.

ARGUMENTS:

-w width ... WIDTH of the edges. Values are floats>0. The default=3.

-a amount ... AMOUNT or strength of the edges. Values are floats>0. The default=5.

-m method ... METHOD of reducing colors. The choices are: posterize (p) or colors (c). The default=posterize

-n number ... NUMBER of reduced colors. Values are integers>=2. The default is no color reduction.

-b blur ... BLUR is the blurring (smoothing) of the result. Values are floats>=0. The default=0.5.

-s sat ... SAT is the saturation of the result. Values are integers>=0. The default=100 for no change.

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


Variation In Width

Original Image

Arguments:
-w 1 -a 5

Arguments:
-w 2 -a 5

Arguments:
-w 3 -a 5



Variation In Amount

Original Image

Arguments:
-w 3 -a 1

Arguments:
-w 3 -a 3

Arguments:
-w 3 -a 5



Variation In Numbers

Original Image

Arguments:
-w 3 -a 5 -m posterize
(no reduction)

Arguments:
-w 3 -a 5 -m posterize
-n 3

Arguments:
-w 3 -a 5 -m posterize
-n 8

Arguments:
-w 3 -a 5 -m posterize
-n 16

Original Image

Arguments:
-w 3 -a 5 -m colors
(no reduction)

Arguments:
-w 3 -a 5 -m colors
-n 3

Arguments:
-w 3 -a 5 -m colors
-n 8

Arguments:
-w 3 -a 5 -m colors
-n 16



Variation In Blur

Original Image

Arguments:
-w 3 -a 5 -b 0

Arguments:
-w 3 -a 5 -b 0.5

Arguments:
-w 3 -a 5 -b 1



What the script does is as follows:

  • clone the input and convert to hcl and separate channels
  • clone L channel and reduce colors
  • recombine with new L channel
  • delete unnecessary images
  • clone original image and convert to grayscale
  • clone grayscale and apply unsharp masking
  • subtract unsharp grayscale image from original grayscale image to get edge image, amplify and negate
  • compose multiply the edge image over the reduced color image and save as output image

This is equivalent to the following IM commands for method=posterize

  • convert $tmpA1 \
    \( -clone 0 -colorspace HCL -separate +channel \) \
    \( -clone 3 -posterize $number \) \
    \( -clone 1 -clone 2 -clone 4 -set colorspace HCL -combine -colorspace -colorspace sRGB \
    -define modulate:colorspace=hcl -modulate 100,$sat,100 \) \
    -delete 1-4 \
    \( -clone 0 -set colorspace RGB -colorspace gray \) \
    \( -clone 2 -unsharp 0x$width \) \
    \( -clone 2 -clone 3 +swap -compose minus -composite -evaluate multiply $amount -negate \) \
    -delete 0,2,3 -compose multiply -composite -blur 0x$blur $outfile