4

我正在尝试打开一个env .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 文件中提取这两个图像?

4

2 回答 2

2

你可以试试这个变种:

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')
于 2018-02-13T13:18:14.283 回答
0

您可以从具有相同名称的 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 band 提取到 img1 和 img2,您可以根据自己的判断保存或显示它们。

于 2019-01-29T12:34:04.407 回答