Fred's ImageMagick Scripts



 

 

CHROME


Applies a chrome effect to a binary image.

Download Script

last modified: November 27, 2011



USAGE: chrome [-i intensity] [-n numcycles] [-s smooth] [-a azimuth] [-e elevation] [-c color] [-b bgcolor] [-f fuzzfact] infile outfile
USAGE: chrome [-h or -help]

-i .... intensity ....... intensity of chrome effect; integer>=0;
......................... default=100 (nominal)
-n .... numcycles ....... number of cycles in the chrome lookup table;
......................... integer>0; default=2
-s .... smooth .......... smoothing amount; float>=0; default=3
-a .... azimuth ......... azimuth angle for light source; 0<=integer<=360;
......................... counterclockwise from positive x axis (East);
......................... default=135 (NorthWest)
-e .... elevation ....... elevation angle for light source; 0<=integer<=90;
......................... upwards from x-y plane; default=45;
-c .... color ........... color for chrome effect; any valid IM color;
......................... default=no special coloration
-b .... bgcolor ......... background color outside chrome area; any valid
......................... IM color including none for transparent
-f .... fuzzfact ........ percent fuzz factor for extracting the background
......................... area; float>=0; default=1

PURPOSE: To apply a chrome effect to a binary image.

DESCRIPTION: CHROME applies an chrome effect to a binary image. Coloration is optional.

ARGUMENTS:

-i intensity ... INTENSITY of chrome effect. This brings out contrast. Values are integers>=0. The default=100 is the nominal values.

-n numcycles ... NUMCYCLES is the number of cycles in the chrome look up table that controls the type of chrome effect. Values are integers>0. The default=2.

-s smooth ... SMOOTH is the amount of smoothing to apply to chrome effect. Values are floats>=0. The default=3.

-a azimuth ... AZIMUTH is the angle in degrees in the x-y plane measured counterclockwise from EAST to the light source. Values are integers in the range 0<=azimuth<=360. The default=135 (NorthWest).

-e elevation ... ELEVATION is the angle in degrees upwards from the x-y plane to the light source. Values are integers in the range 0<=elevation<=90. The default=45.

-c color ... COLOR is the optional color to apply to the chrome effect. Any valid IM color is allowed. The default is no additional color on top of the natural chrome effect.

-b bgcolor ... BGCOLOR is the optional background color outside the chromed items. Any valid IM color is allowed including none for transparency. The default is no special background color.

-f fuzzfact ... FUZZFACT is the fuzz factor in percent used to extract the background region for coloring. Values are floats>=0. The default=1.

REQUIREMENTS: IM 6.4.8-9 in order to support -function sinusoid.

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 Intensity

Original
(http://www.codeproject.com/KB/GDI-plus/Image_Processing_Lab.aspx)

Arguments:
-i 50

Arguments:
-i 100

Arguments:
-i 200



Variation In Numcycles

Original

Arguments:
-n 1

Arguments:
-n 2

Arguments:
-n 3

Arguments:
-n 4

Arguments:
-n 5

Arguments:
-n 6



Variation In Smoothing

Original

Arguments:
-s 2

Arguments:
-s 3

Arguments:
-s 4



Variation In Coloring

Original

Arguments:
-c lightblue

Arguments:
-c lightblue -b none

Arguments:
-c lightblue -b red



What the script does is as follows:

  • Creates a special rising cyclical look up table
  • Applies a smoothing blur to the input image
  • Applies a shading to the blurred image
  • Applies the lut to the shaded blurred image

This is equivalent to the following IM commands

  • amp0=`convert xc: -format "%[fx:$amplitude/100]" info:`
  • amp1=`convert xc: -format "%[fx:$amp0/($amp0+1)]" info:`
  • amp2=`convert xc: -format "%[fx:1/($amp0+1)]" info:`
  • cyc=`convert xc: -format "%[fx:0.5+$numcycles]" info:`
  • convert \( -size 1x100 gradient: -rotate 90 \) \
    \( -clone 0 -function sinusoid $cyc,-90,0.5,0.5 \) \
    \( -clone 1 -evaluate multiply $amp1 \) \
    \( -clone 0 -evaluate multiply $amp2 \) \
    -delete 0,1 -compose plus -composite $tmpA2
  • convert \( $tmpA1 -colorspace gray -blur 0x$smooth \
    -shade ${azimuth}x${elevation} -auto-level \) \
    $tmpA2 -clut $outfile