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.

WHITEBALANCE


Transform an image's overall color balance according to a desired change in a specified white point color.

Download Script

last modified: December 16, 2018



USAGE: whitebalance [x,y] [-c color] [-r refcolor] infile outfile
USAGE: whitebalance [-h or -help]

x,y .................. x,y coordinate in the image to get color to
...................... transform to pure white
-c .... color ........ color to transform to pure white;
...................... may be specified in any standard IM notation
-r .... refcolor ..... reference color to which to match;
...................... may be specified in any standard IM notation
...................... default=white i.e. rgb(255,255,255)

PURPOSE: To transform an image's overall color balance according to a desired change in a specified white point color.

DESCRIPTION: WHITEBALANCE transforms an image's overall color balance according to a desired change in a specified white point color. The white point color may be specified by selecting a pixel coordinate (position) to extract the color or by specifying the color that should be transformed to pure white. One or the other must be specified, but not both. The white point color values (actually any color value as an r,g,b triple in the range of 0 to 255) may be specified.

ARGUMENTS:

x,y ... x,y are the coordinates in the image where the color is to be extracted and transformed to pure white.

-c color ... COLOR is the color to be used to transform to pure white. Any IM color specification is valid. Be sure to enclose it in double quotes.

One or the other of the above must be provided, but not both.

-r refcolor ... REFCOLOR is the reference color to which to match. Any IM color specification is valid. Be sure to enclose it in double quotes. The default="white".

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


White Balance Transformation Of An Image

Original Image

Arguments:
127,1

Arguments:
-c "rgb(200,220,210)"

Arguments:
-c "rgb(250,250,210)"



What the script does is as follows:

  • Extracts the red, green and blue values from the coordinate
    specified or the color specified
  • Determines the red, green and blue ratios for pure white
    vs specified or determined color
  • Determines the recolor transformation matrix entries from
    the color ratios
  • Applies the recolor matrix using -recolor to modify the
    input image's overall color balance

This is equivalent to the following IM commands:

  • convert $infile -recolor "$redfrac 0 0 0 $greenfrac 0 0 0 $bluefrac" $outfile