Python 用Roipoly进行图像分析。获取值错误

Python 用Roipoly进行图像分析。获取值错误,python,image,image-processing,valueerror,roi,Python,Image,Image Processing,Valueerror,Roi,我一直在尝试使用它来绘制一个ROI,并在图像中找到ROI内的平均像素灰度值。但是,我不断遇到以下错误: Traceback (most recent call last): File "example.py", line 22, in <module> ROI1.displayMean(img) File "/home/ruven/Downloads/Rupesh images/roipoly.py", line 74, in displayMean mask

我一直在尝试使用它来绘制一个ROI,并在图像中找到ROI内的平均像素灰度值。但是,我不断遇到以下错误:

Traceback (most recent call last):
  File "example.py", line 22, in <module>
    ROI1.displayMean(img)
  File "/home/ruven/Downloads/Rupesh images/roipoly.py", line 74, in displayMean
    mask = self.getMask(currentImage)
  File "/home/ruven/Downloads/Rupesh images/roipoly.py", line 48, in getMask
    ny, nx = np.shape(currentImage)
ValueError: too many values to unpack
这是图像:

这就是投资回报率:


我也喜欢使用ROI来查找平均像素灰度值的其他方法。您看到的错误是由于您的输入是3通道图像(RGB),而不是1通道。因此,当roipoly试图解压形状时,它试图将3个值放入2个变量中

它应该通过从3通道图像转换为1通道来固定。这里有一个方法:

# create image
img = mpimg.imread('5.jpg')

print(img.shape)   # (992, 1024, 3)
img = img[:,:,0]
print(img.shape)   # (992, 1024)
您也可以阅读此q/答案了解其他方法:


尝试将图像更改为单个通道(灰色,而不是RGB)。看起来roipoly需要这种格式。@NateTheGrate-Mmm。我不太清楚你的意思。输入的图像实际上是灰度图像,而这里显示的另一个图像只是以黄色突出显示ROI。仅仅因为大部分图像是灰色的,并不意味着它是灰度图像。请注意右下角的绿色水印/元数据。试试我的答案,我希望它对你有用。
# create image
img = mpimg.imread('5.jpg')

print(img.shape)   # (992, 1024, 3)
img = img[:,:,0]
print(img.shape)   # (992, 1024)