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

ENDPOINTS


Applies a Photoshop-like curves operation on an image that only adjusts the linear endpoints.

Download Script

file is missing or empty



USAGE: endpoints [-l lowpt] [-h highpt] [-u units] [-c channels ] infile outfile
USAGE: endpoints [-help]

-l ... lowpt ....... lowpt input,output graylevels as pair of
.................... comma separate non-negative floats;
.................... default="0,0"
-h ... highpt ...... highpt input,output graylevels as pair of
.................... comma separate non-negative floats;
.................... default="100,100" or "255,255" depending upon units.
-u ... units ....... units to use for lowpt and highpt values;
.................... choices are: percent (p) for 0 to 100 percent or
.................... 8bit (8) for 0 to 255; default=8bit
-C ... channels .... processing channels; choices are: all (a),
.................... red (r), green (g) or blue (b); default=global

PURPOSE: To apply a Photoshop-like curves operation that only adjusts the linear endpoints.

DESCRIPTION: ENDPOINTS applies a Photoshop-like curves operation on an image that only adjusts the linear endpoints. 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:

-l lowpt ... LOWPT input,output graylevels as pair of comma separate non-negative floats. The default="0,0".

-h highpt ... HIGHPT input,output graylevels as pair of comma separate non-negative floats. The default="0,0.

-u units ... UNITS to use for lowpt and highpt values. The choices are: percent (p) for 0 to 100 percent or 8bit (8) for 0 to 255. The default=8bit.

-c channels ... CHANNELS are the channel or channels to process. The choices are: all (a) i.e., R,G,B equally, red (r), green (g) or blue (b). The default=all.

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:
-l 64,92 -h 225,255



Example 2 - Cowboy Image

Original

Arguments:
-l 64,92 -h 225,255 -c all

Original

Arguments:
-l 64,92 -h 225,255 -c red

Original

Arguments:
-l 64,92 -h 225,255 -c green

Original

Arguments:
-l 64,92 -h 225,255 -c blue



Example 2 - Photoshop Curves Equivalent

Original

Select Lower Left (low) End Point 1

Select Upper Right (high) End Point 2

Result



What the script does is as follows:

  • Converts both end points' values to percent if 8-bit values
  • Creates a 1D linear gradient lut
  • Computes the slope and intercept from the two points
  • Modifies the 1D lut according to the slope and intercept
    using -function polynomial
  • Limits the high and low values of the 1D lut
    from the point values using -evaluate min and -evaluate max

This is equivalent to the following IM commands for the "all" case using 8bit values.

  • lowpt1=`echo "$lowpt" | cut -d, -f1`
  • lowpt2=`echo "$lowpt" | cut -d, -f2`
  • lowpt1=`convert xc: -format "%[fx:100*$lowpt1/255]" info:`
  • lowpt2=`convert xc: -format "%[fx:100*$lowpt2/255]" info:`
  • highpt1=`echo "$highpt" | cut -d, -f1`
  • highpt2=`echo "$highpt" | cut -d, -f2`
  • highpt1=`convert xc: -format "%[fx:100*$highpt1/255]" info:`
  • highpt2=`convert xc: -format "%[fx:100*$highpt2/255]" info:`
  • convert -size 1x4000 gradient: -rotate 90 -set colorspace sRGB $tmpL
  • a=`convert xc: -format "%[fx:($highpt2-$lowpt2)/($highpt1-$lowpt1)]" info:`
  • b=`convert xc: -format "%[fx:($lowpt2-$a*$lowpt1)/100]" info:`
  • convert $tmpL -function polynomial "$a,$b" \
    -evaluate max $lowpt2% -evaluate min $highpt2% $tmpL
  • convert "$infile" $tmpL -clut "$outfile"