Skip to content

Instantly share code, notes, and snippets.

@abecode
Last active Apr 21, 2016
Embed
What would you like to do?
reading ENVI from header (hdr) and openflight (flt) files
import matplotlib.pyplot as plt
import scipy.misc
import spectral.io.envi as envi
# in ftp.djamshidpour.com/SanFrancisco/d20160226T2055
img = envi.open('FBI_TET1_20160226T205533_20160226T205613_L1B_C_EL-02984_LWIR.hdr',
'FBI_TET1_20160226T205533_20160226T205613_L1B_C_EL-02984_LWIR.flt')
#show images in viewer
# plt.imshow(img.asarray().squeeze()) # color
# plt.imshow(img.asarray().squeeze(), cmap=plt.cm.binary) # grey
# ptl.imshow(img.asarray().squeeze(), cmap='Greys_r') # negative?
# save as png
scipy.misc.imsave('outfile.png', img.asarray().squeeze())
# convert envi data as hdr and flt files to png in same directory
import glob
import os
import matplotlib.pyplot as plt
import scipy.misc
import spectral.io.envi as envi
rootdir = os.getcwd()
# for each sub directory
for subdir, dirs, files in os.walk(rootdir):
hdrs = glob.glob(os.path.join(subdir, '*hdr'))
flts = glob.glob(os.path.join(subdir, '*flt'))
if len(hdrs) != len(flts):
print "mismatched header and flt files"
continue
for hdr, flt in zip(hdrs, flts):
png_out = hdr.rsplit(".", 1)[0] + ".png"
img = envi.open(hdr, flt)
scipy.misc.imsave(png_out, img.asarray().squeeze())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment