Skip to content

Instantly share code, notes, and snippets.

@abecode
Last active April 21, 2016 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abecode/93267f4961be489d42d25589259285ea to your computer and use it in GitHub Desktop.
Save abecode/93267f4961be489d42d25589259285ea to your computer and use it in GitHub Desktop.
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