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

binary_blobs fails with io.imshow #5250

Closed
Mec-iS opened this issue Feb 25, 2021 · 2 comments
Closed

binary_blobs fails with io.imshow #5250

Mec-iS opened this issue Feb 25, 2021 · 2 comments

Comments

@Mec-iS
Copy link

Mec-iS commented Feb 25, 2021

Description

Tested in Python 3.7 and 3.8 on Ubuntu 18. I am using pyQT5 as matplot backend by matplotlib.use('Qt5Agg')
This chunk of code fails:

import skimage.io as io
import skimage.data as data
img = data.binary_blobs(length=512, blob_size_fraction=0.1, seed=5)
io.imshow(img)
io.show()

with stacktrace:

Traceback (most recent call last):
  File "src/sk_img/00_basics.py", line 9, in <module>
    io.imshow(img)
  File "/.venv/lib/python3.8/site-packages/skimage/io/_io.py", line 159, in imshow
    return call_plugin('imshow', arr, plugin=plugin, **plugin_args)
  File "/.venv/lib/python3.8/site-packages/skimage/io/manage_plugins.py", line 207, in call_plugin
    return func(*args, **kwargs)
  File "/.venv/lib/python3.8/site-packages/skimage/io/_plugins/matplotlib_plugin.py", line 150, in imshow
    lo, hi, cmap = _get_display_range(image)
  File "/.venv/lib/python3.8/site-packages/skimage/io/_plugins/matplotlib_plugin.py", line 97, in _get_display_range
    ip = _get_image_properties(image)
  File "/.venv/lib/python3.8/site-packages/skimage/io/_plugins/matplotlib_plugin.py", line 55, in _get_image_properties
    is_low_contrast(image))
  File "/.venv/lib/python3.8/site-packages/skimage/exposure/exposure.py", line 651, in is_low_contrast
    limits = np.percentile(image, [lower_percentile, upper_percentile])
  File "<__array_function__ internals>", line 5, in percentile
  File "/.venv/lib/python3.8/site-packages/numpy/lib/function_base.py", line 3818, in percentile
    return _quantile_unchecked(
  File "/.venv/lib/python3.8/site-packages/numpy/lib/function_base.py", line 3937, in _quantile_unchecked
    r, k = _ureduce(a, func=_quantile_ureduce_func, q=q, axis=axis, out=out,
  File "/.venv/lib/python3.8/site-packages/numpy/lib/function_base.py", line 3515, in _ureduce
    r = func(a, **kwargs)
  File "/.venv/lib/python3.8/site-packages/numpy/lib/function_base.py", line 4064, in _quantile_ureduce_func
    r = _lerp(x_below, x_above, weights_above, out=out)
  File "/.venv/lib/python3.8/site-packages/numpy/lib/function_base.py", line 3961, in _lerp
    diff_b_a = subtract(b, a)
TypeError: numpy boolean subtract, the `-` operator, is not supported, use the bitwise_xor, the `^` operator, or the logical_xor function instead.

The same operation succeed using matplotlib:

import skimage.io as io
import skimage.data as data
import matplotlib.pyplot as plt

img = data.binary_blobs(length=512, blob_size_fraction=0.1, seed=5)
plt.imshow(img)
plt.show()

Way to reproduce

Run the chunk above

Version information

3.8.8 (default, Feb 22 2021, 15:43:28) 
[GCC 7.5.0]
Linux-5.4.0-66-generic-x86_64-with-glibc2.27
scikit-image version: 0.18.1
numpy version: 1.20.1

same with:

3.7.9 (default, Sep 29 2020, 15:13:16) 
[GCC 7.5.0]
Linux-5.4.0-66-generic-x86_64-with-debian-buster-sid
scikit-image version: 0.18.1
numpy version: 1.20.1
@mkcor
Copy link
Member

mkcor commented Feb 26, 2021

Hello @Mec-iS,

Since you're mentioning PyQt5, it's not clear to me whether your usage is via non-interactive scripts...

def show():
'''Display pending images.
Launch the event loop of the current gui plugin, and display all
pending images, queued via `imshow`. This is required when using
`imshow` from non-interactive scripts.
A call to `show` will block execution of code until all windows
have been closed.

Having said this, let me quote @jni: "in the medium term (~1y) we aim to pull out the matplotlib dependency and make sure the focus of scikit-image is on image processing, not display or IO. So you should probably start migrating your downstream code to start using plt.imshow directly."

@Mec-iS
Copy link
Author

Mec-iS commented Feb 26, 2021

ok. thanks for the reference, so basically io.imshow() will be deprecated.

I am using the library in scripts that are supposed to visualize the results into subplots.

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

No branches or pull requests

2 participants