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

THRESHOLDS


Applies one or two thresholds to an image.

Download Script

last modified: September 26, 2017



USAGE: thresholds [-l lowthresh] [-h highthresh] [-u units] [-t type] [-M midvalue] [-L lowvalue] [-H highvalue] [-P profile] infile outfile
USAGE: thresholds [-help]

-l ... lowthresh ... low threshold in range of units; default=0 (percent)
-h ... highthresh ... high threshold in range of units; default=100 (percent)
-u ... units units to use; choices are: percent (p) for range of
..................... 0 to 100 percent, 8bit (8) for range of 0 to 255 and
..................... 16bit (16) for range 0 to 65535; default is 100 (percent)
-t ... type ......... type of thresholds; choices are: hard (h), soft (s) or
..................... clipped (c); default=hard
-M ... midvalue ..... mid graylevel value in units for type=clipped;
..................... default is no value
-L ... lowvalue ..... low graylevel value in units; used only for type=clipped
..................... and when midvalue supplied; default=0 (percent)
-H ... highvalue .... high graylevel value in units; used only for
..................... type=clipped and when midvalue supplied;
..................... default=100 (percent)
-P ... profile ...... view (v) or save (s) the profile graph; default is neither

PURPOSE: To apply one or two thresholds to an image. linear endpoints.

DESCRIPTION: ENDPOINTS applies one or two thresholds to an image. The types of thresholds allowed are: hard, soft and clipped. Units for the thresholds may be any of: percent, 8-bit values or 16-bit values.

ARGUMENTS:

-l lowthresh ... LOWTHRESH is the low threshold in the range of the specified units. The default=0 (percent).

-h highthresh ... HIGHTHRESH is the high threshold in the range of the specified units. The default=100 (percent).

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

-t type ... TYPE of thresholds. The choices are: hard (h), soft (s) or clipped (c). The default=hard.

-M midvalue ... MIDVALUE is the mid (output) graylevel value in the specified units for type=clipped. The default is no value.

-L lowvalue ... LOWVALUE is the low (output) graylevel value in the specified units. It is used only for type=clipped and when the midvalue is supplied. The default=0 (percent).

-H highvalue ... HIGHVALUE is the high (output) graylevel value in the specified units. It is used only for type=clipped and when the midvalue is supplied. The default=100 (percent).

-P profile ... PROFILE allows the option to view (v) or save (s) the profile graph. The profile will be named from the input file with _profile.gif appended. The default is neither. Requires my script, plot.

REQUIREMENTS: my script, plot, is needed to use the -P option.

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:
-t hard -l 25 -h 100

same as
-black-threshold 25%

Arguments:
-t soft -l 25 -h 100

Arguments:
-t clipped -l 25 -h 100

Arguments:
-t hard -l 0 -h 75

same as
-white-threshold 75%

Arguments:
-t soft -l 0 -h 75

Arguments:
-t clipped -l 0 -h 75

Arguments:
-t hard -l 25 -h 75

Arguments:
-t soft -l 25 -h 75

Arguments:
-t clipped -l 25 -h 75

Arguments:
-t clipped -l 25 -h 75 -M 100 -L 0 -H 0

Arguments:
-t clipped -l 25 -h 75 -M 75 -L 25 -H 25

Arguments:
-t clipped -l 25 -h 75 -M 75 -L 25 -H 50



What the script does is as follows:

  • Applies different combinations of -black-threshold, -white-threshold,
    and -fill ... -opaque ... to achieve one or two thresholds

This is equivalent to the following IM commands for type=clipped and two thresholds

  • if [ "$lowthresh" != "0" ]; then
    lowproc1="-black-threshold ${lowthresh}%"
    lowproc2="-fill 'gray($lowvalue%)' -opaque black"
    else
    lowproc1=""
    lowproc2=""
    fi
  • if [ "$highthresh" != "100" ]; then
    highproc1="-white-threshold ${highthresh}%"
    highproc2="-fill 'gray($highvalue%)' -opaque white"
    else
    highproc1=""
    highproc2=""
    fi
  • midproc="-fill 'gray($midvalue%)' +opaque 'gray($lowvalue%)'"
  • eval convert $infile $lowproc1 $lowproc2 $highproc1 $highproc2 $midproc $outfile