spectralpython / spectral

Python module for hyperspectral image processing
MIT License
571 stars 139 forks source link

Displaying Data in a script #71

Closed elenacristinarg closed 6 years ago

elenacristinarg commented 6 years ago

Hi!

Firstly, thanks for your work with this library.

I`m trying to use imshow inside a script and I always get an error (using python or ipython interpreter):

Traceback (most recent call last):
  File ".\DisplayingDataHSI.py", line 17, in <module>
    view = imshow(img, (30, 20, 10), classes=gt)
  File "C:\Users\elena\Anaconda3\lib\site-packages\spectral\graphics\spypylab.py", line 1252, in imshow
    view.set_classes(classes, colors, **kwargs)
  File "C:\Users\elena\Anaconda3\lib\site-packages\spectral\graphics\spypylab.py", line 692, in set_classes
    raise ValueError('Class data shape is inconsistent with ' \
ValueError: Class data shape is inconsistent with previously set data.

Is there a way to use any of these displaying functions in a non-interactive way? For instance, to show an image at the end of a script

Thanks, in advance.

Best regards.

tboggs commented 6 years ago

I'm not sure if that's a spectral issue or a matplotlib issue. spectral.imshow explicitly turns on interactivity in matplotlib. If you want to avoid that, you could try using matplotlib's imshow instead. To do that, use the spectral.get_rgb function to get the image display data (which shouldn't turn on interactivity), then matplotlib.imshow to display it:

import matplotlib.pyplot as plt
rgb = spy.get_rgb(img, (30, 20, 10), classes=gt)
plt.imshow(rgb)