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.

PLOT


Generates a profile of an image row or column or an image histogram.

Download Script

last modified: December 15, 2018



USAGE: plot [-r row] [-c col] [-p process] [-m mode] [-f format] [-n normalize] [-w width] [-h height] [-t ticspace] [-d density] [-x xplotscale] [-y yplotscale] [-e expansion] [-l] [-b brightness] [-g gridmode] [-s] infile [outfile]
USAGE: plot [-help]

-r ... row .......... row of image to plot; rows start at 0; default=0
-c ... col .......... column of image to plot; cols start at 0;
..................... script will use only one of -r or -c, namely, the last
..................... one specified in the command line; default is -r 0
-p ... process ...... processing type; choices are graph (g) or histogram (h);
..................... default=graph
-m ... mode ......... graph mode; choices are unfilled curve or filled curve;
..................... default=unfilled
-f ... format ....... number of graphs; choices are 1 combined or 3 separate
..................... graphs; default=1
-n ... normalize .... y-axis plot normalization (only for format=3 with
..................... either histogram or graph with yplotscale=minmax);
..................... choices are global (g) or separate (s); default=global
-w ... width ........ width of plot; integer>=0 or "image"; a value of 0 is
..................... the same as "image" (i.e. use the full length of
..................... the row or column); otherwise resize to width supplied;
..................... default=256
-h ... height ....... height of plot; integer>0; default=256
-t ... ticspace ..... tic/grid separation as a percent of plotscales;
..................... 0<integer<100; nominally 20 or 25; default=25
-d ... density ...... thickness (strokewidth) of drawn lines; default=1
-x ... xplotscale ... max value shown on x axes; choices are integer>0 or
..................... "image" (i.e. use the full length of the row or column);
..................... default=image; not used for process=histogram
-y ... yplotscale ... max value shown on y axes; choices are integer>0 or
..................... "image" (2^depth-1; e.g. 255 for 8-bit image) or
..................... "minmax" (image channel minimum and maximum values);
..................... typical values are either 255 (i.e. 8-bit depth) or
..................... 100 (percent); default=image; not used for histogram
-F ... font ......... font name or path to font file and size to use,
..................... e.g. "arial,9"; default=medium
-e ... expansion .... histogram vertical expansion of the count data;
..................... float>=1; default=1
-l .................. log plot on y axis; process=histogram only
-b ... brightness ... background grayscale brightness; 0<=integer<=100;
..................... 0 is black and 100 is white; default=100
-g ... gridmode ..... mode for grid; choices are front, back, none;
..................... default=front
-s .................. show text list of data to terminal
outfile ............. if not specified, outfile will be named from the
..................... infile name with _graph.gif appended

PURPOSE: To generates a profile of an image row or column or an image histogram.

DESCRIPTION: PROFILE generates an output image which is composed of the separate profiles from each channel of the input image for a given row or column. Alternately the output will the histogram of each channel of the image. If the image is CMYK, then it must be converted to RGB or sRGB prior to running the script.

ARGUMENTS:

-r row ... ROW is the row of image to plot. Rows start at 0. The default=0.

-c col ... COL is the column of image to plot. Rows start at 0. The default=0.

Note, the script will use only one of -r or -c, whichever is the last one specified in the command line. The default is to use -r 0.

-p process ... PROCESS is the processing type. Choices are: graph (g) or histogram (h). When mode=graph, the xplotscale and yplotscale are user specified. When mode=histogram, xplotscale=255 (8-bit data number of bins) and yplotscale is the largest count from all bins. The default=graph.

-m mode ... MODE of graph/histogram. The choices are unfilled (u) or filled (f). Unfilled is simple curve. Filled is curve colored to x-axis. The default=unfilled.

-f format ... FORMAT is the number of graphs. The choices are: 1 (for one combined plot) or 3 (for three separate stacked plots). When format=3, the 3 graphs will be trimmed and padded before stacking. Therefore, the width will be a litte smaller than specified and the height will be little smaller than 3x the specified height. The default=1.

-n normalize ... NORMALIZE is the y-axis plot normalization. This is only useable when format=3 combined with either histogram or with graph plus yplotscale=minmax. The choices are global (g) or separate (s). The default=global. Global means to use the maximum count or maximum and minimum graylevel from r,g,b channels for normalizing the y-axis of each plot. Separate means to use each channels maximum count or maximum and minimum graylevel for normalizing its own y-axis in the corresponding plot. The default=global.

-w width ... WIDTH of plot in pixels. Values are integer>=0 or "image". A value of 0 is the same as "image" (i.e. use the full length of the row or column); otherwise resize to width supplied. The default=256.

-h height ... HEIGHT of plot in pixels. Values are integer>0. The default=256.

-t ticspace ... TICSPACE is the tic/grid separation as a percent of the plotscales. Values are 0<integer<100. Nominal values are either 20 or 25. The default=25.

-d density ... DENSITY is the thickness (strokewidth) of drawn lines. Values are either 1 or 2. The default=1.

-x xplotscale ... XPLOTSCALE is the max value shown on x axes. Values are integer>0 or "image" (i.e. use the full length of the row or column). The default=image. Note this is only relevant to process=graph. For histograms, this is 255 (8-bit image depth).

-y yplotscale ... YPLOTSCALE is the max value shown on y axes. The choices are integer>0 or "image" (2^depth-1; e.g. 255 for 8-bit image) or "minmax" (image channel minimum and maximum graylevel values). Typical values are either 255 (i.e. 8-bit depth) or 100 (percent). The default=image. Note this is only relevant to process=graph. For histograms, the max value comes from the histogram counts.

-F font ... FONT name or path to font file and size to use. For example, "arial,9". The default=medium.

-e expansion ... EXPANSION is the histogram count expandion on the graph, so that low counts can be amplified at the expense of saturating high counts. Values are floats greater than or equal to one. The default=1.

-l .. use LOG base 10 plot on y (count) axis. Only for process=histogram

-b brightness ... BRIGHTNESS is the background grayscale brightness. Values are 0<=integer<=100. 0 is black and 100 is white. The default=100.

-g gridmode ... GRIDMODE is the grid setting. The choices are: front (f), back (b), none (n). The default=front.

-s ... SHOW text list of data to terminal

REQUIREMENTS: Needs GNUPLOT (4.6). I cannot guarantee it will work on older versions, but it may. Also libgd is needed by GNUPLOT for proper rendering of fonts in PNG output. The GDFONTPATH environment variable should then be set to your fonts location and that put in your PATH. The script may also work without libgd by setting the font argument to a specific font and size or to "". But that has not been tested.

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


Example 1 -- Graph (Profile)

Original

Arguments:
-p graph -m unfilled -f 1 -t 20 -d 1 -x 100 -y 100

Arguments:
-p graph -m unfilled -f 1 -t 20 -d 1 -x 255 -y 255

Arguments:
-p graph -m unfilled -f 1 -t 20 -d 2 -x 255 -y 255

Arguments:
-p graph -m unfilled -f 1 -t 25 -d 1 -x 255 -y 255

Arguments:
-p graph -m unfilled -f 3 -t 20 -d 1 -x 255 -y 255

Arguments:
-p graph -m filled -f 3 -t 20 -d 1 -x 255 -y 255



Example 2 -- Graph (Profile)

Original

Arguments:
-p graph -m unfilled -f 1 -w image -h 256 -t 20 -d 1 -x image -y 255

Arguments:
-p graph -m unfilled -f 1 -w image -h 256 -t 10 -d 1 -x image -y 256

Arguments:
-p graph -m unfilled -f 1 -w 256 -h 256 -t 20 -d 1 -x 100 -y 100

Arguments:
-p graph -m filled -f 1 -w image -h 256 -t 20 -d 1 -x image -y 255 -b 100

Arguments:
-p graph -m filled -f 1 -w image -h 256 -t 20 -d 1 -x image -y 255 -b 75

Arguments:
-p graph -m filled -f 1 -w image -h 256 -t 20 -d 1 -x image -y 255 -b 50

Arguments:
-p graph -m filled -f 1 -w image -h 256 -t 20 -d 1 -x image -y 255 -b 0



Example 3 -- Graph (Profile)

Original

Arguments:
-r 0 -p graph -m unfilled -f 1 -w 256 -h 256 -t 20 -d 2 -x 100 -y 256

Arguments:
-r 20 -p graph -m unfilled -f 1 -w 256 -h 256 -t 20 -d 2 -x 100 -y 256

Arguments:
-r 40 -p graph -m unfilled -f 1 -w 256 -h 256 -t 20 -d 2 -x 100 -y 256



Example 4 -- Histogram

Original

Arguments:
-p histogram -m unfilled -f 1 -w 256 -h 256 -t 20 -d 2 -b 100

Arguments:
-p histogram -m filled -f 1 -w 256 -h 256 -t 20 -d 2 -b 100 -g front

Arguments:
-p histogram -m filled -f 1 -w 256 -h 256 -t 20 -d 2 -b 75 -g front

Arguments:
-p histogram -m filled -f 1 -w 256 -h 256 -t 20 -d 2 -b 75 -g back

Arguments:
-p histogram -m filled -f 1 -w 256 -h 256 -t 20 -d 2 -b 75 -g none

Arguments:
-p histogram -m filled -f 1 -w 256 -h 256 -t 20 -d 2 -b 0 -g front

Arguments:
-p histogram -m unfilled -f 3 -w 256 -h 256 -t 20 -d 2 -b 100 -n global

Arguments:
-p histogram -m unfilled -f 3 -w 256 -h 256 -t 20 -d 2 -b 100 -n separate

Arguments:
-p histogram -m filled -f 3 -w 256 -h 256 -t 20 -d 2 -b 100 -n global

Arguments:
-p histogram -m filled -f 3 -w 256 -h 256 -t 20 -d 2 -b 100 -n separate



Example 5 -- Histogram Enlarged

Original

Arguments:
-p histogram -m filled -f 1 -w 512 -h 512 -t 20 -d 2 -b 0



What the script does is as follows:

  • The script crops a row or column of the image or generates a textual histogram
  • It then feeds the data to GNUPLOT to generate the output image

See the script for further details