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.

BCIMAGE


Changes the brightness and/or contrast of an image

Download Script

last modified: December 15, 2018



USAGE: bcimage [-g] bri,con[,sat] infile outfile
USAGE: bcimage [-h or -help]

bri ................. percent change in brightness (+/-)
con ................. percent change in contrast (+/-)
sat ................. percent change in saturation (+/-)
-g .................. display mapping function graph

PURPOSE: To change the brightness, contrast and/or saturation of an image.

DESCRIPTION: BCIMAGE is designed to change the brightness and/or contrast and optionally saturation of an image. It works by converting bri and con into slope and intercept and and then into break points. The break points are then converted into a 1-D image look up table. This LUT is then used with clut or -fx to process the image. If the image is not grayscale and a sat value provided, it will convert the image into HSL space and then modify the saturation channel by changing the gamma using -gamma. Both bri and con are required. The range of values for bri,con,sat are -100 to +100. A value of 0,0[,0] leaves the image unchanged. If the image is grayscale, then it simply processes the image for brightness and contrast. The -g option displays a graph of the piece-wise linear mapping function between the input and output grayscale domains (scaled to the range of 0 to 100). The graph is normally just viewed, but a default parameter in the program can be set to allow it to be saved as outfilename_graph.gif. To end the script, close/quit the graph image.

Arguments: -h or -help ....... displays help information.

Arguments: -g ................ displays graph of intensity mapping function.

Note: -g must come before bri,con[,sat]

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

artificially brightened and contrast lowered
convert lena.jpg -fx ".724u+.310" lena_poor.jpg



Brightness, Contrast, (Saturation) Changes

arguments:
-20,20

arguments:
-10,10,30

arguments:
0,100
full contrast

arguments:
0,-100
zero contrast

slope=1.256
intcp=-.353
break points:
0,0 28,0 100,90

slope=1.121
intcp=-.166
sgamma=1.409
Break Points:
0,0 14,0 100,95

slope=501.000
intcp=-250.000
Break Points:
0,0 49,0 50,100 100,100

slope=0
intcp=.500
Break Points:
0,50 100,50


The second example above from the left does the following:

  • Separates the RBG image into HSB channels and saves the Saturation channel
  • Convert the slope (1.121) and intercept (-.166) into break points (0,0 14,0 100,95)
  • Convert the break points into a LUT image
  • Applies the LUT image to each RGB channel
  • Separates the new RBG image into HSB channels
  • Applies a gamma of 1.409 to the new Saturation channel.
  • Merges the Hue, Saturation and Brightness channels back as an RBG image.

This is equivalent to the following IM commands:

  • convert lena_poor.jpg -colorspace RGB tmp0.jpg
  • convert tmp0.jpg tmplut.jpg -clut tmp0p.jpg
  • convert tmp0p.jpg -colorspace $colormodel -channel R -separate tmp1.jpg
  • convert tmp0p.jpg -colorspace $colormodel -channel G -separate tmp2.jpg
  • convert tmp0p.jpg -colorspace $colormodel -channel B -separate tmp3.jpg
  • convert tmp2.jpg -gamma 1.409 tmp2p.jpg
  • convert tmp0.jpg -colorspace HSB tmp1.jpg -compose CopyRed -composite \
    tmp2p.jpg -compose CopyGreen -composite tmp3.jpg -compose CopyBlue -composite \
    -colorspace RGB lena_b-10_c10_s30.jpg