Skip to content

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

Merged
hugovk merged 3 commits intopython-pillow:masterfrom
fish2000:image-entropy-method-revised
Jun 29, 2019
Merged

Added an image.entropy() method (second revision)#3608
hugovk merged 3 commits intopython-pillow:masterfrom
fish2000:image-entropy-method-revised

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?

@fish2000 fish2000 force-pushed the image-entropy-method-revised branch from aaa797e to a6424b8 Compare February 5, 2019 16:02
@fish2000

This comment has been minimized.

@hugovk

This comment has been minimized.

@fish2000 fish2000 force-pushed the image-entropy-method-revised branch from a6424b8 to 0a640f8 Compare February 5, 2019 16:40
@fish2000

This comment has been minimized.

@fish2000 fish2000 force-pushed the image-entropy-method-revised branch from 0a640f8 to 761ec74 Compare February 5, 2019 16:49
@fish2000

This comment has been minimized.

@fish2000 fish2000 force-pushed the image-entropy-method-revised branch from 3ee9a4c to bdce3f1 Compare February 6, 2019 19:05
@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.

@fish2000 fish2000 force-pushed the image-entropy-method-revised branch from bdce3f1 to b384a8d Compare February 6, 2019 22:37
@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
@radarhere radarhere force-pushed the image-entropy-method-revised branch from 06f4bad to 24afcc7 Compare March 27, 2019 08:15
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.

3 participants