我正在尝试打开一个 envi .img 文件,并且有一个同名的 .hdr 文件。在.img文件中,我可以使用以下代码读取两个图像。
from spectral import *
img = open_image('LC08_L1TP_029029_20130330_20170310_01_T1_sensor_B05.img')
而img(BSQ文件(的属性如下图所示
In[352] img
Out[352]:
Data Source: '.LC08_L1TP_029029_20130330_20170310_01_T1_sensor_B05.img'
# Rows: 7311
# Samples: 7371
# Bands: 2
Interleave: BSQ
Quantization: 16 bits
Data format: int16
我想从 img 中提取这两个图像。但是当我尝试使用
img[:,:,1]
它给了我一个大小(7311,7371,1(的数组,但数组中的所有值都是零,但我知道它们应该是非零值。
我的问题是如何从 BSQ 文件中提取这两个图像?
您可以尝试此变体:
from spectral import *
img = open_image('LC08_L1TP_029029_20130330_20170310_01_T1_sensor_B05.img')
img_open = img.open_memmap(writeable = True)
img_band = img_open[:,:,1]
envi.save_image('new_image.bsq', ext='bsq', interleave = 'BSQ')
或
此变体需要通过 hdr 文件打开图像。但它应该像以前的变体一样工作。
from spectral import *
img = envi.open('<name of hdr file>')
img_open = img.open_memmap(writeable = True)
img_band = img_open[:,:,1]
envi.save_image('new_image.bsq', ext='bsq', interleave = 'BSQ')
您可以从具有相同名称的 hdr 文件中读取 envi 图像。
import numpy as np
from spectral import*
img1=open_image("<path to file.hdr>").read_band(0)
img2=open_image("<path to file.hdr>").read_band(1)
现在,您已将 BITH 波段提取到 IMG1 和 IMG2,您可以自行决定保存或显示它们。