# Entropy or co-occurrence matrix to compute the randomness of gray scale images?

I have an algorithm that outputs gray scale images (not normalized). These images often contain a lot of random noise and sometimes also contain spatial structures.

I would like to have some kind of measurement to compute how random an image is. Random images should have a low score whereas images with structures should score higher. Ideally the score should be in an range so that I can compare images with each other. Something like:

• 0 = image consists purely of random noise
• 1 = image contains clear and sharp structures (whatever that would mean)

The first thing that came into my mind was computing the Shannon entropy of each image but I ended up with a lot of questions:

• What is the correct way to normalize the images or more specifically, how many gray levels should the image have? 8 or 256 or something else?

• Which base of the logarithm should I use? Common is 2 but also $$e$$ and 10.

• Do I compute the entropy for the whole image or do I compute the entropy of patches of size $$m \times m$$ around a pixel $$(i,j)$$ and sum up the entropy afterwards?

• Does Shannon's entropy really take spatial structures into account? It seems to me, that the definition only looks locally at a single pixel. Is that right?

In some articles about Shannon's entropy the co-occurrence matrix was mentioned which can measure the texture of the image.

• Is that a better way to go for my problem? How can I use this for my purpose?

• I read that this method provides some statistics I have problems to understand. Articles about co-occurrence matrices mentioned Contrast, Correlation, Energy and Homogeneity as a tool to analyze an image. Which one should I consider for a distinction between images that with a lot of random noise and images with sharp structures?

• Have you examined this answer yet? It seems to address most of your issues quite well with respect to binary 2D datasets/images. The essential idea is to examine local entropy at a series of different scales. It might help to edit to re-focus your question on the additional issues introduced by having other than binary data. – EdM Jul 24 '18 at 15:36

There are the NIST SP 800-90 series of test for randomness (with source), specifically:

Discrete Fourier Transform (Spectral) Test

Description: The focus of this test is the peak heights in the discrete Fast Fourier Transform. The purpose of this test is to detect periodic features (i.e., repetitive patterns that are near each other) in the tested sequence that would indicate a deviation from the assumption of randomness.

2nd Question:

Is that a better way to go for my problem? How can I use this for my purpose?

There's a StackOverflow Q&A on feature detection/extraction: Difference between Feature Detection and Descriptor Extraction and DSP.SE's Purpose of image feature detection and matching, while not calculating randomness (as the prior example does) it can classify the features in case there's something you want to exclude.

There's the power of Cloud Computing, for example: Google's Cloud Vision API, again this won't say if "it is random" but if it isn't random it will tell you what is in the photo. It's quick and using very few of your CPU cycles to obtain the answer.

Once you know 'what and where' you can subtract it from the image and test for randomness on the remainder.

You are likely going to be best off with some kind of compression based approach - in particular, since you don't have a clear idea of the scale at which to measure things.

Let $C(\cdot)$ be a compression function. Generate a purely random image (i.e., pure noise), $N$. Then, one can use the ratio $\frac{C(A)}{C(N)}$. to capture how much randomness is in $A$ relative to the pure noise.

• Can you please be more specific about the compression function? What would an approach in python for such a function? – recipe_for_disaster Jul 26 '18 at 11:06
• You should likely be looking at a wavelet based approach which can capture information at different scales - e.g. see pdfs.semanticscholar.org/10bc/… – MotiN Jul 26 '18 at 11:55