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.

MEDIAN


Computes the median value of an image.

Download Script

last modified: December 15, 2018



USAGE: median [-p processing] infile
USAGE: median [-h or -help]

-p ... processing ... processing of images; choices are: gray (convert
..................... to grayscale first), global (append all channels
..................... into one grayscale image) or all (process each
..................... channel separately); default=gray

PURPOSE: To compute the median value of an image.

DESCRIPTION: MEDIAN computes the median value of an image. The median is that graylevel for which half the pixels in the image have larger values and half have smaller values. In other words, it is the graylevel that splits the histogram into two equal counts. The user may choose either to process the image to grayscale, to append all the channels into one grayscale image or process each channel separately.

ARGUMENTS:

-p processing ... PROCESSING of the images. The choices are: gray (convert to grayscale first), global (append all channels into one grayscale image) and all (process each channel separately). The default=gray.

NOTE: This script will process only the first frame/page of a multiframe or multipage image.

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


Input Image

Arguments:

Median

-p gray

gray: 146

-p global

global: 154

-p all

red: 173
green: 142
blue: 127



What the script does is as follows:

  • Generates the textual histogram
  • Finds the bin that separates the counts such that half are above and half below

See the script for actual code details.