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.

AUTOTONE2


Automatically tone balances an image.

Download Script

last modified: July 07, 2023



USAGE: autotone2 [-a autostretch] [-b brightness] [-c contrast] [-s sharpen] [-n noise] [-cb colorbalance] [-w window] [-R resize] [-P percent] infile outfile

USAGE: autotone2 [-h or -help]

-a .... autostretch .... autostretch image channels; options are:
........................ together (t), separate (s), or auto (a);
........................ default=auto
-b .... brightness ..... brightness adjustment factor; float>0;
........................ default=1 (no change from automatic value)
-c .... contrast ....... contrast adjustment factor; float>0;
........................ default=1 (no change from automatic value)
-s .... sharpen ........ sharpening amount; float>0; default=2.5;
........................ larger values will allow more detail;
-n .... noise .......... noise removal factor; integer>=0; default is
........................ auto computed; typical range is about 1 to 4;
........................ zero is no noise removal
-cb ... colorbalance ... color balance mode; choices are gray, white,
........................ both or none; default=both
-w .... window ......... windowing size as percentage of image; nominally
........................ between 5 and 20; 2<=float<=50; default=8
-R .... resize ......... limit the output size to this value; integer>0;
........................ will resize if the larger dimension of the image
........................ exceeds this value
-P .... percent ........ percent threshold for detecting gray/white
........................ for auto color balance; 0<float<100; default=1

PURPOSE: To automatically tone balance an image.

DESCRIPTION: AUTOTONE2 attempts to automatically tone balance and image. This includes brightness/contrast adjustment, color balance, noise removal and sharpening.

ARGUMENTS:

-a autostretch --- AUTOSTRETCH image channels as preprocessing step. The options are: together (t), separate (s) or auto (a). The default=auto. Note, for some images with severe channel stretch, the option separate can cause severe color shifts.

-b brightness --- BRIGHTNESS is a brightness adjustment factor multiplied by the automatically computed default. It is a float>0. Values larger then 1 will increase the brightness and values smaller than 1 will decrease the brightness. The default is 1 or no change from the automatically computed value.

-c contrast --- CONTRAST is a contrast adjustment factor multiplied by the automatically computed default. It is a float>0. Values larger then 1 will increase the contrast and values smaller than 1 will decrease the contrast. The default is 1 or no change from the automatically computed value.

-s sharpen --- SHARPEN is the amount of sharpening to apply. Values are floats>0. The default is 2.5. Larger values allow more detail to show and may be useful for very hazy images. Too large a value may over-exaggerate detail, especially when there is no haze.

-n noise ... NOISE removal amount. Values are integers>=0. The nominal range is about 1 to 4 depending upon image size. Larger values are used for larger images. A value of 0 is no noise removal. The default is automatically computed.

-cb colorbalance ... COLORBALANCE mode. The choices are gray, white, both or none. The default=both.

-w window --- the moving WINDOW size as a percentage of the input image as part of the automatic brightness, contrast and sharpening operations. Values are 2<=float<=50. Typical values are between 5 and 20. The default is 8 (%).

-R resize ... RESIZE is the limit on the output image size. Values are integer>0. This will only resize if the larger dimension of the image exceeds this value. The default is no limit (i.e. no resize).

-P percent ... PERCENT is the percent threshold for detecting gray/white in the image for auto gray and auto white balance. Values are 0<floats<100. The default=1.

RESTRICTIONS: IM 6.5.5-1 or higher due to the use of -autolevel to do the autostretch. Also only works on RGB images (not CMYK). Set colorbalance to none for grayscale images. Note that this script may be slow when using the older (slow) -fx.

NOTE: I thank Dr. Guenter Grau for the suggestion to normalize the r,g,b ratios by their average in the color balance part of the code.

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


Original Image
(http://3.bp.blogspot.com/-iOOnD5rmkxk/Ta7Vi7ePTsI/AAAAAAAAANM/EgDnXlR0HHU/s1600/Chloe%2BBell%2B045.JPG)

 

Arguments:
(defaults)


Original Image
(provided by Anthony Thyssen)

 

Arguments:
(defaults)


Original Image
(http://www.asknlearn.com/EduWiz/help/Chapter9/Chapter9.htm)

 

Arguments:
(defaults)


Original Image
(http://enhance.pho.to/)

 

Arguments:
(defaults)


Original Image
(http://enhance.pho.to/)

 

Arguments:
(defaults)


Original Image
(http://warrencampdesign.com/warren/images/photoEdits/basics/focusContrast/lions_before.jpg)

 

Arguments:
(defaults)


Original Image
(http://digital-photography-school.com/turn-ho-hum-color-into-wow-with-photoshop)

 

Arguments:
(defaults)


Original Image
(http://dragon.larc.nasa.gov/retinex/757/)

 

Arguments:
(defaults)


Original Image
(http://dragon.larc.nasa.gov/retinex/757/)

 

Arguments:
(defaults)
Arguments:
-cb none


Original Image
(http://dragon.larc.nasa.gov/retinex/757/)

 

Arguments:
(defaults)
Arguments:
-s 10


Original Image
(http://sipi.usc.edu/database/database.php?volume=misc&image=1#top)

 

Arguments:
(defaults)
Arguments:
-a t


What the script does is as follows:

  • Applies an automatic channel stretch to full dynamic range using -auto-level
  • Applies an automatic automatic brightness/contrast adjustment using -sigmoidal-contrast
  • Applies a spatially adaptive brightness/contrast and sharpening adjustment
  • Applies auto gray balance using -color-matrix
  • Applies auto white balance using -color-matrix
  • Applies noise removal using iterations of -enhance
  • Applies sharpening using -unsharp