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.

SIGMOIDAL


Applies a sigmoidal brightness and/or contrast adjustment to an image

Download Script

last modified: December 15, 2018



USAGE: sigmoidal [-b bri] [-c con] [-C channels] [-l lutlength] [-g] infile outfile
USAGE: sigmoidal [-h or -help]

-b ... bri ........... brightness change; float; positive increases brightness;
...................... negative decreases brightness; default=0 (no change)
-c ... con ........... contrast change; float; positive increases contrast;
...................... negative decreases contrast; default=0 (no change)
-C ... channels ...... any valid IM combination of channels corresponding to
...................... the image's colorspace to which to apply the
...................... transformation: r,g,b,a, or c,m,y,k,a;
...................... default=all non-alpha channels
-l ... lutlength ..... length of 1D lut; integer>0; default=1000
-g ................... enables the creation of a graph of the sigmoidal curve
...................... mapping transformation, which is then displayed
...................... automatically. There is a default setting below that
...................... can be changed to enable this to be save to a file
...................... named outfile_kneegraph.gif rather than just viewed.

PURPOSE: To apply a sigmoidal brightness and/or contrast adjustment to an image.

DESCRIPTION: SIGMOIDAL applies a sigmoidal brightness and/or contrast adjustment to an image. The contrast change is the IM -/+sigmoidal-contrast con,50%. The brightness change is the IM -/+sigmoidal-contrast bri,0%. Thus it is half the sigmoidal curve. The bri values are 10 time larger than those used in the IM function and the con values are 5 time larger than those used in the IM function. The transformation is generated as a 1D lut and applied to the image using -clut to affect the desired brightness and/or contrast transformation. The transformation is sensitive to the specified channels. This script is similar to, but not exactly identical to the Photoshop new (CS3 or higher) brightness contrast function.

ARGUMENTS:

-b bri ... BRI is the amount of brightness change. Values are positive or negative floats. Positive values increase the brightness, while negative values decrease the brightness. The default=0 for no change.

-c con ... CON is the amount of contrast change. Values are positive or negative floats. Positive values increase the contrast, while negative values decrease the contrast. The default=0 for no change.

-C channels ... CHANNELS are any valid IM combination of channels corresponding to the image's colorspace to which to apply the transformation. Combinations include: r,g,b,a, or c,m,y,k,a (with no commas). The default=all non-alpha channels.

-l lutlength ... LUTLENGTH is the length of 1D lut. Values are integers>0. The default=1000.

-g ... enables the creation of a graph of the knee curve mapping transformation, which is then displayed automatically. There is a default setting below that can be changed to enable this to be save to a file named outfile_kneegraph.gif. The graph will be scaled to size 100x100. image.

REQUIREMENTS: IM 6.3.5-7 is required to support the use of -clut

NOTE: Negative values for con do not work properly between IM 6.7.6.4 and IM 6.7.8.2 inclusive due to bug in +contrast-stretch

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


Increase Brightness

Original Image

arguments:
-b 10

arguments:
-b 20

arguments:
-b 40

arguments:
-b 80



Decrease Brightness

Original Image

arguments:
-b -10

arguments:
-b -20

arguments:
-b -40

arguments:
-b -80



Increase Contrast

Original Image

arguments:
-c 10

arguments:
-c 20

arguments:
-c 40

arguments:
-c 80



Decrease Contrast

Original Image

arguments:
-c -10

arguments:
-c -20

arguments:
-c -40

arguments:
-c -80



Adjust Brightness And Contrast

Original Image

arguments:
-b 20 -c 20

arguments:
-b 20 -c -20

arguments:
-b -20 -c 20

arguments:
-b -20 -c -20



What the script does is as follows:

  • Creates a linear gradient lut
  • Applies -sigmoidal-contrast bri,0% to adjust the brightness
    and/or -sigmoidal-contrast con,50% to adjust the contrast
  • Use the modified lut with -clut to adjust the image

This is equivalent to the following IM commands for increased brightness
and increased when applied to all channels.

  • abri=`convert xc: -format "%[fx:(1/10)*abs($bri)]" info:`
  • acon=`convert xc: -format "%[fx:(2/10)*abs($con)]" info:`
  • convert -size 1x$lutlength gradient: -rotate 90 $tmpL1
  • convert $tmpL1 -sigmoidal-contrast $acon,50% -sigmoidal-contrast $abri,0% $tmpL1
  • convert $infile $tmpL1 -clut $outfile