Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

morphology.flood fails for boolean image type if tolerance is set #7301

Open
lagru opened this issue Jan 18, 2024 · 1 comment
Open

morphology.flood fails for boolean image type if tolerance is set #7301

lagru opened this issue Jan 18, 2024 · 1 comment
Labels

Comments

@lagru
Copy link
Member

lagru commented Jan 18, 2024

Description:

This is because neither numpy.finfo nor numpy.iinfo work for a boolean dtype in

try:
max_value = np.finfo(working_image.dtype).max
min_value = np.finfo(working_image.dtype).min
except ValueError:
max_value = np.iinfo(working_image.dtype).max
min_value = np.iinfo(working_image.dtype).min

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
@lagru lagru added the 🐛 Bug label Jan 18, 2024
@decorouz
Copy link
Contributor

Would converting the image to int type if input image is boolean type be a good work around.?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants