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

SLANTEDLIGHT


Applies slanted lighting to an image.

Download Script

last modified: April 25, 2015



USAGE: slantedlight [-a angles] [-i intensities] [-d distances] [-s smooth]
[-p percent] [-c color] infile outfile

USAGE: slantedlight [-h or -help]

-a ... angles ........ angles towards which the light is directed; one or more
...................... comma or space separated values; 0<=integers<=360;
...................... angle directions are clockwise from east; default=0
-i ... intensities ... intensities corresponding to each light;
...................... integers>=0; default=100
-d ... distances ..... distances for which each light is directed;
...................... integers>=0; default=30
-s ... smooth ........ smoothing (softening) of soft lights; float>=0;
...................... default=0 (no smoothing)
-p ... percent ....... percent of white from thresholding; 0<=float<=100;
...................... default=2
-c ... color ......... color of softlight; any valid opaque IM color;
...................... default=white

PURPOSE: To apply slanted lighting to an image.

DESCRIPTION: SLANTEDLIGHT applies slanted lighting to an image. Multiple directions of light may be applied with different intensities and lengths.

ARGUMENTS:

-a angles ... ANGLES towards which the light is directed. One or more comma or space separated values enclosed in quotes. Values are integers between 0 and 360 (degrees). Angle directions are clockwise from east. The default=0.

-i intensities ... INTENSITIES corresponding to each light. One or more comma or space separated values enclosed in quotes. If the list of intensities is shorter than the list of angles, then the first intensity value will be used for missing entries. Values are integers greater then 0. The default=100.

-d distances ... DISTANCES corresponding to each angle for which each light is directed. One or more comma or space separated values enclosed in quotes. If the list of intensities is shorter than the list of angles, then the first intensity value will be used for missing entries. Values are integers greater than or equal to 0. The default=30.

-s smooth ... SMOOTH is the smoothing amount of the slanted lights. Values are floats greater than or equal to 0. The default=0 (no smoothing).

-p percent ...PERCENT of white from thresholding used to create the slanted light. Values are integers between 0 and 100. The default=2.

-c color ... COLOR of the slanted light. Any valid opaque IM color is allowed. The default=white.

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 Intensities

Original
(image)

Arguments:
(default)
-a 0 -i 100 -d 30 -s 0 -p 2 -c white

Arguments:
(default)
-a 0 -i 50 -d 30 -s 0 -p 2 -c white

Arguments:
(default)
-a 0 -i 75 -d 30 -s 0 -p 2 -c white



Example 2 - Variation In Distances

Original

Arguments:
(default)
-a 0 -i 100 -d 30 -s 0 -p 2 -c white

Arguments:
(default)
-a 0 -i 100 -d 10 -s 0 -p 2 -c white

Arguments:
(default)
-a 0 -i 100 -d 20 -s 0 -p 2 -c white



Example 3 - Variation In Smoothness

Original

Arguments:
(default)
-a 0 -i 100 -d 30 -s 0 -p 2 -c white

Arguments:
(default)
-a 0 -i 100 -d 30 -s 4 -p 2 -c white

Arguments:
(default)
-a 0 -i 100 -d 30 -s 2 -p 2 -c white



Example 4 - Variation In Percent

Original

Arguments:
(default)
-a 0 -i 100 -d 30 -s 0 -p 2 -c white

Arguments:
(default)
-a 0 -i 100 -d 30 -s 2 -p 1 -c white

Arguments:
(default)
-a 0 -i 100 -d 30 -s 4 -p 3 -c white



Example 4 - Multiple Angles

Original

Arguments:
(default)
-a 0 -i 100 -d 30 -s 0 -p 2 -c white



Example 5

Original
(image)

Arguments:
(default)
-a 120 -i 200 -d 40 -s 0 -p 1 -c white



What the script does is as follows:

  • Creates a mask that represents some percent of the most whitish pixels in the image
  • Optionally Blurs the mask to smooth it
  • For each angle applies motion blur and attenuation/amplification and
    does a compose lighten with the previous result
  • Composes the image with pure white using the processed mask to create the output

This is equivalent to the following IM commands

  • convert $infile -set colorspace RGB -colorspace HSB \
    -channel G -negate -channel GB -separate +channel \
    -compose multiply -composite -contrast-stretch 0,${percent}% \
    -fill black +opaque white $smoothing $tmpB1
  • convert $tmpB1 -fill black -colorize 100% $tmpC1
  • for ((i=0; i angle=${angleArr[$i]}
    intensity=`convert xc: -format "%[fx:${intensityArr[$i]}/100]" info:`
    distance=${distanceArr[$i]}
    angle=`convert xc: -format "%[fx:mod(($angle+180),360)]" info:`
    convert $tmpC1 \
    \( $tmpB1 -motion-blur 0x${distance}+$angle -evaluate multiply $intensity \) \
    -compose lighten -composite $tmpC1
    done
  • convert $infile \( -clone 0 -fill $color -colorize 100% \) $tmpC1 \
    -compose over -composite $outfile