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

MOMENTS


Compute shift, scale and rotation invariant image moments as well as elliptical shape descriptors

Download Script

last modified: September 26, 2017



USAGE: moments [-z] infile
USAGE: moments [-h or -help]

-z ... Replaces NAN or DBZ with 0; default shows NAN and/or DBZ

PURPOSE: To compute shift, scale and rotation invariant image moments as well as elliptical shape descriptors.

DESCRIPTION: ENTROPY computes Hu and Maitra shift, scale and rotation invariant image moments as well as elliptical shape descriptors. Currently this script is limited to grayscale images. If the input is not grayscale, it will be converted to grayscale. The list of moments and shape descriptors is sent to the terminal.

ARGUMENTS:

-z ... replace (not a number) NAN (from square root of negative value) or (divide by zero) DBZ with 0 in Maitra moments. The default is to show NAN and/or DBZ.

REFERENCES:
http://en.wikipedia.org/wiki/Image_moments
http://www.via.cornell.edu/ece547/text/survey.pdf

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


Image And List of Moments

Original Image

Image Creation Parameters

Moment List and
Ellipse Shape Descriptors

 

zelda3_moments.txt

X Center of Mass (XCOM) = 69.13896179
Y Center of Mass (YCOM) = 57.86068726
Ellipse Angle (radians) = 0.3220438063
Ellipse Angle (degrees) = 18.4517498
Ellipse Semi-Major Axis = 76.38931274
Ellipse Semi-Minor Axis = 71.42292786
Ellipse Eccentricity = 0.2549786866
Ellipse Intensity = 134.8245239

White Ellipse:
X,Y Center: 100,100
Semi-Major Axis: 50
Semi-Minor Axis: 25
Rotation: 0 degrees

ellipse_moments.txt

X Center of Mass (XCOM) = 100.0000687
Y Center of Mass (YCOM) = 100.0000229
Ellipse Angle (radians) = -1.268604365e-06
Ellipse Angle (degrees) = -7.268567424e-05
Ellipse Semi-Major Axis = 50.3578949
Ellipse Semi-Minor Axis = 25.35848236
Ellipse Eccentricity = 0.7045813203
Ellipse Intensity = 254.9430695

White Rectangle:
X,Y Center: 138,138
Width Axis: 50
Height: 25
Rotation: 30 degrees

rectangle_moments.txt

X Center of Mass (XCOM) = 137.5
Y Center of Mass (YCOM) = 137.5
Ellipse Angle (radians) = 0.5235797763
Ellipse Angle (degrees) = 29.9989109
Ellipse Semi-Major Axis = 57.73477936
Ellipse Semi-Minor Axis = 28.87569618
Ellipse Eccentricity = 0.707005024
Ellipse Intensity = 243.4593353



What the script does is as follows:

  • Computes the raw image moments
  • Computes the central image moments using some of the raw image moments
  • Computes the normalized central image moments
  • Computes the Hu invariant moments from the normalized central image moments
  • Computes Maitra invariant moments from the Hu invariant moments