fmi-faim / faim-ipa

A collection of Image Processing and Analysis (IPA) functions used at the Facility for Advanced Imaging and Microscopy (FAIM)
BSD 3-Clause "New" or "Revised" License
9 stars 6 forks source link

Improve `UIntHistogram` #53

Closed imagejan closed 1 year ago

imagejan commented 1 year ago

The UIntHistogram currently saves redundant data: bins is always len(frequencies) + 1.

See here:

https://github.com/fmi-faim/faim-hcs/blob/4e73d599dd841bf64b5035a0fa7771023ad9b499/tests/test_UIntHistogram.py#L26

and all these lines... https://github.com/fmi-faim/faim-hcs/blob/4e73d599dd841bf64b5035a0fa7771023ad9b499/tests/test_UIntHistogram.py#L47 https://github.com/fmi-faim/faim-hcs/blob/4e73d599dd841bf64b5035a0fa7771023ad9b499/tests/test_UIntHistogram.py#L60 https://github.com/fmi-faim/faim-hcs/blob/4e73d599dd841bf64b5035a0fa7771023ad9b499/tests/test_UIntHistogram.py#L73

Also, there no use in adding + 1, we can have just bins == len(frequencies).

We currently don't read bins anywhere except in the tests, so I propose we change it, and also don't serialize bins as it can be computed from frequencies easily.


To preserve backwards compatibility, we should ignore bins when reading from files, and instead return len(frequencies) when asked for bins.


In addition to bins and offset, we can then maybe also serialize a version value, so if that is absent, we switch to "legacy" behavior. But that might not even be needed since we don't change how bins and offset are stored.