如何提取ROI掩模内的光谱范围?

huangapple go评论74阅读模式
英文:

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)

我想提取特定二进制掩模内的光谱(或像这里所示的矩形内的像素值):

如何提取ROI掩模内的光谱范围?

我的问题包括两个部分:

  1. 哪个Python库适合光谱分析和处理超立方体?
  2. 我应该编写什么命令来提取感兴趣区域的光谱值?

谢谢

英文:

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:

如何提取ROI掩模内的光谱范围?

My question includes two parts:

  1. which python library is suitable for spectra analysis and working with hypercubes?
  2. 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)]

huangapple
  • 本文由 发表于 2023年7月13日 18:37:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76678420.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定