matthewwithanm / pilkit

Utilities and processors built for, and on top of PIL
BSD 3-Clause "New" or "Revised" License
196 stars 54 forks source link

Updating histogram entropy implementations #42

Closed fish2000 closed 4 years ago

fish2000 commented 4 years ago

As of version 6.1.0, the Pillow imaging library’s C module includes an optimized native entropy method:

https://github.com/python-pillow/Pillow/blob/master/CHANGES.rst#610-2019-07-01

This change detects and selects this new native method, if it is available in the version of Pillow upon which pilkit finds itself running.

Additionally, an optimized version of the existing Python entropy method is furnished as a fallback: rather than summing the entire histogram value set, the function calculates the product of the image dimensions and band count to arrive at the same number. It also uses generator expressions and the specialized math.fsum(…) and math.log2(…) library calls to improve on the performance of its predecessor without altering the algorithm.

The appropriate image-entropy function is then conditionally ensconced in the pilkit.processors.utils module, at module-load time.

fish2000 commented 4 years ago

Screen Shot 2019-11-12 at 7 34 02 PM

Hey I am not sure why the Python 3.4 test failed – it does look like it is a failure in the entropy code, but it seems to be related to the PIL.Image type, qua a nose mocking operation?… I couldn’t reproduce this error on my end, but if someone points me toward anything wrong, I’ll gladly fix it of course.