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.

SSIM


Computes the structural similarity metric between two equal sized images and its complement structural dissimilarity metric.

Download Script

last modified: July 03, 2020



USAGE: ssim [-r radius] [-s sigma] [-f format] [-m method] [-p precision] [-v vp] infile1 infile2 [outfile]
USAGE: ssim [-h or -help]

-r ... radius ...... RADIUS of window used to do local gaussian blurring
.................... integer>0; default=5
-s ... sigma ....... SIGMA of gaussian blurring; float>0; default=1.5
-f ... format ...... FORMAT is the output image format, if the outfile is
.................... specified; choices are: ssim or dssim; default=ssim
-m ... method ...... METHOD of computing the variance and covariance; choices are:
.................... 1 or 2; default=1
-p ... precision ... PRECISION is the number of decimal figures in the
.................... metric to show; integer>=0; default=3
-v ... vp .......... VP is the virtual pixel method; choices are edge, mirror or off;
.................... default=edge

PURPOSE: To compute the structural similarity metric between two equal sized images.

DESCRIPTION: SSIM computes the structural similarity metric between two equal sized images and its complement structural dissimilarity metric (DSSIM). The DSSIM=(1-SSIM). An optional output image may be specified which can show the SSIM or DSSIM image. The latter is just the -negate of the former. The SSIM process computes the ssim metric within 11x11 local regions at every pixel with Gaussian weighting. Then it computes the average ssim value across the resulting ssim image and all channels and reports that value.

ARGUMENTS:

-r radius ... RADIUS of window used to do local gaussian blurring. Values are integers>0. The default=5. The square dimensions of the window will be 2*radius+1.

-s sigma ... SIGMA of gaussian blurring. Values are floats>0. The default=1.5.

-f format ... FORMAT is the output image format, if the outfile is specified. The choices are: ssim (s) or dssim (d). The default=ssim

-m method ... METHOD of computing the variance and covariance. choices are: 1 or 2. Method 1 is var=ave(X^2)-ave(X)*ave(X). Method 2 is var=ave((X-ave(X))^2). Method 1 is used by all SSIM code that I can find, but may suffer from catastrophic cancellation. See https://en.wikipedia.org/wiki/Variance

-p precision ... PRECISION is the number of decimal figures in the metric to show. Values are integers>0. The default=3

-v vp ... VP is the virtual pixel method. Choices are edge, mirror or off. The default=edge. If off is used, the resulting image will be cropped smaller by 2*floor((window-1)/2) in each width and height.

REFERENCES:
http://en.m.wikipedia.org/wiki/SSIM
https://en.wikipedia.org/wiki/Variance
https://en.wikipedia.org/wiki/Covariance
http://www.cns.nyu.edu/pub/eero/wang03-reprint.pdf
http://www.cns.nyu.edu/~lcv/ssim/

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

NOTE: Without HDRI enabled, the script will be slow due to the use of -fx.

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

Images


Input Image 1

Input Image 2

SSIM Image

SSIM / DSSIM Metrics

ssim=1 dssim=0

ssim=0.702 dssim=0.298

ssim=0.67 dssim=0.33

ssim=0.391 dssim=0.609



What the script does is as follows:

  • Computes the SSIM Metric according to the references
  • Returns the SSIM metric and optional SSIM image

See the script for actual code details.