Fred's ImageMagick Scripts


    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:


Creates a cartoon-like appearance to an image.

Download Script

last modified: February 18, 2017

USAGE: cartoon [-p pattern] [-n numlevels] [-m method] [-e edgeamount] [-b brightness] [-s saturation] infile outfile
USAGE: cartoon [-h or -help]

-p ... pattern ...... segmentation pattern (shape); 0<=integer<=100;
..................... default=70
-n ... numlevels .... number of desired segmentation levels; integer>=2;
..................... default=6
-m ... method ....... edge method; 1 or 2; default=1
-e ... edgeamount ... amount of edges; float>=0; default=4
-b ... brightness ... brightness of cartoon; integer>=0; default=100
-s ... saturation ... saturation of cartoon; integer>=0; default=150

PURPOSE: To create a cartoon-like appearance to an image.

DESCRIPTION: CARTOON creates a cartoon-like appearance to an image. The image is smoothed and then multiplied by a grayscale version of the image with the desired number of levels to produce the segmented appearance. The pattern parameter changes the shape of the segmentation for the given number of levels. Edges are then superimposed onto the image.


-p pattern ... PATTERN is the pattern or shape of the segmentation. Values are between 0 and 100. The default=70.

-n numlevels ... NUMLEVELS is the desired number of segmentation levels. Values are integers>=2. The default=6.

-m method ... edge METHOD. Choices are 1 or 2. The default=1.

-e edgeamount ... EDGEAMOUNT is the amount of edges to overlay on the cartoon. Values are floats>=0. The default=4.

-b brightness ... BRIGHTNESS of the cartoon. Values are integer>=0. The default=100 (no change).

-s saturation ... SATURATION of the cartoon. Values are integer>=0. The default=150.

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.


Image 1 -- Variation In Pattern


Arguments: -p 60 -e 4 -n 6

Arguments: -p 70 -e 4 -n 6

-p 80 -e 4 -n 6

Image 1 -- Variation In Number Of Levels


Arguments: -p 70 -e 4 -n 4

Arguments: -p 70 -e 4 -n 5

-p 70 -e 4 -n 6

Image 1 -- Variation In Edge Amount


Arguments: -p 70 -e 3 -n 6

Arguments: -p 70 -e 4 -n 6

-p 70 -e 5 -n 6

Image 1 -- Method 1 vs Method 2


Arguments: -p 70 -e 4 -n 6 -m 1

Arguments: -p 70 -e 4 -n 6 -m 2

Image 2


-p 70 -n 6 -e 3

Image 3


Arguments: -p 80 -n 6 -e 3 -b 120

Image 4


Arguments: -p 70 -n 6 -e 4

What the script does is as follows:

  • (Optionally) applies a median filter to the image
  • Reduces the number of colors in the filtered image
  • Converts the original image to grayscale
  • (Optionally) applies a median filter to the grayscale image
  • Applies a gradient edge detector to the grayscale image
  • Thresholds the edge image to binary
  • Composites the edge image with the color reduced image

This is equivalent to the following IM commands

  • Smooths the image
  • Converts a copy to grayscale, posterizes the levels and \
    applied median filtering and a small amount of blur
  • Multiples the smoothed and grayscale images to create \
    the cartoon appearance
  • Negates and blurs the previous image and colordodge \
    composites to create an edge image
  • Raises the edge image to a power to amplify the edges,
    thresholds and median filters it to create a binary edge mask image
  • Multiplies the binary edge mask image with the cartoonish image