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.

STRETCH


Modifies an image to automatically stretch the dynamic range between full black and white.

Download Script

last modified: December 15, 2018



USAGE: stretch [-c colormode] infile outfile
USAGE: stretch [-h or -help]

-c .... colormode ..... colorspace/channel to use to compute
....................... min and max statistics; choices are:
....................... global, intensity, luminance, lightness,
....................... rgb and sl; default=luminance

PURPOSE: To modify an image to automatically stretch the dynamic range between full black and white.

DESCRIPTION: STRETCH modifies an image to automatically stretch the dynamic range between full black and white. No gamma correction is applied. The minimum and maximum values may be computed from various graylevel representations of the image or individually channel-by-channel. The script then passes these values to the IM function -level.

ARGUMENTS:

-c colormode ... COLORMODE is the colorspace/channel(s) to use to compute the minimum and maximum values. The choices are: global, intensity, luminance, lightness, rgb and sl. The default is luminance.

Global uses aggregate statistics from all the channels. Intensity uses statistics from -colorspace Gray (Rec609Luma). Luminance uses statistics from -colorspace Rec709Luma. Lightness uses statistics from the lightness channel of -colorspace HSL. RGB uses statistics independently from each channel of -colorspace RGB. SL uses statistics independently from each the S,L channels of -colorspace HSL. See definitions at: http://www.imagemagick.org/script/command-line-options.php#colorspace

Note: generally there are only slight differences between the various non-rgb colormode results. Colormode=rgb can cause color balance shifts.

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


Variations On Colormode In Low Contrast Image

Original Image

Arguments:
-c global

Arguments:
-c intensity

Arguments:
-c luminance

Arguments:
-c lightness

Arguments:
-c sl

Arguments:
-c rgb



Variations On Colormode In Low Contrast Image
(Image obtained from http://www.webdesign.org/web/photoshop/photoshop-basics/photo-correction-101-auto-color.8149.html)

Original Image

Arguments:
-c global

Arguments:
-c intensity

Arguments:
-c luminance

Arguments:
-c lightness

Arguments:
-c ls

Arguments:
-c rgb



What the script does is as follows:

  • Converts the image to the desired colorspace/channel(s)
  • Generates a copy of the image in the desired colorspace/channel(s)
  • Accesses the minimum and maximum for this colorspace/channel(s)
  • Passes the minimum and maximum values to -level and applies to
    each channel
  • Converts back to RGB if necessary

This is equivalent to the following IM commands for the luminance colormode.

  • convert $tmpA1 -colorspace Rec709Luma $tmpI1
  • min=`convert $tmpI1 -format "%[min]" info:`
  • max=`convert $tmpI1 -format "%[max]" info:`
  • min=`convert xc: -format "%[fx:100*$min/quantumrange]" info:`
  • max=`convert xc: -format "%[fx:100*$max/quantumrange]" info:`
  • convert $tmpA1 -level ${min}%,${max}% $outfile