I am learning hyperspectral data analysis, so my question may sound simple.
I am reading a hypercube by using the following command:
import spectral.io.envi as envi
hc = envi.open('cube_envi32.hdr','cube_envi32.dat')
'hc' has the following shape:
# Rows: 512
# Samples: 640
# Bands: 92
Interleave: BSQ
Quantization: 32 bits
Data format: float32
(512, 640, 92)
I want to extract the spectral (or pixel values of within a specific binary mask, as shown with rectangle here:
My question includes two parts:
- which python library is suitable for spectra analysis and working with hypercubes?
- what command should I write to extract the spectra values of the region of interest?
Thanks
You can use the
spectral
module and numpy to read the data.If you know the bounding coordinates of your rectangle, you can simply use
If you have an arbitrary mask (mask is not necessarily a rectangular subregion) and can load the entire image into memory, then you can use numpy syntax to read the spectra. Suppose your mask
m
has a value of 1 for pixels you want to read. Then you can do this:If you can't (or don't want to) read the entire image, you can read the masked pixels into a list like so: