Commit Graph

104 Commits

Author SHA1 Message Date
Alexander Böhn
7b815a5f1d Added an image.entropy() method
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
2019-06-26 19:15:47 +10:00
Hugo
cab7231e2a Format with Black 2019-06-11 11:42:05 +03:00
Hugo
169455f924 Refactor and format with Black 2019-06-10 18:22:46 +03:00
Hugo
53a7e35004 Format with Black 2019-06-10 18:22:46 +03:00
Andrew Murray
a94bd13791 Changed string formatting 2019-06-06 21:36:38 +10:00
Andrew Murray
4fa3016d67 Changed string formatting
Co-Authored-By: Hugo <hugovk@users.noreply.github.com>
2019-06-06 21:36:38 +10:00
Andrew Murray
77630f000c Updated resampling filter error messages 2019-06-06 21:36:38 +10:00
Hugo
169961649d
Merge pull request #3848 from radarhere/pa
Improved palette handling for LA and PA modes
2019-06-05 22:32:44 +03:00
Jon Dufresne
3f2cfb2027 Remove unnecessary numeric placeholders from format strings
Unnecessary since Python 2.7.
2019-05-26 07:07:32 -07:00
Andrew Murray
e9c0cf61f3 Fixed palette for LA and PA mode when pickling 2019-05-11 14:43:00 +10:00
Andrew Murray
691df96734 Fixed opening mmap image through Path on Windows 2019-05-04 15:00:49 +10:00
Andrew Murray
40bc46ff49 Moved ImageFile.Exif to Image.Exif 2019-04-01 20:03:02 +11:00
Hugo
4f8cfd536b
Merge pull request #3721 from radarhere/quantize
Update palette in quantize
2019-03-30 12:07:38 +02:00
Andrew Murray
dba38912fb Allow putpalette for LA and PA 2019-03-29 23:13:50 +11:00
Hugo
a93bcdfe0c
Merge pull request #3724 from radarhere/readonly_save
Ensure image is mutable before saving
2019-03-28 11:53:33 +02:00
Hugo
e7c2828b4e
Merge pull request #3740 from radarhere/remap_palette
Corrected remap_palette documentation
2019-03-28 11:47:36 +02:00
Hugo
0572983104
Merge pull request #3726 from radarhere/pa
Promote P images to PA in putalpha
2019-03-28 11:44:52 +02:00
Hugo
adbe97594e
Merge pull request #3719 from radarhere/p_rgb_rgba
Allow RGB and RGBA values for new P images
2019-03-27 18:03:23 +02:00
Andrew Murray
4a5666f1f4 Added transparency for all PNG greyscale modes 2019-03-27 07:41:33 +11:00
Andrew Murray
81cfede546 Corrected remap_palette documentation [ci skip] 2019-03-23 09:36:59 +11:00
Andrew Murray
f61828acdc Promote P images to PA in putalpha 2019-03-19 11:13:58 +11:00
Hugo
b8ea8814f0
Merge pull request #3683 from radarhere/exclusive
Only close original fp in __del__ and __exit__ if original fp is exclusive
2019-03-18 20:37:21 +02:00
Andrew Murray
9bdab56689 Replaced hasattr conditions with getattr and default 2019-03-18 09:15:37 +11:00
Andrew Murray
0b62337b6f Ensure image is mutable before saving 2019-03-17 23:37:40 +11:00
Andrew Murray
fa8ecffff2 Corrected seek documentation 2019-03-17 00:00:10 +11:00
Andrew Murray
5b9c11b426 Update palette in quantize 2019-03-16 13:36:58 +11:00
Andrew Murray
6790c2e375 Allow RGB and RGBA values for new P images 2019-03-15 17:35:05 +11:00
Andrew Murray
22b0110f89 Only close original fp in __del__ and __exit__ if original fp is exclusive 2019-03-12 08:54:43 +11:00
Hugo
125a001b66
Merge pull request #3698 from radarhere/context
Only close exclusive fp on Image __exit__
2019-03-11 21:41:44 +02:00
Hugo
63f31ee380
Merge pull request #3699 from glasnt/topic/quantize-dither
Add option to set dither param on quantize
2019-03-11 12:18:32 +02:00
Andrew Murray
878244bf38 Fixed typo 2019-03-11 11:13:39 +11:00
Katie McLaughlin
0b63579f39 Add option to set dither param on quantize
Default the option to `1`, as per original setting
2019-03-09 10:36:13 +11:00
Andrew Murray
b29365e8a0 Updated list of Unix utilities used to show an image [ci skip] 2019-03-07 15:24:27 +11:00
Hugo
2edab165a1 Since #2527, macOS saves to a temp PNG before showing 2019-03-06 15:57:58 +02:00
Andrew Murray
b1cc7df7ba Only close exclusive fp on Image __exit__ 2019-03-06 21:55:32 +11:00
Frédéric Chapoton
e514fbbbb1
use the already import io
instead of importing again from io (lgtm suggestion)
2019-03-02 21:19:57 +01:00
Andrew Murray
57807e9ce2
Merge pull request #3624 from hugovk/rm-VERSION
Remove deprecated VERSION
2019-03-02 11:47:59 +11:00
Hugo
d9f5f44799
Merge pull request #3632 from radarhere/thumbnail
Do not resize in Image.thumbnail if already the destination size
2019-02-27 23:37:20 +02:00
Andrew Murray
1162b4cf83 Do not resize if already the destination size 2019-02-13 19:26:37 +11:00
Jon Dufresne
dd1e7ccc4a Slightly simplify Image.__eq__
Two identical types can be compared using the `is` operator. Object
identity is slightly faster than a string comparison as well.
2019-02-03 07:13:28 -08:00
Hugo
4d1a459fa7
Merge pull request #3574 from jdufresne/base-exc
Catch BaseException for resource cleanup handlers
2019-02-03 11:35:44 +02:00
Hugo
158d99b8b0 Remove deprecated VERSION 2019-01-30 15:46:14 +02:00
Jon Dufresne
51e95f6252 Catch BaseException for resource cleanup handlers
In the event of a SystemExit or KeyboardInterrupt, file resources should
still be cleaned up before re-raising the exception.

https://docs.python.org/3/library/exceptions.html#exception-hierarchy
2019-01-12 18:32:14 -08:00
Jon Dufresne
3e28ba3b7d Python del is a statement not a function
https://docs.python.org/3/reference/simple_stmts.html#the-del-statement
2019-01-12 18:28:35 -08:00
Andrew Murray
71b64dcf73 Only close __fp if not fp 2019-01-04 12:29:23 +11:00
Andrew Murray
671f7a392d Allow RGBA value for P image putpixel 2018-12-31 13:37:04 +11:00
Andrew Murray
3f6282e259 Allow RGB value for P image putpixel 2018-12-31 11:35:15 +11:00
Andrew Murray
5edeca28b6 Corrected docstring 2018-12-28 07:14:44 +11:00
Hugo
69837baba2
Merge pull request #3490 from radarhere/open_files
Updated open files documentation
2018-12-13 21:14:22 +02:00
Hugo
3ed5dcc928
Merge pull request #3467 from hugovk/lint-can-fail
CI: Allow lint job to fail
2018-12-13 21:09:58 +02:00