NEW: add shannon entropy #2416

Open
wants to merge 3 commits into
from

Projects

None yet

5 participants

@sciunto
Member
sciunto commented Dec 25, 2016 edited

Description

This PR implements a new feature, the shannon entropy. It's very simple, but we often miss simple features.
This also reflects a personal need for a library I'm writting.

Checklist

[It's fine to submit PRs which are a work in progress! But before they are merged, all PRs should provide:]

skimage/measure/entropy.py
+ >>> shannon_entropy(data.camera())
+ 12.290907503512717
+ """
+ return scipy_entropy(img.ravel())
@soupault
soupault Dec 27, 2016 Member

Could you check if the input image is non-grayscale?

@sciunto
sciunto Dec 27, 2016 Member

done :)

@codecov-io
codecov-io commented Dec 27, 2016 edited

Current coverage is 90.64% (diff: 100%)

No coverage report found for master at 73ac742.

Powered by Codecov. Last update 73ac742...f0a1bcd

@jni

@sciunto I have one requested change and two comments, that you may choose to ignore or address. =)

skimage/measure/entropy.py
+from .._shared.utils import assert_nD
+
+
+def shannon_entropy(image):
@jni
jni Dec 30, 2016 Contributor

Another slight preference would be for the name to just be entropy. At which point we are just a very thin wrapper around scipy, but that's ok.

skimage/measure/entropy.py
+ >>> shannon_entropy(data.camera())
+ 12.290907503512717
+ """
+ assert_nD(image, 2)
@jni
jni Dec 30, 2016 Contributor

Please remove this check. The entropy is equally defined for 3D images.

skimage/measure/entropy.py
+ 12.290907503512717
+ """
+ assert_nD(image, 2)
+ return scipy_entropy(image.ravel())
@jni
jni Dec 30, 2016 Contributor

I have a slight preference towards using base 2... Do you have a preference for base e?

@sciunto
Member
sciunto commented Dec 30, 2016

@jni I believe I addressed your comment. From your feedback I chose to pass the base in the signature, defaulted to bits.

@sciunto sciunto added this to the 0.13 milestone Dec 30, 2016
sciunto added some commits Dec 25, 2016
@sciunto sciunto NEW: add shannon entropy
2ef6323
@sciunto sciunto Bump scipy version to 0.14 for stats.entropy
e4eaa79
@sciunto
Member
sciunto commented Dec 30, 2016

I have to bump scipy to 0.14 (published in Apr 14). I guess it's fine, we depend on numpy 1.11 published in March 16.

@sciunto sciunto DOC: add optional in docstring
f0a1bcd
+ Calculate the Shannon entropy of an image.
+
+ The Shannon entropy is defined as S = -sum(pk * log(pk)),
+ where pk are the number of pixels of value k.
@emmanuelle
emmanuelle Dec 31, 2016 Member

With this definition, it's not obvious to me how the entropy is computed on an image of floats. However, I just checked that the entropy is the same whether the image is made of ints or floats.

+
+ Notes
+ -----
+ The units are bits or shannon (Sh) for base=2, natural unit (nat) for
@emmanuelle
emmanuelle Dec 31, 2016 Member

I don't understand "units" here.

@emmanuelle
Member

As for the version bump for scipy, is it a runtime only requirement? Can we keep 0.10 in DEPENDS.txt (used for Debian/Ubuntu packaging??) for build requirements and have 0.14 for runtime requirement? @yarikoptic

@jni
Contributor
jni commented Jan 1, 2017

@emmanuelle @sciunto I agree that it's tricky to bump up the SciPy requirement. There's been some strong resistance to this in the past. I'm happy with the current changes, but we should perhaps wait to merge this until 0.13 is out. @sciunto do you have a strong desire for this to be in 0.13 or are you ok with waiting one release?

@sciunto sciunto modified the milestone: 0.14, 0.13 Jan 1, 2017
@sciunto
Member
sciunto commented Jan 1, 2017 edited

I'm OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment