英文:
How to extract the spectra range within a roi mask?
问题
我正在学习高光谱数据分析,所以我的问题可能听起来很简单。
我正在使用以下命令读取一个超立方体:
import spectral.io.envi as envi
hc = envi.open('cube_envi32.hdr','cube_envi32.dat')
'hc' 的形状如下:
# 行数: 512
# 样本数: 640
# 波段数: 92
Interleave: BSQ
Quantization: 32 位
数据格式: float32
(512, 640, 92)
我想提取特定二进制掩模内的光谱(或像这里所示的矩形内的像素值):
我的问题包括两个部分:
- 哪个Python库适合光谱分析和处理超立方体?
- 我应该编写什么命令来提取感兴趣区域的光谱值?
谢谢
英文:
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
答案1
得分: 1
你可以使用spectral
模块和numpy来读取数据。
如果你知道你的矩形的边界坐标,你可以简单地使用
region = hc[i_start:i_stop, j_start:j_stop]
如果你有一个任意的蒙版(蒙版不一定是一个矩形子区域),并且可以将整个图像加载到内存中,那么你可以使用numpy语法来读取光谱。假设你的蒙版m
对于你想要读取的像素值为1。然后你可以这样做:
pixels = hc.load().asarray[m == 1]
如果你不能(或不想)读取整个图像,你可以将蒙版像素读入一个列表中,如下所示:
pixels = [hc[i, j] for (i, j) in np.argwhere(m == 1)]
英文:
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
region = hc[i_start:i_stop, j_start:j_stop]
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:
pixels = hc.load().asarray[m == 1]
If you can't (or don't want to) read the entire image, you can read the masked pixels into a list like so:
pixels = [hc[i, j] for (i, j) in np.argwhere(m == 1)]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论