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.

SATURATION


Changes the color saturation in an image.

Download Script

last modified: December 15, 2018



USAGE: saturation [value] infile outfile
USAGE: saturation [-h or -help]

value ................ saturation gain factor (float);
...................... sat>=0.0; default=1.0 (no change)
...................... must specify one digit after decimal
-h or -help .......... get help

PURPOSE: To change the color saturation in an image.

DESCRIPTION: SATURATION changes the color saturation in an image in a linear manner. The image is first converted to HSL colorspace and then the saturation value is used as a multiplier for each value in the S channel. Then the modified saturation channel is recombined with the H and L channels and the image is converted to RGB colorspace as output.

ARGUMENTS:

value --- value is the saturation factor. It is a multiplier for the saturation channel in an image. Values greater than 1.0 will increase the saturation of the image and values less than 1.0 will decrease the saturation of the image. The default is 1.0 or no gain. Note: must specify the decimal point and one digit following it.

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


Increasing Saturation

Original Image

Arguments:
1.2

Arguments:
1.5



Decreasing Saturation

Original Image

Arguments:
0.8

Arguments:
0.5



What the script does is as follows:

  • Converts image to HSL colorspace
  • Multiplies the saturation channel by the desired value
  • Recombines the H, modified S and L channels and
    converts to RGB colorspace

This is equivalent to the following IM commands for
the case of a desired value of 1.2:

  • convert $infile -colorspace HSL -channel R -separate $tmp0
  • convert $infile -colorspace HSL -channel G -separate $tmp1
  • convert $infile -colorspace HSL -channel B -separate $tmp2
  • convert $tmp0 -colorspace HSL \
    $tmp0 -compose CopyRed -composite \
    \( $tmp1 -evaluate multiply 1.2 \) -compose CopyGreen -composite \
    $tmp2 -compose CopyBlue -composite \
    -colorspace RGB $outfile