Fred's ImageMagick Scripts



    Licensing:

    Copyright © Fred Weinhaus

    My scripts are available free of charge for non-commercial 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

LEVELS


Applies a Photoshop-like levels operation on an image.

Download Script

last modified: August 27, 2013



USAGE: levels [-C colorspace ] [-i invals] [-o outvals] [-r range] [-g gammaval] [-c clipvals] infile outfile
USAGE: levels [-h or -help]

-C ... channels .... processing channels; choices are: global (g),
.................... rgb (r) or lum (l); default=global
-i ... invals ...... input stretch values; ilow,ihi as pair of
.................... comma separate non-negative floats;
.................... default=no change
-o ... outvals ..... output compress values; olow,ohi as pair of
.................... comma separate non-negative floats;
.................... default=no change
-r ... range ....... range of values to use for invals and outvals;
.................... choices are: percent (p) for 0 to 100 percent,
.................... 8bit (8) for 0 to 255, qrange (q) for
.................... quantumrange for IM Qlevel (e.g. 0 to 65535
.................... for Q16); default=percent
-g ... gammaval .... gamma value for non-linear adjustment;
.................... float>0; default=1 (for no change)
-c ... clipvals .... clip values as percent counts; clow,chi as
.................... comma separated pair of floats; default is
.................... for no change

PURPOSE: To apply a Photoshop-like levels operation on an image.

DESCRIPTION: LEVELS applies a Photoshop-like levels operation on an image. The user may specify the input stretch values, a gamma value, the output compress (limiting) values and percent count clip values. Processing can be applied globally (i.e. to the rgb channels equally), to the rgb channels independently or to the luminosity channel from YUV.

ARGUMENTS:

-C channels ... CHANNELS are the channel or channels to process. The choices are: global (g) i.e., to RGB equally, rgb (r) for clipping each rgb channel separately or lum (l) i.e. the luminosity Y channel from colorspace YUV. The default=global

-i invals ... INVALS=ilow,ihi are the input linear stretch values expressed as a pair of comma separate non-negative floats. Values will depend upon the range parameter. The default=no change

-o outvals ... OUTVALS=olow,ohi are the output linear compress or limiting values expressed as a pair of comma separate non-negative floats. Values will depend upon the range parameter. The default=no change

-r range ... RANGE is the range of values to use for invals and outvals. Choices are: percent (p) for 0 to 100 percent, 8bit (8) for 0 to 255, qrange (q) for quantumrange for IM Qlevel (e.g. 0 to 65535 for Q16). The default=percent

-g gamma ... GAMMA is the gamma value for non-linear adjustment. Values are floats>0. The default=1 (for no change)

-c clipvals ... CLIPVALS=clow,chi are the clip values as percent counts from the histogram ends. Values are 0<=floats<=100. The default is no change. Values of 0,0, however, will stretch the min and max to black and white globally or for each channel depending upon the channels parameter.

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 -- Gradient

Arguments:

Image

Profile

Original

Arguments:
-i 25,75

Arguments:
-o 25,75

Arguments:
-c 5,5

Arguments:
-i 25,75 -o 25,75



Example 2

Original

Arguments:
-C global -i 25,75

Original

Arguments:
-C global -o 25,75

Original

Arguments:
-C global -i 25,75 -o 25,75

Original

Arguments:
-C lum -i 25,75 -o 25,75

Original

Arguments:
-C global -i 25,75 -o 25,75 -c 2,2

Original

Arguments:
-C rgb -i 25,75 -o 25,75 -c 2,2



What the script does is as follows:

  • Combines -contrast-stretch, -level and +level

This is equivalent to the following IM commands for the global case using percent values.

  • if [ "$clipvals" = "" ]; then
    clipping=""
    else
    clipping="-contrast-stretch $clipvals%"
    fi
  • convert $infile $clipping \
    -level ${invals},${gammaval}% -clamp \
    +level ${outvals}% \
    $outfile