Last active
April 21, 2016 00:54
-
-
Save abecode/93267f4961be489d42d25589259285ea to your computer and use it in GitHub Desktop.
reading ENVI from header (hdr) and openflight (flt) files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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