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.

WHITEBALANCING


Applies white balancing to an image according to a gray world method in LAB colorspace.

Download Script

last modified: April 01, 2020



USAGE: whitebalancing [-b blackpt ] [-w whitept] [-g gammaval] [-s sigmoid] [-v vibrance] infile outfile
USAGE: whitebalancing [-h or -help]

-b ... blackpt .... black point percent value for level adjustment of the L
................... channel; 0<=integer<=100; default=0 (no change)
-w ... whitept .... white point percent value for level adjustment of the L
................... channel; 0<=integer<=100; default=100 (no change)
-g ... gammaval ... gamma value for non-linear adjustment on the L channel;
................... float>0; default=1 (no change)
-s ... sigmoid .... sigmoidal contrast value for non-linear adjustment of
................... the L channel; float (positive or negative); default=0
................... (no change)
-v ... vibrance ... percent change in vibrance (saturation);
................... integer (positive or negative); default=0 (no change)

PURPOSE: To apply white balancing to an image and optionally apply brightness/contrast/vibrance enhancement.

DESCRIPTION: WHITEBALANCING applies white balance to an image according to a gray world method in LAB colorspace and optionally applies brightness/contrast/vibrance enhancement. There are no specific arguments for adjusting the white balancing.

ARGUMENTS:

-b blackpt ... BLACKPT is the black point percent value for level adjustment of the L channel. Values are integers between 0 and 100. The default=0 (no change)

-w whitept ... WHITEPT is the white point percent value for level adjustment of the L channel. Values are integers between 0 and 100. The default=0 (no change)

-g gammaval ... GAMMAVAL is the gamma value for non-linear adjustment on the L channel. Values are floats greater than 0. The default=1 (no change)

-s sigmoid ... SIGMOID is the sigmoidal contrast value for non-linear adjustment of the L channel. Values are floats (positive or negative). The default=0 (no change)

-v vibrance ... VIBRANCE is the percent change in vibrance (saturation). Values are integers (positive or negative). The default=0 (no change)

REQUIREMENTS: IM 6.7.8.2 or higher, when the LAB colorspace conversions were fixed. But requires HDMI for correct output results

REFERENCES: https://pippin.gimp.org/image-processing/chapter-automaticadjustments.html http://digital-photography-school.com/turn-ho-hum-color-into-wow-with-photoshop

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
Arguments:
(defaults)
Animation: Original vs Balanced
(source)


Example 2
Arguments:
(defaults)
Animation: Original vs Balanced
(source)


Example 3
Arguments:
(defaults)
Animation: Original vs Balanced
(source)


Example 4
Arguments:
(defaults)
Animation: Original vs Balanced
(source)


Example 5
Arguments:
(defaults)
Animation: Original vs Balanced
(source)


Example 6
Arguments:
(defaults)
Animation: Original vs Balanced




Example 7
Arguments:
-v 20
Animation: Original vs Balanced/Enhanced7
(source)
Example 8
Arguments:
-v 20 -b 20
Animation: Original vs Balanced/Enhanced7
(source)


What the script does is as follows:

  • Converts the image to LAB colorspace
  • Computes the differences of the means of channels A and B from 0.5
  • Multiplies the L channel by the differences and subtracts the results
    from the original A and B channels
  • Converts the L and changed A and B channels back to sRGB colorspace

This is equivalent to the following IM commands.

  • convert $tmpA1 -colorspace LAB -separate +channel $tmpA2
  • meanA=`im7 magick $tmpA2[1] -format "%[fx:(mean-0.5)]" info:`
  • meanB=`im7 magick $tmpA2[2] -format "%[fx:(mean-0.5)]" info:`
  • convert $tmpA2[0] +write mpr:lum \
    \( $tmpA2[1] \( mpr:lum -evaluate multiply $meanA \) +swap -define compose:clamp=off \
    -compose minus -composite \) \
    \( $tmpA2[2] \( mpr:lum -evaluate multiply $meanB \) +swap -define compose:clamp=off \
    -compose minus -composite \) \
    -set colorspace LAB -combine -colorspace sRGB \
    "$outfile"