2

I recently tested the following algorithm for determining the "colorfulness" of an image by David Haslera and Sabine Susstrunk, which is implemented in Python here. However, I noticed something interesting about the performance of this algorithm on some test images.

The colorfulness metric for a 3x1, 8-bit-per-channel RGB image of a single red, green, and blue pixel seems to be as high as it gets (feel free to prove me wrong, that's simply what I've observed).

Here's what I mean. This image has a colorfulness of 206.52:

enter image description here

while this 4x4 image has a colorfulness of 185.13:

enter image description here

while a pure black/white image has a colorfulness of 0, for comparison. (These values are calculated when the levels for each channel are stored as integers between 0 and 255, inclusive).

Intuitively, I would consider the second image to be far more "colorful" than the first, but this is not the result given by that algorithm.

Essentially, I'm looking for some other measurement that corresponds to the variation in colors that appear in an image. However, I'm not really sure what that would look like mathematically, especially since images are represented as distinct red, blue, and green channels.

One idea might be to simply keep a tally of the number of distinct pixels in an image (add one to the tally every time a pixel of a new color is seen), but this does not do a good job when there are many dark (yet different) pixels that are virtually indistinguishable. It also wouldn't do a good job if there are a lot of slightly different pixels of all approximately the same color. Yet the algorithm in that paper seems to break my intuition when testing an extreme case like this one.

Does anybody know of other metrics that might give a more accurate representation of the variety of colors that appear in an image? Or can you perhaps propose one yourself? I'm open to any and all ideas.

jippyjoe4
  • 742
  • 4
  • 19
  • 2
    Colourfulness is defined by the CIE as the "attribute of a visual perception according to which the perceived colour of an area appears to be more or less chromatic". Your 3 RGB samples have maximum chroma for a given RGB colourspace, it should not be surprising that an image full of them has more colourfulness than an image with samples with less chroma. – Kel Solaar Apr 13 '19 at 08:12

1 Answers1

0

My recommendation (not from any authority) would be to convert the image to HSV and then construct a histogram over a certain irregular set of bins. One simple scheme would be

  1. three gray bins (s<1/3): “black” (v<1/3), “gray” (v<2/3), and “white”
  2. six tone bins (s<2/3): for each of three primary colors (the thirds of h), “tint” (v>1/2) and “shade”
  3. twelve pure bins: the same v distinction for each of six hues

This very roughly approximates the perceived distance between colors; other numbers of bins can be easily had by adjusting the numbers of the various subdivisions.

Normalize the histogram to obtain an empirical discrete probability distribution; compute its entropy and normalize by dividing by the theoretical maximum (log N for N bins). An image with an equal number of pixels in each bin will score 1; any solid color will score 0.

There are of course pathological cases, like an image comprising just two distinct pixel values that lie just on a boundary between bins. Such an image will score log 2/log N, and the idea can be extended to 8 bins that meet at a shared corner. It might be worthwhile to add a small amount of noise to the image (or to copies of it merged with the original) to reduce the likelihood of such anomalies.

To consider an all-red image (slightly) more colorful than an all-gray one, you can introduce a “test pattern” of grays into the histogram (and adjust the normalization of the entropy to account for the increased minimum and reduced maximum values). The test pattern should be comparable in size to the image.

Davis Herring
  • 24,173
  • 3
  • 25
  • 55