Fred's ImageMagick Scripts



    Licensing:

    Copyright © Fred Weinhaus

    My scripts are available free of charge for non-commercial (non-profit) 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

    Please read the Pointers For Use on my home page to properly install and customize my scripts.

MODULATECOLOR1


Changes brightness, saturation and/or hue for any primary or secondary color in an image.

Download Script

last modified: December 15, 2018



USAGE: modulatecolor1 [-c color] [-b brightness] [-s saturation] [-u units] [-h hue] [-m mode] [-C colorspace] infile outfile
USAGE: modulatecolor1 [-help]

-c ... color ........ color to modify: red (r), yellow (y), green (g),
..................... cyan (c), blue (b), magenta (m); default=red
-b ... brightness ... percent brightness; float>=0; default=100 (no change)
-s ... saturation ... percent saturation; float>=0; default=100 (no change)
-u ... units ........ units for hue; percent (p) or degrees (d);
..................... default=percent
-h ... hue .......... hue value 0<=float<=100 percent or 0<=float<=360
..................... degrees; default=0 (red stays red)
-m ... mode ......... mode for hue values; choices are: relative (r) or
..................... absolute (a); default=absolute
-C ... colorspace ... colorspace in which to modulate the image; choices are:
..................... HSL or HCLp; default=HSL

PURPOSE: To change brightness, saturation and/or hue for any primary or secondary color in an image.

DESCRIPTION: MODULATECOLOR1 changes the brightness and/or saturation and/or hue for any primary or secondary color in an image. Hues are arranged in a cyclical order in the range 0 to 100 percent or 0 to 360 degrees. Hue may be changed any amount in those ranges per the units specified. The colors allowed are: red, yellow, green, cyan, blue and magenta. Units for hue may be either percent or degrees.

ARGUMENTS:

-c color ... COLOR to modify. The choices are: red (r), yellow (y), green (g), cyan (c), blue (b) or magenta (m). The default=red.

-b brightness ... BRIGHTNESS is the absolute percent brightness. Values are floats>=0. The default=100 (no change).

-s saturation ... SATURATION is the absolute percent saturation. Values are floats>=0. The default=100 (no change).

-u units ... UNITS for hue. Choices are: percent (p) or degrees (d). The default=degrees.

-m mode ... MODE for hue values. The choices are: relative (r) or absolute (a). Relative means the replacement hue value will be a shift relative to the specified color. Absolute means the hue value will be the exact hue value that will be used to replace the specified color. The default=absolute.

-h hue ... HUE is the absolute hue value to be used to replace the hue of the specified color. Values are 0<=floats<=100 for percent or 0<=floats<=360 for degrees. The default=0 (red stays red). Hue change is cyclical in the range from 0 to either 100 percent or 360 degrees. So a hue value of 100 percent or 360 degrees is equivalent to 0 or no change.

-C colorspace ... COLORSPACE is the colorspace in which to modulate the image. The choices are: HSL or HCLp.

REQUIREMENTS: IM 6.5.3-7 so that -modulate uses HSL and not HSB colorspace. HCLp modulation is available as of version 6.8.6-7.

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.


REFERENCE CHART


EXAMPLES


Example 1

Original Image

Arguments:
-c green -u degrees -m absolute -h 240


Example 2

Original Image
(source)

Arguments:
-c green -u degrees -m absolute -h 0 -s 300
Arguments:
-c green -u degrees -m absolute -h 180 -s 300


What the script does is as follows:

  • Clones the input and modulates it
  • Creates a mask image from the desired color channel(s) and negated other channel(s)
  • Composites the original and modulated image together using the mask image

This is equivalent to the following IM commands for the case of color=green, units=degrees and mode=absolute.

  • hue=`convert xc: -format "%[fx:100+(200*($hue-120)/360)]" info:`
  • convert $infile \
    \( -clone 0 -define modulate:colorspace=$colorspace -modulate $brightness,$saturation,$hue \) \
    \( -clone 0 -channel rb -separate +channel -negate -clone 0 -channel g -separate -evaluate-sequence multiply \) \
    -compose over -composite "$outfile"