1

我有显示高光谱图像(立方体)的代码。

我必须要图像: 图 1:具有 N 行数和 N 列数的高光谱图像。图像 2:只有一行的高光谱图像,但它的列数与图像 1 相同。

我想创建迭代:对于图像 1 中的每一行,我想从图像 2 中减去值。例如,如果在第一列中,图像 1 中的值为 10,图像 2 中的值为 4,则新图像将具有像素值为 6。

问题是我不知道如何遍历图像中的行。

这是我到目前为止所尝试的:

import spectral.io.envi as envi
import matplotlib.pyplot as plt
import os
from spectral import *
import numpy as np

#Create the image path
#the path 
img_path = r'N:\this\is\path\emptyname_2019-08-13_11-05-46\capture'
cali_path=r'N:\more\path'

#the specific file 
img_file = 'emptyname_2019-08-13_11-05-46.hdr'
img_dark= 'DARKREF_emptyname_2019-08-13_11-05-46.hdr'
cali_hdr= 'Radiometric_1x1.hdr'
cali_img = 'Radiometric_1x1.cal'

#load the images
img= envi.open(os.path.join(img_path,img_file)).load()
img_dark= envi.open(os.path.join(img_path,img_dark)).load()
img_cali= envi.open(os.path.join(cali_path,cali_hdr), image = os.path.join(cali_path,cali_img)).load()

wavelength=[float(i) for i in img.metadata['wavelength']]

#here I have created image 2- the image with the 1 row 
dark_1024=img_dark.mean(axis=0)


#bad attempt  to iterate through each row.
for index, row in img.iterrows():
    img-img_dark

AttributeError:“ImageArray”对象没有属性“iterrows”

知道如何仅“抓取”行并使用新值创建新图像吗?

4

0 回答 0