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

envi.save_image() fails when writing a single band numpy array imported by SPy_obj.read_band() #20

Closed
MoTSCHIGGE opened this issue Jan 22, 2015 · 0 comments
Labels
Milestone

Comments

@MoTSCHIGGE
Copy link

Version 0.16.1:
I imported a single band like this:

import spectral
Obj      = spectral.open_image('image.hdr')
Band1 = Obj.read_band(0)

When I try to save the imported 2D numpy array "Band1 using envi.save_saveimage with interleave ='bsq', I get the following error:

File "...\Python27\lib\site-packages\spectral\io\envi.py", line 537, in _prepared_data_and_metadata
  data = data.transpose(interleave_transpose(src_interleave, interleave))

ValueError: axes don't match array

The problem is that read_band() returns a 2D, not a 3D numpy array, which cannot be transposed with the argument (2,0,1), which is returned by spectral.io.spyfile.interleave_transpose('bip','bsq').
In my case I try to do this:

data = np_array_of_shape_10_10.transpose(2,0,1)
ValueError: axes don't match array

Solution:
The 2D numpy array returned by Obj.read_band(0) has to be converted into a 3D array like this:
Band1 = Obj.read_band(0)
Band1 = Band1[ : , : , numpy.newaxis]

Afterwards it can be saved by envi.save_image
@tboggs
Would it be possible modify the save_image function to be compatible with 2D numpy arrays?

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

No branches or pull requests

2 participants