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

EDGEFX


Extracts the edges in an image and optionally composes them with the image to create interesting effects.

Download Script

last modified: April 25, 2015



USAGE: edgefx [-s strength] [-c compose] [-m mix] [-N] infile outfile
USAGE: edgefx [-h or -help]

-s ... strength .... edge strength (i.e. gain or intensity); float>=0;
.................... default=5
-c ... compose ..... compose method to composite edge image with original;
.................... most mathematical, lighting or channel IM compose
.................... methods allowed; default=over for simple blending;
-m ... mix ......... mix percent between compose processed edge image and
.................... the original; 0<=integer<=100; default=100 for full
.................... edge composed image (0 for original image)
-N ................. Negate (reverses) edge polarity

PURPOSE: To extract the edges in an image and optionally composes them with the image to create interesting effects.

DESCRIPTION: EDGEFX extracts the edges in an image and optionally composes them with the image to create interesting effects. The polarity of the extracted edge may be reversed. The 8-directional sobel edge operator is used to extract the edges.

ARGUMENTS:

-s strength ... STRENGTH is the edge strength (i.e., gain or intensity). Values are floats>=0. The default=5.

-c compose ... COMPOSE is the compose method used to combine the edge image with the original image. Most mathematical, lighting or channel IM compose methods are allowed. The default=over, which is just simple blending.

-m mix ... MIX is the mix percent between compose processed edge image and the original. Mix=0 results in the original image. Mix=100 is results in the compose processed edge image. The default=100. When used with the default compose method, this produces the simple edge extracted image.

-N ... NEGATE (reverses) edge polarity.

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 Edge Strength
(source)

Original

Arguments:
-s 1 -m 100 -c over

Arguments:
-s 3 -m 100 -c over

Arguments:
-s 5 -m 100 -c over

Arguments:
-s 7 -m 100 -c over

Arguments:
-s 9 -m 100 -c over



Example 2 -- Variation in Negated Edge Strength

Original

Arguments:
-s 1 -m 100 -c over

Arguments:
-s 3 -m 100 -c over

Arguments:
-s 5 -m 100 -c over

Arguments:
-s 7 -m 100 -c over

Arguments:
-s 9 -m 100 -c over



Example 3 -- Variation in Edge Mixed with Original

Original

Arguments:
-s 5 -m 0 -c over

Arguments:
-s 5 -m 25 -c over

Arguments:
-s 5 -m 50 -c over

Arguments:
-s 5 -m 75 -c over

Arguments:
-s 5 -m 100 -c over



Example 4 -- Variation in Compose Method

Original

Arguments:
-s 5 -m 100 -c over
(default)

Arguments:
-s 5 -m 100 -c overlay

Arguments:
-s 5 -m 100 -c vivid_light

Arguments:
-s 5 -m 100 -c luminize

Arguments:
-s 5 -m 100 -c pin_light

Arguments:
-s 5 -m 100 -c hard_light

Arguments:
-s 5 -m 100 -c linear_light

Arguments:
-s 5 -m 100 -c lighten

Arguments:
-s 5 -m 100 -c color_dodge

Arguments:
-s 5 -m 100 -c screen

Arguments:
-s 5 -m 100 -c linear_dodge

Arguments:
-s 5 -m 100 -c linear_burn

Arguments:
-s 5 -m 100 -c color_burn

Arguments:
-s 5 -m 100 -c multiply

Arguments:
-s 5 -m 100 -c darken

Arguments:
-s 5 -m 100 -c pegtop_light

Arguments:
-s 5 -m 100 -c soft_light

Arguments:
-s 5 -m 100 -c colorize

Arguments:
-s 5 -m 100 -c saturate

Arguments:
-s 5 -m 100 -c hue

Arguments:
-s 5 -m 100 -c difference

Arguments:
-s 5 -m 100 -c exclusion

 

 


Example 5 -- English Tea Cup Painting
(reference)

Original

Arguments:
-s 5 -m 33 -c luminize



Example 6 -- Daylight To Evening Transition

Original

Arguments:
-s 5 -m 10 -c difference

Arguments:
-s 5 -m 20 -c difference

Arguments:
-s 5 -m 30 -c difference

Arguments:
-s 5 -m 40 -c difference

Arguments:
-s 5 -m 50 -c difference



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 extacted edges
  • Composes the edge image with the original
  • Optionally blends the compose processed edge image with the original

This is equivalent to the following IM commands

  • if [ "$neg" = "yes" ]; then
    neg="-negate"
    else
    neg=""
    fi
  • convert $infile \
    \( -clone 0 -define convolve:scale='!' \
    -define morphology:compose=Lighten \
    -morphology Convolve 'Sobel:>' \
    -negate -evaluate pow $strength $neg \) \
    \( -clone 0 -clone 1 -compose $compose -composite \) \
    -delete 1 -define compose:args=$mix -compose blend -composite \
    $outfile