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.

UWCORRECT


Corrects the color balance for red light attenuation in pictures taken underwater.

Download Script

last modified: November 22, 2023



USAGE: uwcorrect [-m method] [-b bright] [-c contrast] [-s sat] [-h hue] [-S sharp] infile outfile
USAGE: uwcorrect [-H or -help]

-m .... method ......... method of red substitution; method=1 or 2;
........................ method 1 uses -tint, method 2 uses +level-colors;
........................ default=1
-b .... bright ......... brightness change in percent; -100<=integer<=100;
........................ default=0 (no change)
-c .... contrast ....... contrast change in percent; -100<=integer<=100;
........................ default=0 (no change)
-s .... sat ............ saturation change in percent; -100<=integer<=100;
........................ default=0 (no change)
-h .... hue ............ hue change in percent; -100<=integer<=100;
........................ default=0; +-100 corresponds to +-180 deg
-S .... sharp .......... sharpening in pixels; integer>=0; default=0

PURPOSE: To correct the color balance for red light attenuation in pictures taken underwater.

DESCRIPTION: UWCORRECT corrects the color balance for red light attenuation in pictures taken underwater. It uses a red colorized grayscale version of the image to compensate for the nearly dark red channel.

ARGUMENTS:

-m method ... METHOD is the technique for red substitution. Choices are method=1 or 2. Method 1 uses -tint. Method 2 uses -level-colors. The default=1

-b bright ... BRIGHT is the percent change in brightness. Values are integers between -100 and 100. Positive values increase brightnesss and negative values decrease brightness. The default is zero or no change.

-c contrast ... Contrast is the percent change in contrast. Values are integers between -100 and 100. Positive values increase contrast and negative values decrease contrast. The default is zero or no change.

-s sat ... Sat is the percent change in saturation. Values are integers between -100 and 100. Positive values increase contrast and negative values decrease contrast. The default is zero or no change.

-h hue ... HUE is the percent change in hue. Values are integers between -100 and 100 (corresponding to -180 deg and +180 deg shifts). Positive values shift red towards yellow and green and negative values shift red toward magenta and blue. Similarly for other colors. The default is zero or no change.

-S sharp ... SHARP is the change in sharpness expressed in pixels. Values are integers greater than or equal to 0. The default=0 or no sharpening.

NOTE: This script requires IM 6.5.9-0 or higher due if using -brightness-contrast; otherwise IM 6.5.5-1 due to the use of -auto-level.

Technique References:
http://www.scubaboard.com/forums/digital-darkroom/269939-faster-mandrake-method.html
http://www.divester.com/2005/03/08/how-to-editing-underwater-photos-with-adobe-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

Original

Arguments:
-m 1 -s 10 -h -20 -S 3



Example 2

Original

Arguments:
-m 2 -s 30



Example 3

Original

Arguments:
-m 1 -b -20 -s 20



What the script does is as follows:

  • Makes a grayscale copy of the image and either tints it red
    or composites it with a red image via multiplication
  • Screen composites the original with the red colorized grayscale image
  • Optionally applies changes to any or all of brightness,
    contrast, satuation, hue and sharpening

This is equivalent to the following IM commands for tint case.

  • sat=`convert xc: -format "%[fx:100+$sat]" info:`
  • hue=`convert xc: -format "%[fx:100+$hue]" info:`
  • convert \( $infile -auto-level \) \
    \( +clone -colorspace gray -fill red -tint 50 \) \
    -compose screen -composite -channel rgb -auto-level +channel \
    -brightness-contrast ${bright},${contrast} \
    -modulate 100,${sat},${hue} -sharpen 0x${sharp} $outfile