spectralpython / spectral

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

Error while saving the file with envi header. #83

Closed BlcaKHat closed 6 years ago

BlcaKHat commented 6 years ago

The code to save the file is working fine with sample data but when i am trying with hyperian (.hdr) data i am getting error save

TypeError: load() got an unexpected keyword argument 'scale'

tboggs commented 6 years ago

envi.save_image expects either a SpyFile or numpy.ndarray. It looks like you are passing it a TransformedImage object because you are calling transform on a SpyFile, rather than an ndarray. To save img_pc to a file, do this instead:

envi.save_image('pcimage.hdr', img_pc.load(), dtype=np.float32)

I don't know if you are intentionally calling principal_components on a SpyFile object (e.g., because of system resource limitations) but note that doing so is orders of magnitude slower than doing so on a numpy array. In other words, doing this would be much faster:

data = open_image('Dun_Hyperion_Atm_Corr.hdr').load()
pc = principal_components(data)
<etc.>

Doing what I described above would also return a numpy array from the transform call so you would not need the load call in the arguments to the the save_image call.

tboggs commented 6 years ago

I updated the code to handle this situation in the future.

BlcaKHat commented 6 years ago

thank you @tboggs .