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. |
Enhances the contrast/brightness in an image using a locally adaptive gamma method. |
last modified: December 15, 2018
USAGE: adaptivegamma [-t type] [-c colormode] [-a autolevel] [-s sigma] [-m mix ]
[-b base] [-g gain] infile outfile
-t ... type ........ type of adaptive gamma enhancement; choices are lcc, pnae, hybrid; PURPOSE: To enhance the contrast/brightness in an image using an adaptive gamma method. DESCRIPTION: ADAPTIVEGAMMA is a locally/spatially adaptive gamma technique to enhance an image's brightness and contrast. There are 3 types of adaptive gamma enhancement that can be used. The first is the local contrast correction (lcc) method. The second is the parallel nonlinear adaptive enhancement (pnae) method. The third is a hybrid blend of the other two. These adaptive gamma methods are power law adjustments of the image as defined by OUT=pow(IN,exponent); where exponent = 1/gamma. However, here the exponent is a value that changes spatially according to the local mean M(x,y) of the intensity-like channel of the image. In the lcc method, exponent=[base]*M(x,y)-1, where M is an image of the local mean of the intensity-like channel achieve by blurring the image and base is nominally 2. In the pnae method, exponent=const*[M(x,y)-epsilon]/[1-M(x,y)+epsilon] + gain. The const and epsilon values are constants where const=0.1 and epsilon=0.01. The gain is essentially a global (inverse) gamma value and is nominally about 0.5. But here the default is computed automatically as (log(0.5)/log(M))*($maxstd/min($maxstd,S)), where M is the global mean of the image and S is the global standard deviation of the image and maxstd is a maximum value for the standard deviation above which the standard deviation term equals unity and so does not affect the first mean term. ARGUMENTS: -t type ... TYPE of adaptive gamma enhancement. The choices are lcc (l), pnae (p) and hybrid (h). The default=hybrid. -c colormode ... COLORMODE is thecolorspace for processing. The choices are gray, srgb, lab, hcl, hsl, hsv, hsi, ycbcr and ohta. The default=gray. -a autolevel ... AUTOLEVEL as preprocessing step. The choices are: off (o), together (t) and separately (s). The default=together -s sigma ... SIGMA value for blurring the intensity-like channel. Values are integer>=0. The default=20. Larger values give slightly more contrast. -m mix ... MIX is the mixing percent for the hybrid blend of the lcc and pnae types. Values are 0<=integers<= 100. The default=50. 0 is pure lcc and 100 is pure pnae. -b base .. BASE value for lcc method. Values are floats>0. The default=2. Larger values reduce the contrast and smaller values increase the contrast. -g gain ... GAIN value for pnae method. Values aare float>=0. The default is computed automatically from the global mean and standard deviation of the intensity-like channel of the image. The nominal value is around 0.5. -T thresh ... THRESH is a threshold to determine if the image is bright or dark. Values are 0<=float<=1. The default=0.5. If bright, the image will be negated before and after processing.
REFERENCES: NOTE: This script may be a bit slow due to the use of -fx. 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. |
Original Image |
![]() |
|
Arguments: (defaults) |
![]() |
Original Image |
![]() |
|
Arguments: (defaults) |
![]() |
Original Image |
![]() |
|
Arguments: (defaults) |
![]() |
Original Image |
![]() |
|
Arguments: (defaults) |
![]() |
Original Image |
![]() |
|
Arguments: (defaults) |
![]() |
Original Image |
![]() |
|
Arguments: (defaults) |
![]() |
Original Image |
![]() |
|
Arguments: (defaults) |
![]() |
Original Image |
![]() |
|
Arguments: (defaults) |
![]() |
Original Image |
![]() |
|
Arguments: (defaults) |
![]() |
Original Image |
![]() |
|
Arguments: (defaults) |
![]() |
Original Image |
|||
![]() |
|||
|
|||
Arguments: -gt 0.55 -dg 1 (defaults) |
|||
![]() |
Original Image |
|
![]() |
|
|
|
Arguments: -gt 0.55 -dg 1 (defaults) |
|
![]() |
Variation in Type |
||
Original Image |
||
![]() |
||
Arguments: -t lcc |
Arguments: -t hybrid |
Arguments: -t pnae |
![]() |
![]() |
![]() |
|
||
Original Image |
||
![]() |
||
Arguments: -t lcc |
Arguments: -t hybrid |
Arguments: -t pnae |
![]() |
![]() |
![]() |
|
||
Original Image |
||
![]() |
||
Arguments: -t lcc |
Arguments: -t hybrid |
Arguments: -t pnae |
![]() |
![]() |
![]() |
|
||
Original Image |
||
![]() |
||
Arguments: -t lcc |
Arguments: -t hybrid |
Arguments: -t pnae |
![]() |
![]() |
![]() |
|
||
Original Image |
||
![]() |
||
Arguments: -t lcc |
Arguments: -t hybrid |
Arguments: -t pnae |
![]() |
![]() |
![]() |
|
||
Original Image |
||
![]() |
||
Arguments: -t lcc |
Arguments: -t hybrid |
Arguments: -t pnae |
![]() |
![]() |
![]() |
|
||
Original Image |
||
![]() |
||
Arguments: -t lcc |
Arguments: -t hybrid |
Arguments: -t pnae |
![]() |
![]() |
![]() |
Variation in Colormode |
||
Original Image |
||
![]() |
||
Arguments: -c gray |
Arguments: -c srgb |
Arguments: -c lab |
![]() |
![]() |
![]() |
Arguments: -c hcl |
Arguments: -c ycbcr |
Arguments: -c ohta |
![]() |
![]() |
![]() |
Variation in Autolevel |
||
Original Image |
||
![]() |
||
Arguments: -a together |
Arguments: -a separate |
|
![]() |
![]() |
|
|
||
Original Image |
||
![]() |
||
Arguments: -a together |
Arguments: -a separate |
|
![]() |
![]() |
Variation in Bias and Gain |
||
Original Image |
||
![]() |
||
Arguments: -t lcc -b 2 |
Arguments: -t lcc -b 3 |
Arguments: -t lcc -b 4 |
![]() |
![]() |
![]() |
Arguments: -t pnae -g 0.4 |
Arguments: -t pnae -g 0.5 |
Arguments: -t pnae -g 0.6 |
![]() |
![]() |
![]() |
Variation in Sigma |
||
Original Image |
||
![]() |
||
Arguments: -s 5 |
Arguments: -s 20 |
Arguments: -s 80 |
![]() |
![]() |
![]() |
What the script does is as follows:
|