Fred's ImageMagick Scripts


 

 

SATURATION


Changes the color saturation in an image.

Download Script

last modified: May 30, 2008



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

value ................ saturation gain factor (float);
...................... sat>=0.0; default=1 (no change)
-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 will increase the saturation of the image and values less than 1 will decrease the saturation of the image. The default is 1 or no gain.

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