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.

GRAYTONING


Mixes color channels from an image into a grayscale image and optionally tints it

Download Script

last modified: December 15, 2018



USAGE: graytoning [-r red] [-g green] [-b blue] [-o offset] [-c contrast] [-t tintcolor] [-m mode] [-a amount] infile outfile
USAGE: graytoning [-h or -help]

-r ... red ......... red mix percent; float; default=29.9
-g ... green ....... green mix percent; float; default=58.7
-b ... blue ........ blue mix percent; float; default=11.4
-o ... offset ...... gray brightness percent change; -100<=float<=100;
.................... default=0
-c ... contrast .... gray contrast percent change; -100<=float<=100;
.................... default=0
-t ... tintcolor ... color for tinting; any valid opaque IM color is allowed;
.................... default is no tinting
-m ... mode ........ mode of tinting: choices are: all, midtones, highlights
.................... and shadows; default=midtones
-a ... amount ...... amount of tinting; 0<=integer<=100; default=40

PURPOSE: To mix color channels from an image into a grayscale image and optionally tint it.

DESCRIPTION: GRAYTONING mixes color channels from an image into a grayscale image and optionally tints it. Tint modes allow selective tinting of: all, midtones, hightlights or shadows.

Arguments:

-r red ... RED is the red mix percent in forming the grayscale image. Values are floats. The default=29.9 (equivalent to IM standard grayscale or Rec609Luma.

-g green ... GREEN is the red mix percent in forming the grayscale image. Values are floats. The default=58.7 (equivalent to IM standard grayscale or Rec609Luma.

-b blue ... BLUE is the red mix percent in forming the grayscale image. Values are floats. The default=11.4 (equivalent to IM standard grayscale or Rec609Luma.

-o offset ... OFFSET is the gray offset or brightness percent change. Values are -100<=float<=100. The default=0.

-c contrast ... CONTRAST is the gray contrast percent change. Values are -100<=float<=100. The default=0.

-t tintcolor ... TINTCOLOR is the color for tinting the grayscale image. Any valid opaque IM color is allowed. The default is no tinting.

-m mode ... MODE is the mode of tinting. Choices are: all (a), midtones (m), highlights (h) and shadows (s). The default=midtones.

-a amount ... AMOUNT is the amount of tinting. Values are 0<=integer<=100. The default=40.

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 -- Convert To Grayscale

Original Image

Arguments:
-r 30 -g 60 -b 10

Arguments:
-r 60 -g 20 -b 20

Arguments:
-r -40 -g 144 -b -4



Example 1 -- Convert To Grayscale And Tint

Original Image

Arguments:
-r 30 -g 60 -b 10
-t magenta -m all

Arguments:
-r 30 -g 60 -b 10
-t magenta -m midtones

-r 30 -g 60 -b 10
-t magenta -m highlights

-r 30 -g 60 -b 10
-t magenta -m shadows



Example 1 -- Convert To Grayscale And Tint

Original Image

Arguments:
-r 30 -g 60 -b 10
-t magenta -m all
-a 25

Arguments:
-r 30 -g 60 -b 10
-t magenta -m all
-a 40

Arguments:
-r 30 -g 60 -b 10
-t magenta -m all
-a 50

Arguments:
-r 30 -g 60 -b 10
-t magenta -m all
-a 75

Arguments:
-r 30 -g 60 -b 10
-t magenta -m all
-a 100

Arguments:
-r 30 -g 60 -b 10
-t magenta -m midtones
-a 25

Arguments:
-r 30 -g 60 -b 10
-t magenta -m midtones
-a 40

Arguments:
-r 30 -g 60 -b 10
-t magenta -m midtones
-a 50

Arguments:
-r 30 -g 60 -b 10
-t magenta -m midtones
-a 75

Arguments:
-r 30 -g 60 -b 10
-t magenta -m midtones
-a 100

Arguments:
-r 30 -g 60 -b 10
-t magenta -m highlights
-a 25

Arguments:
-r 30 -g 60 -b 10
-t magenta -m highlights
-a 40

Arguments:
-r 30 -g 60 -b 10
-t magenta -m highlights
-a 50

Arguments:
-r 30 -g 60 -b 10
-t magenta -m highlights
-a 75

Arguments:
-r 30 -g 60 -b 10
-t magenta -m highlights
-a 100

Arguments:
-r 30 -g 60 -b 10
-t magenta -m shadows
-a 25

Arguments:
-r 30 -g 60 -b 10
-t magenta -m shadows
-a 40

Arguments:
-r 30 -g 60 -b 10
-t magenta -m shadows
-a 50

Arguments:
-r 30 -g 60 -b 10
-t magenta -m shadows
-a 75

Arguments:
-r 30 -g 60 -b 10
-t magenta -m shadows
-a 100



What the script does is as follows:

  • Use -color-matrix to mix channels into grayscale
  • Optionally apply selected tinting method

This is equivalent to the following IM commands for the case of
-m midtone.

  • rf=`convert xc: -format "%[fx:$red/100]" info:`
  • gf=`convert xc: -format "%[fx:$green/100]" info:`
  • bf=`convert xc: -format "%[fx:$blue/100]" info:`
  • convert $infile -color-matrix "\
    $rf $gf $bf \
    $rf $gf $bf \
    $rf $gf $bf \
    " -fill "$tintcolor" -tint $amount% $outfile