spectralpython / spectral

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

AttributeError: 'RasterWindow' object has no attribute 'SetClientSizeWH' #169

Open afk-moneymaker opened 2 weeks ago

afk-moneymaker commented 2 weeks ago

Hello, I have been trying to familiarize myself with the library. However, I encountered a problem. The spectral library calls SetClientSizeWH. If the call is changed to SetClientSize, the error does not occur anymore, but others are raised. I therefore assume that the library versions I am using are incompatible with each other. But which combination works?

Code

import os

from spectral import *
import spectral.io.envi as envi

if __name__ == "__main__":
    path = os.path.dirname(__file__) + "/../../data/raw/"
    header = path + "ENVIDATA.hdr"
    data = path + "ENVIDATA.dat"
    img = envi.open(header, data)

    view_indexed(img)

Error message

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~\source\repos\hyperspectral-imaging\src\core\__init__.py:12
      9     data = path + "ENVIDATA.dat"
     10     img = envi.open(header, data)
---> 12     view_indexed(img)
     13     # view = imshow(img, colors=spy_colors)
     14     # gt = img.read_band(0)
     15     # view = imshow(classes=gt, colors=spy_colors)
   (...)
     20
     21 # Run with: & PROJECT/.venv/Scripts/ipython.exe PROJECT/src/core/__init__.py --pylab=WX -i

File ~\source\repos\hyperspectral-imaging\.venv\Lib\site-packages\spectral\graphics\graphics.py:277, in view_indexed(*args, **kwargs)
    274 if 'colors' not in kwargs:
    275     kwargs['colors'] = spy_colors
--> 277 return view(*args, **kwargs)

File ~\source\repos\hyperspectral-imaging\.venv\Lib\site-packages\spectral\graphics\graphics.py:97, in view(*args, **kwargs)
     94 else:
     95     rgb = rgb.astype(np.uint8)
---> 97 frame = RasterWindow(None, -1, rgb, **kwargs)
     98 frame.Raise()
     99 frame.Show()

File ~\source\repos\hyperspectral-imaging\.venv\Lib\site-packages\spectral\graphics\rasterwindow.py:36, in RasterWindow.__init__(self, parent, index, rgb, **kwargs)
     33 self.kwargs = kwargs
     34 wx.Frame.__init__(self, parent, index, title,
     35                   wx.DefaultPosition)
---> 36 self.SetClientSizeWH(self.bmp.GetWidth(), self.bmp.GetHeight())
     37 wx.EVT_PAINT(self, self.on_paint)
     38 wx.EVT_LEFT_DCLICK(self, self.left_double_click)

AttributeError: 'RasterWindow' object has no attribute 'SetClientSizeWH'

Technical details

Dependency Versions

tboggs commented 2 weeks ago

Hello,

view_indexed is now deprecated (I should add a warning for that). Please use the display functions here. So in your case, you would want to do something like

import spectral as spy
gt = img.read_band(0)
spy.imshow(classes=gt, interpolation='nearest')

Note that the classes keyword is primarily intended for displaying ground truth or classification masks (not actual image data).