Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an image.entropy() method (second revision) #3608

Merged
merged 3 commits into from Jun 29, 2019

Conversation

fish2000
Copy link
Contributor

@fish2000 fish2000 commented Jan 25, 2019

This calculates the entropy for the image, based on the histogram.

Because this uses image histogram data directly, the existing C function underpinning the image.histogram() method was abstracted into a static function to parse extrema tuple arguments, and a new C function was added to calculate image entropy, making use of the new static extrema function.

The extrema-parsing function was written by @homm, based on the macro abstraction I wrote, during the discussion of my first entropy-method pull request: #3530 (comment)

The original PR had code with issues with log2 and the use of the standard math library – @radarhere corrected these: fish2000#1

The new image.entropy() method is based on image.histogram(), and will accept the same arguments to calculate the histogram data it will use to assess the entropy of the image.

The algorithm and methodology is based on existing Python code:

... A test case in the Tests/ directory, and doctest lines in selftest.py, have both been added and checked.

Changes proposed in this pull request:

  • Adding the <math.h> include to _imaging.c,
  • The addition of an image.entropy() method to the Image Python class,
  • The abstraction of the extrema-parsing logic of of the C function _histogram into a static function, and
  • The use of that static function in both the _histogram and _entropy C functions.
  • Minor documentation addenda in the docstrings for both the image.entropy() and image.histogram() methods were also added.

This resolves my earlier version of this feature, PR #3530.

@fish2000

This comment has been minimized.

@fish2000 fish2000 closed this Jan 25, 2019
@fish2000 fish2000 reopened this Jan 25, 2019
@fish2000

This comment has been minimized.

@fish2000 fish2000 changed the title Added an image.entropy() method Added an image.entropy() method (second revision) Jan 30, 2019
@fish2000
Copy link
Contributor Author

fish2000 commented Feb 1, 2019

@homm @radarhere Might I get a review on this, if either of you get a moment?

src/_imaging.c Outdated Show resolved Hide resolved
@fish2000

This comment has been minimized.

@hugovk

This comment has been minimized.

Tests/test_image_entropy.py Outdated Show resolved Hide resolved
@fish2000

This comment has been minimized.

@fish2000

This comment has been minimized.

src/_imaging.c Outdated Show resolved Hide resolved
@fish2000
Copy link
Contributor Author

fish2000 commented Feb 6, 2019

screen shot 2019-02-06 at 4 01 56 pm

… OK so it looks like /usr/bin/xvfb-run segfaulted in one of the QImage tests during the Docker Arch run – but otherwise everything else on the latest Travis build-flight passed it would seem, erm yes.

@radarhere

This comment has been minimized.

@fish2000

This comment has been minimized.

@fish2000
Copy link
Contributor Author

fish2000 commented Mar 4, 2019

Any chance of getting this into version 6.0.0? – q.v. issue #3618 supra.

@fish2000 fish2000 force-pushed the image-entropy-method-revised branch 2 times, most recently from 4030957 to 06f4bad Compare March 5, 2019 13:46
src/_imaging.c Outdated Show resolved Hide resolved
This calculates the entropy for the image, based on the histogram.

Because this uses image histogram data directly, the existing C
function underpinning the `image.histogram()` method was abstracted
into a static function to parse extrema tuple arguments, and a new
C function was added to calculate image entropy, making use of the
new static extrema function.

The extrema-parsing function was written by @homm, based on the
macro abstraction I wrote, during the discussion of my first
entropy-method pull request: https://git.io/fhodS

The new `image.entropy()` method is based on `image.histogram()`,
and will accept the same arguments to calculate the histogram data
it will use to assess the entropy of the image.

The algorithm and methodology is based on existing Python code:

* https://git.io/fhmIU

... A test case in the `Tests/` directory, and doctest lines in
`selftest.py`, have both been added and checked.

Changes proposed in this pull request:

* Added “math.h” include to _imaging.c
* The addition of an `image.entropy()` method to the `Image`
  Python class,
* The abstraction of the extrema-parsing logic of of the C
  function `_histogram` into a static function, and
* The use of that static function in both the `_histogram` and
  `_entropy` C functions.
* Minor documentation addenda in the docstrings for both the
  `image.entropy()` and `image.histogram()` methods were also
  added.
* Removed outdated boilerplate from testing code
* Removed unused “unittest” import
@radarhere radarhere force-pushed the image-entropy-method-revised branch from cf22a97 to 8b447c4 Compare June 26, 2019 09:17
@hugovk hugovk merged commit 08c4792 into python-pillow:master Jun 29, 2019
@hugovk
Copy link
Member

hugovk commented Jun 29, 2019

Thank you! This will be released on Monday.

Please could you add release notes to https://github.com/python-pillow/Pillow/blob/master/docs/releasenotes/6.1.0.rst#api-additions?

hugovk added a commit to hugovk/Pillow that referenced this pull request Jul 1, 2019
@hugovk
Copy link
Member

hugovk commented Jul 1, 2019

Release notes added in #3930.

hugovk added a commit that referenced this pull request Jul 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants