Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display hyperspectral image with SPy by python script not ipython?

when I use the script the window flashes and then disappears, so I just want to know how to make it stay for a long time? Thanks very much! you can get this python package form

from spectral import *
img = open_image('92AV3C.lan')
view = imshow(img, (29, 19, 9))


def imshow(data=None, bands=None, classes=None, source=None, colors=None,
       figsize=None, fignum=None, title=None, **kwargs):
    import matplotlib.pyplot as plt
    from spectral import settings
    from .graphics import get_rgb

    set_mpl_interactive()

    view = ImageView()
    if data is not None:
        view.set_data(data, bands, **kwargs)
    if classes is not None:
        view.set_classes(classes, colors, **kwargs)
    if source is not None:
        view.set_source(source)
    elif data is not None and len(data.shape) == 3 and data.shape[2] > 3:
        view.set_source(data)
    if fignum is not None or figsize is not None:
        fig = plt.figure(num=fignum, figsize=figsize)
        view.show(fignum=fig.number)
    else:
        view.show()

    if title is not None:
        view.set_title(title)
    return view
like image 203
Semie J Avatar asked Nov 07 '25 01:11

Semie J


2 Answers

I use PyCharm2019 and python3.8. After add two lines, it works. import matplotlib.pyplot as plt plt.pause(10)

like image 184
Scentea Avatar answered Nov 08 '25 16:11

Scentea


It flashes because the program execution finishes, which closes the GUI.

The common approach is to call plt.pause(<expected pause in seconds>) after calling view.show.

like image 25
kist Avatar answered Nov 08 '25 16:11

kist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!