If I want to measure entropy of an image how should I do it?

My aim is to ignore things like tree leaves moving in the wind with my C# desktop application.

I know matlab has this functionality but I cannot see it within Emgu which is what I am using.

I got as far as finding 'Shannon Entropy' is probably the way forward but I am stuck as to how to implement it in C# speficially for images.


2 Answers 2


You have probably found out that entropy of a discrete random variable $X$ is defined by

$$H(X)=-\sum_{i=1}^N p_i\log_2 p_i\tag{1}$$

where $N$ is the size of the alphabet (i.e. the number of possible values of $X$), and $p_i$ is the probability that $X$ assumes the $i^{th}$ value of the alphabet. The entropy $H(X)$ can be interpreted as the average information obtained by observing $X$.

In the case of an image, you need to estimate the values $p_i$. You can do this by computing the histogram of the image: define a number $N$ of bins of (equal) grayscale ranges and simply count the number of pixels per bin. Dividing the number of pixels per bin by the total number of pixles gives you an estimate of $p_i$. Then you just need to plug these values into (1) and you get the entropy of the image.

  • $\begingroup$ Hi, thats for your response. I did come across that formulae (1) on my searching travels. OK, I can take an image, grayscale it, compute the histogram of it which will return me 256 bins each with a number of pixel counts within each bin. Now, to understand the variables I say 'X' is the total number of pixels of that image. N is the number of bins ~ 256. So is 'i' my measuring axis? $\endgroup$ Mar 23, 2014 at 13:22
  • 1
    $\begingroup$ The variable $X$ is the grayscale value, and $i$ is the bin index. So $p_i$ is the probability that a pixel of your image has a gray-scale value corresponding to bin $i$. $\endgroup$
    – Matt L.
    Mar 23, 2014 at 13:25
  • $\begingroup$ Hi, thanks again for your time. It is educational and much appreciated. I 'think' i understand what you just stated. But, I need help to apply this practically to my objective which is discerning whether the motion movement i detect within an image has a high atrophy 'rating' (i.e. trees, bushes, leaves etc) as opposed to a solid object like a car/person. Would I isolate the pixels with the ROI and enumerate through each individual pixel value using that formulate to rate the 'randomness' of the pixel changes? $\endgroup$ Mar 23, 2014 at 13:31
  • $\begingroup$ I think we're now discussing different questions. I tried to explain how to measure the entropy of an image, as asked in your original question. Maybe it would make sense to formulate a new question concerning the overall problem and the algorithm you have in mind. $\endgroup$
    – Matt L.
    Mar 23, 2014 at 15:02
  • $\begingroup$ Hi, you did explain entropy to me and i am very grateful. I thought I had explained in my question what I was try to achieve. "My aim is to ignore things like tree leaves moving in the wind with my C# desktop application." i cannot think of another way to express that. But i will give you tick as you did explain entropy to me. Thanks :) $\endgroup$ Mar 23, 2014 at 16:16

"If I want to measure entropy of an image how should I do it?"

An excellent question and one that, as of September 2016, has a simple and directly computable answer.

The question is answered in a recent Stack Exchange correspondence:


A detailed explanation is presented in the recent arXiv preprint:


Note that the preprint includes a link to GitHub experimental sourcecode.

  • $\begingroup$ The author of that answer confuses entropy and information -- an image is a signal, it can have information, not entropy. Only sources have entropy (unless there's a different use of the term in image processing). $\endgroup$
    – MBaz
    Dec 8, 2016 at 2:31
  • $\begingroup$ Hi both, thanks for the link and yes i have wised up now to the error of my question. $\endgroup$ Dec 8, 2016 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.