2017-07-18 150 views
1

我想打開一個envi .img文件並且有一個.hdr文件具有相同的名稱。 .img文件中有兩個圖像,我可以使用下面的代碼讀取它們。閱讀.img與光譜python envi文件

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文件中提取這兩個圖像?

回答

0

你可以試試這個變種:

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')