Monday, November 6, 2017

c# - Entropy of an image


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.



Answer



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.


No comments:

Post a Comment

periodic trends - Comparing radii in lithium, beryllium, magnesium, aluminium and sodium ions

Apparently the of last four, $\ce{Mg^2+}$ is closest in radius to $\ce{Li+}$. Is this true, and if so, why would a whole larger shell ($\ce{...