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.

MAXIMA


Locates one or more local maxima in a grayscale image

Download Script

last modified: December 15, 2018



USAGE: maxima [-r rad ] [-n num] [-t thresh] [-u units] [-d dist] [-m metric] [-g graphic] infile [outfile]
USAGE: maxima [-h or -help]

-r ... rad ...... x,y radii for masking out peaks; integer>0;
................. one value will be used for both dimensions;
................. default=5;
-n ... num ...... stopping number of maxima; integer>0; default=1
-t ... thresh ... graylevel (maxima amplitude) stopping threshold;
................. integer>0; default=ignore argument
-u ... units .... units for graylevel threshold; choices are:
................. percent (p), raw (r), 8bit (8); default=percent
-d ... dist ..... pixel distance for stopping; integer>0;
................. default=ignore argument
-m ... metric ... compare metric; any valid IM metric; default=rmse
-g .............. display intermediate images

PURPOSE: To locate one or more local maxima in a grayscale image.

DESCRIPTION: MAXIMA locates one or more local maxima in a grayscale image. It does this by finding the highest graylevel value and its location (via the compare function). Then it draws a black circle (ellipse) at that location and repeats the process. The process can be stopped by any combination of more than some number of maxima, the graylevel (amplitude) at a maxima is lower than some threshold value or the distance between any two maxima are less than some spacing distance. Each maxima location and its graylevel will be returned to the terminal. If the input is not grayscale it will be converted to grayscale.

ARGUMENTS:

-r rad ... RAD are the x,y radii for masking out peaks. Values are integers>0. One value will be used for both dimensions. The default=5.

-n num ... NUM is the number of maxima used to stop the iterative process. Stopping occurs when the iteration exceeds the num value. Values are integers>0. The default=1. Note that a number must be set even if one uses thresh.

-t thresh ... THRESH is the graylevel (maxima amplitude) used as the stopping threshold. Stopping occurs when a maxima graylevel is less than thresh. Values are integers>0. The default=ignore this argument.

-u units ... UNITS for the graylevel threshold. Choices are: percent (or p), raw (or r), 8bit (or 8). The default=percent.

-d dist ... DISTANCE in pixels between maxima used for stopping. Stopping occurs when any two maxima are too close together, i.e. less than dist. Values are integers>0. The default=ignore this argument.

-m metric ... METRIC is the compare metric used to locate the maxima. Any valid IM metric may be used. The default=rmse. Only needed for Imagemagick versions less than 6.8.6-10.

-g ... Indicates to display the intermediate masked images.

An optional output image may be specified which will be the input image with the masked areas showing where the maxima are located.

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 -- Two Proper Maxima

Creation of Example

Image 1

Image 2

Processing Commands
To Get The Input Image
for The Maxima Script

compare -metric rmse -subimage-search
image1 image2 compare_result

Input
(compare_result-1)

Arguments:
-r 5 -n 2
or
-r 5 -n 10 -t 80 -d 15

Maxima Locations

156,22 gray=65535,255,100%
76,24 gray=56026,218,85.4902%



Example 2 -- Two Proper Maxima -- Threshold Too Low

Creation of Example

Image 1

Image 2

Processing Commands
To Get The Input Image
for The Maxima Script

compare -metric rmse -subimage-search
image1 image2 compare_result

Input
(compare_result-1)

Arguments:
-r 5 -n 10 -t 70 -d 15

Maxima Locations

156,22 gray=65535,255,100%
76,24 gray=56026,218,85.4902%
9,152 gray=52171,203,79.6078%
17,204 gray=51400,200,78.4314%
29,214 gray=51400,200,78.4314%



Example 3 -- Six Proper Maxima -- Circular Masking

Creation of Example

Image 1

Image 2

Processing Commands
To Get The Input Image
for The Maxima Script

compare -metric rmse -subimage-search
image1 image2 compare_result

Input
(compare_result-1)

Arguments:
-r 5 -n 10 -t 90 -d 15

Maxima Locations

197,10 gray=65535,255,100%
57,63 gray=65535,255,100%
180,63 gray=65535,255,100%
196,116 gray=65535,255,100%
19,169 gray=65535,255,100%
175,275 gray=65535,255,100%



Example 4 -- Six Proper Maxima -- Elliptical Masking

Creation of Example

Image 1

Image 2

Processing Commands
To Get The Input Image
for The Maxima Script

compare -metric rmse -subimage-search
image1 image2 compare_result

Input
(compare_result-1)

Arguments:
-r 3,10 -n 10 -t 90 -d 15

Maxima Locations

197,10 gray=65535,255,100%
57,63 gray=65535,255,100%
180,63 gray=65535,255,100%
196,116 gray=65535,255,100%
19,169 gray=65535,255,100%
175,275 gray=65535,255,100%



Example 5 -- Seven Proper Maxima

Creation of Example

Image 1

Image 2

Processing Commands
To Get The Input Image
for The Maxima Script

compare -metric rmse -subimage-search
image1 image2 compare_result

Input
(compare_result-1)

Arguments:
-r 5 -n 10 -t 80 -d 15

Maxima Locations

234,35 gray=65535,255,100%
32,129 gray=61680,240,94.1176%
305,167 gray=61166,238,93.3333%
234,219 gray=60652,236,92.549%
4,254 gray=60138,234,91.7647%
74,61 gray=59881,233,91.3725%
17,360 gray=58853,229,89.8039%



What the script does is as follows (for any channel):

  • Finds the largest graylevel value in the image
  • Uses compare to locate that graylevel
  • Draws a small black mask about that location
  • Repeats the above until one of the stopping thresholds is met