Python 用Roipoly进行图像分析。获取值错误
我一直在尝试使用它来绘制一个ROI,并在图像中找到ROI内的平均像素灰度值。但是,我不断遇到以下错误: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
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/答案了解其他方法:
# create image
img = mpimg.imread('5.jpg')
print(img.shape) # (992, 1024, 3)
img = img[:,:,0]
print(img.shape) # (992, 1024)