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

COLORFULNESS


Computes a metric that represents the colorfulness of an image

Download Script

last modified: September 26, 2017



USAGE: colorfulness infile
USAGE: colorfulness [-h or -help]

-h or -help .... Displays help information

PURPOSE: To compute a metric that represents the colorfulness of an image.

DESCRIPTION: COLORFULNESS computes a metric that represents the colorfulness of an image. Values range between 0 and about 81. When normalized, then the values are modified by a scaling factor of (1/81) so they range from 0 to 1. Both values are presented as "unnormalized (normalized)". The largest colorfulness appears to correspond to equal parts red, green and blue.

References:
http://www.pyimagesearch.com/2017/06/05/computing-image-colorfulness-with-opencv-and-python/
https://infoscience.epfl.ch/record/33994/files/HaslerS03.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 Vs. Colorfulness Vs. Average Saturation

Original Image

Colorfulness

Average Saturation
Range: 0 to 1

0 (0)

0

0

0

10.4686 (0.129242)

0.292073

17.4206 (0.215069)

0.4168

19.9562 (0.246373)

0.120912

20.0449 (0.247468)

0.242725

23.1143 (0.285362)

0.515007

23.4763 (0.289831)

0.284321

24.3854 (0.301054)

0.521614

24.4009 (0.301246)

0.551431

31.0724 (0.38361)

0.338277

33.5412 (0.414089)

1

43.6767 (0.539219)

0.684382

69.4047 (0.856848)

0.996429

80.6267 (0.995391)

1



Saturation Vs. Colorfulness

Original Image

Saturation Vs. Colorfulness

Iterate saturation from 0 to 100 in steps of 10:
convert rgb100.png -modulate 100,$sat,100 miff:- | colorfulness -

saturation=0 colorfulness=0 (0)
saturation=10 colorfulness=7.94012 (0.0980262)
saturation=20 colorfulness=16.1978 (0.199973)
saturation=30 colorfulness=24.4557 (0.301922)
saturation=40 colorfulness=32.3959 (0.399949)
saturation=50 colorfulness=40.336 (0.497975)
saturation=60 colorfulness=48.5938 (0.599923)
saturation=70 colorfulness=56.8517 (0.701873)
saturation=80 colorfulness=65.1093 (0.803819)
saturation=90 colorfulness=72.7319 (0.897925)
saturation=100 colorfulness=80.9897 (0.999873)



What the script does is as follows:

  • Computes the Colorfulness Metric as follows:
  • rg = R - G
  • yb = 0.5*(R + G) - B
  • compute mean^2 of rg and yb
  • compute std^2 of rg and yb
  • compute mean as sqrt of sum of mean^2 for rg and yb
  • compute std as sqrt of sum of std^2 for rg and yb
  • compute metric as 100*(std + 0.3*mean)

This is equivalent to the following IM commands for a graylevel image:

  • convert -quiet "$infile" -alpha off +repage $tmpA1
  • convert $tmpA1 -colorspace sRGB -channel rg -separate +channel -compose difference -composite $tmpRG1
  • convert $tmpA1 -colorspace sRGB -channel rgb -separate +channel \
    \( -clone 0 -clone 1 -evaluate-sequence mean \) \
    \( -clone 2 \) -delete 0-2 \
    -compose difference -composite $tmpYB1
  • meanRGsq=`convert $tmpRG1 -format "%[fx:mean*mean]" info:`
  • meanYBsq=`convert $tmpYB1 -format "%[fx:mean*mean]" info:`
  • mean=`convert xc: -format "%[fx:sqrt($meanRGsq+$meanYBsq)]" info:`
  • stdRGsq=`convert $tmpRG1 -format "%[fx:standard_deviation*standard_deviation]" info:`
  • stdYBsq=`convert $tmpYB1 -format "%[fx:standard_deviation*standard_deviation]" info:`
  • std=`convert xc: -format "%[fx:sqrt($stdRGsq+$stdYBsq)]" info:`
  • colorfulness=`convert xc: -format "%[fx:100*($std + 0.3*$mean)]" info:`