`morphology.flood` fails for boolean image type if tolerance is set
lagru opened this issue · comments
Lars Grüter commented
Description:
This is because neither numpy.finfo
nor numpy.iinfo
work for a boolean dtype in
scikit-image/skimage/morphology/_flood_fill.py
Lines 275 to 280 in f4c1b34
Way to reproduce:
import numpy as np
import skimage as ski
image = np.empty([10, 10], dtype=bool)
ski.morphology.flood(image, (1, 1), tolerance=2)
Traceback
Traceback (most recent call last):
File "/home/lg/Res/scikit-image/skimage/morphology/_flood_fill.py", line 276, in flood
max_value = np.finfo(working_image.dtype).max
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/skimage2numpy2/lib/python3.12/site-packages/numpy/_core/getlimits.py", line 519, in __new__
raise ValueError("data type %r not inexact" % (dtype))
ValueError: data type <class 'numpy.bool'> not inexact
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/lg/.local/lib/micromamba/envs/skimage2numpy2/lib/python3.12/site-packages/IPython/core/interactiveshell.py", line 3553, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-5-2c35428dde4a>", line 5, in <module>
ski.morphology.flood(image, (1, 1), tolerance=2)
File "/home/lg/Res/scikit-image/skimage/morphology/_flood_fill.py", line 279, in flood
max_value = np.iinfo(working_image.dtype).max
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lg/.local/lib/micromamba/envs/skimage2numpy2/lib/python3.12/site-packages/numpy/_core/getlimits.py", line 697, in __init__
raise ValueError("Invalid integer data type %r." % (self.kind,))
ValueError: Invalid integer data type 'b'.
Version information:
3.12.1 | packaged by conda-forge | (main, Dec 23 2023, 08:03:24) [GCC 12.3.0]
Linux-6.7.0-arch3-1-x86_64-with-glibc2.38
scikit-image version: 0.23.0rc0.dev0+git20240118.4f65ab74a
numpy version: 2.0.0.dev0+git20240113.d2f60ff
Adeyemi Biola commented
Would converting the image to int
type if input image is boolean type be a good work around.?