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

HISTOG


Generates an output image which is composed of the histograms from each channel of the input image

Download Script

last modified: April 25, 2015



USAGE: histog [-l labels] [-c number] [-rgb] infile [outfile]
USAGE: histog [-h or -help]

-l ...... labels .. quoted comma and/or space delimited list of labels for histogram:
................... 1, 3 or 4 values such as: "Grayscale" or "Red Green Blue"
................... or "Hue Saturation Lightness"
................... or "Cyan Magenta Yellow Black"
................... or just "4" to distinguish CMYK from all the 3 channel
................... formats, but leave the label off
-c ...... number .. color scheme number: 1, 2, 3 or 4; default=1
-rgb .............. convert infile to RGB before generating the histogram
outfile ........... if not specified, outfile will be named from the infile name

PURPOSE: To generate an output image which is composed of the histograms from each channel of the input image.

DESCRIPTION: HISTOG generates an output image which is composed of the separate histograms from each channel of the input image. Label names may be supplied for each channel, if desired. However, each channel histogram will display its corresponding min, max, mean, and standard deviation values. There is also an option for four different colorschemes for the histogram to optimize it presentation. Furthermore, the infile may be automatically converted from whatever colorspace it is in to RGB before generating the histogram.

ARGUMENTS:

-l labels indicates to put label names on the histogram for each channel, where labels is a quoted comma and/or space delimited list of labels for the histogram with 1, 3 or 4 values such as: "Grayscale" or "Red Green Blue" or "Hue Saturation Lightness" or "Cyan Magenta Yellow Black" or just "4" to distinguish CMYK from all the 3-channel formats, but leave the label off. Note that if the number of labels provided is 4 or the option is specified as -l "4", then a non-4-channel image will be converted to CMYK before generating the histogram.

-c number indicates the color scheme to use. The choices are:
1 histogram in color; background black; border white
2 histogram in color; background white; border black
3 histogram in white; background black; border color
4 histogram in black; background white; border color
where color is red, green and blue for 3 channel infile and color is cyan, magenta, yellow, black/white for 4 channel infile

-rgb indicates to convert the image from whatever colorspace it has to RGB before generating the histogram

If no outfile is specified, then outfile will be named as infilename_hist.gif, where the suffix has been removed from infile to generate infilename.

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


RGB Histograms

zelda2_redist.jpg

arguments:
-l "Red Green Blue"
(-c 1 -l "Red Green Blue")

arguments:
-c 2 -l "Red Green Blue"

arguments:
-c 3 -l "Red Green Blue"

arguments:
-c 4 -l "Red Green Blue"



HSL Histograms
(convert zelda2_redist.jpg -colorspace HSL zelda2_redist_hsl.jpg)

zelda2_redist_hsl.jpg

arguments:
-l "Hue Sat Light"
(-c 1 -l "Hue Sat Light")

arguments:
-c 2 -l "Hue Sat Light"

arguments:
-c 3 -l "Hue Sat Light"

arguments:
-c 4 -l "Hue Sat Light"



CMYK Histograms
(convert mandril.jpg -equalize -colorspace CMYK mandril_eq_cmyk.jpg)

mandril_eq_cmyk.jpg

arguments:
-l "Cn Ma Yw Bk"
(-c 1 -l "Cn Ma Yw Bk")

arguments:
-c 2 -l "Cn Ma Yw Bk"

arguments:
-c 3 -l "Cn Ma Yw Bk"

arguments:
-c 4 -l "Cn Ma Yw Bk"



What the script does is as follows:

  • Separate the channels in the image
  • Create a grayscale histogram image for each channel
  • Add an appropriately colored border around each histogram image
  • Add appropriately colored labels and statistics annotation
  • Merge all the image histograms into a single column image
  • Resize the merged image to half size

This is equivalent to the following IM commands for the case of
an RGB image with arguments -c 1 -l "Red Green Blue"

  • convert $infile -channel R -separate $tmp0
  • convert $infile -channel G -separate $tmp1
  • convert $infile -channel B -separate $tmp2
  • convert $tmp0 histogram:- | convert - -fill red \
    -opaque white -bordercolor white -border 10x30 \
    -font ArialB -pointsize 20 -draw "text 5,22 'Red'" $tmp0
  • convert $tmp1 histogram:- | convert - -fill green \
    -opaque white -bordercolor white -border 10x30 \
    -font ArialB -pointsize 20 -draw "text 5,22 'Green'" $tmp1
  • convert $tmp2 histogram:- | convert - -fill blue \
    -opaque white -bordercolor white -border $bordersize \
    -font ArialB -pointsize 20 -draw "text 5,22 'Blue'" $tmp2
  • convert $tmp0 $tmp1 $tmp2 -append -resize 50x50% $outfile