spectral - 使用光谱 python 读取 .img 环境文件

标签 spectral spectral-python

我正在尝试打开一个 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')

关于spectral - 使用光谱 python 读取 .img 环境文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45178549/

相关文章:

python - 有效地将带有嵌入数组的字典列表转换为 DataFrame

python - 基于亲和性矩阵的谱聚类

python - 如何使用光谱python处理多光谱栅格文件?

machine-learning - 谱聚类中的度矩阵

python - 稀疏数据集上的谱聚类