spectralpython / spectral

Python module for hyperspectral image processing
MIT License
563 stars 138 forks source link

View Image issue #148

Open scochrane0316 opened 1 year ago

scochrane0316 commented 1 year ago

Hi there,

I'm new to spectral python and have come across unusual behavior when attempting to view a hyperspectral image with imshow. The information from the hdr file looks correct when I load it in, but when I try to view the image it shows up as follows:

Screenshot 2022-11-15 at 2 59 07 PM

Any ideas on what could be the issue here? Thanks in advance!

tboggs commented 1 year ago

My guess is that either the header metadata is wrong or there is just noise in the bands you are viewing. Did you create the header or did it come from some other software?

I suggest first trying to view some other bands to see if they all look the same. Or you could just view the first principal component, since any "real" (non-noise) data would appear there.

The fact that you didn't get an error means the size of the file is consistent with the header metadata but maybe the data type is wrong. You could try a few different values and see if it makes a difference. If you post the contents of your header, I might be able to make a suggestion. The "data type" field would be particularly useful.

scochrane0316 commented 1 year ago

Thanks for the response. The header file came directly from the source (company) that the data itself came from. The data definitely shouldn't be just noise - it shows up correctly in other python packages, QGIS, and ENVI.

I tried out your suggestion of changing the data type, but the set value is correct. I tried changing the interleave, but then the file won't load at all if it's set to 'bil', 'bip', or 'bsq'. Here's a screenshot of the header metadata. Thank you!

Screenshot 2022-11-16 at 4 51 51 PM
tboggs commented 1 year ago

I'm not sure but I've never seen an ENVI header with file type set to "TIFF" so that may be the issue. Can you tell me the exact image file size, in bytes?

scochrane0316 commented 1 year ago

The image file size is 655.2 MB

tboggs commented 1 year ago

I need the exact size, in bytes (not MB).

scochrane0316 commented 1 year ago

655,171,014 bytes

tboggs commented 1 year ago

It seems as though the ENVI "header" was provided for informational purposes, rather than actually reading image data from ENVI. I have never seen an ENVI file type of "TIFF" and an interleave value of "tiff" does not appear valid (based on any ENVI header file format descriptions I have seen). Furthermore, ENVI data files are supposed to be flat, binary files so according to the header, which indicates 16-bit integer value data (data type = 2), the image file size should be

2 * 1519 * 1658 * 235 = 1183695940 bytes

So my guess is that you received a self-contained TIFF file and the ENVI header is provided for metadata. If you want to process the data with the spectral module, the easiest way is probably to convert the TIFF file to ENVI format using something like gdal.

scochrane0316 commented 1 year ago

Thank you, this solved the problem once I converted the TIFF file to ENVI.