-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Hi @Who8MyLunch ,
first of all, thanks to programming this amazing widget! I love it. I made a library based on it and use it often to explore image data from within jupyter notebooks.
I have a little issue when setting an image to an array of zeros. This is a minimal working example:
import numpy as np
import numpy_image_widget as niw
image = np.asarray([[1,0], [2,3]])
view = niw.NumpyImage(image)
Until here everything is good. If I then set the data:
view.data = np.asarray([[0,0], [0,0]])
I receive this error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_13780/2881574154.py in <module>
----> 1 view.data = np.asarray([[0,0], [0,0]])
~\miniconda3\envs\STRESS\lib\site-packages\numpy_image_widget\numpy_image_widget.py in data(self, new_data)
70
71 self._data = new_data
---> 72 self.value = ia.compress(self._data, self.format, quality=self.quality)
73
74 @property
~\miniconda3\envs\STRESS\lib\site-packages\image_attendant\compression.py in compress(data, fmt, **kwargs)
22 """
23 # Enforce 8-byte data
---> 24 data = utility.setup_uint8(data)
25
26 fmt = fmt.lower()
~\miniconda3\envs\STRESS\lib\site-packages\image_attendant\utility.py in setup_uint8(data, lohi)
77 lo, hi = lohi
78 if lo == hi:
---> 79 raise ValueError('Invalid data range: {}, {}'.format(lo, hi))
80
81 data = (data - lo) / (hi - lo)
ValueError: Invalid data range: 0.0, 0.0
It's obviously a division by zero because min and max of the image are equal. If you're busy, I'm happy to send a PR. Just let me know.
Thanks!
Best,
Robert
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels