Reputation: 1942
I have the satellite data files (2) which are available as satdat
and satdat.hdr
.
As per the answer provided here, I tried the following, but, it gave me an invalid header format error.
import imageio
from pathlib import Path
imageio.plugins.freeimage.download()
datapath = Path(r'./sat_data/')
filename = str(datapath / 'satdat.hdr') # I even tried not using this extension
im = imageio.imread(filename, format='HDR-FI')
print(im.shape)
I was expecting this to read the data into numpy arrays; rather it threw the error as invalid ENVI header file. Looking forward to any library to open this type of file, except OpenCV (due to certain constraints on the compute environment I am using.)
Upvotes: 3
Views: 2389
Reputation: 1942
After much trial and error, the following worked for me:
import spectral.io.envi as envi
from pathlib import Path
datapath = Path(r'./sat_data/')
header_file = str(datapath / 'satdat.hdr')
spectral_file = str(datapath / 'satdat')
numpy_ndarr = envi.open(header_file, spectral_file)
img = numpy_ndarr.read_bands([10, 11, 12]) # select the bands
# Here, img is an numpy nd-array
print(img.shape) # returns (100, 100, 3)
I hope others may find this useful. The spectral library can be found here
Upvotes: 3