reading .img envi file with spectral python

Viewed 5632

I am trying to open an envi .img file and there is a .hdr file having same name. In the .img file there are two images which I can read using following code.

from spectral import *
img = open_image('LC08_L1TP_029029_20130330_20170310_01_T1_sensor_B05.img')

And the properties of img(BSQ file) is as following figure

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

What I want to extract those two images from img. But when I am trying with

img[:,:,1]

and it gives me an array of size(7311,7371,1) but all the values inside the array is zero but I know they should be non zero values.

My question is how can I extract those two images from the BSQ file?

2 Answers

You can read the envi image from the hdr file having the same name.

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)

now you have extracted bith bands to img1 and img2, and you can save them or display them as per your discretion.

Related