我正在尝试打开一个环境.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文件中提取这两个图像?
发布于 2018-02-13 21:18:14
您可以尝试此变体:
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')发布于 2019-01-29 20:34:04
您可以从具有相同名称的hdr文件中读取环境图像。
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,您可以根据自己的判断保存或显示它们。
https://stackoverflow.com/questions/45178549
复制相似问题