[英]How to resolve this issue "ValueError: not enough values to unpack (expected 5, got 4)"?
[英]How to resolve this error not enough values to unpack (expected 3,got 2)? for image
我是 python 編程的新手,我剛剛學習基於圖形的分割,當我運行下面的代碼時遇到了一個錯誤。 代碼是:
import numpy as np
from glob import glob
from PIL import Image
from matplotlib import pyplot as plt
from felzenszwalb_segmentation import segment
image_files = glob('/content/IMG-0020-00144.png')
len(image_files)
image = np.array(Image.open(image_files[0]))
segmented_image = segment(image, 0.2, 400, 50)
fig = plt.figure(figsize=(12, 12))
a = fig.add_subplot(1, 2, 1)
plt.imshow(image)
a = fig.add_subplot(1, 2, 2)
plt.imshow(segmented_image.astype(np.uint8))
plt.show()
Error is:
ValueError Traceback (most recent call last)
<ipython-input-18-cff61e7244bf> in <module>()
1 image = np.array(Image.open(image_files[0]))
----> 2 segmented_image = segment(image, 0.2, 400, 50)
3 fig = plt.figure(figsize=(12, 12))
4 a = fig.add_subplot(1, 2, 1)
5 plt.imshow(image)
/usr/local/lib/python3.7/dist-packages/felzenszwalb_segmentation/segmentation.py in segment(in_image, sigma, k, min_size)
23
24 def segment(in_image, sigma, k, min_size):
---> 25 height, width, band = in_image.shape
26 smooth_red_band = smoothen(in_image[:, :, 0], sigma)
27 smooth_green_band = smoothen(in_image[:, :, 1], sigma)
ValueError:沒有足夠的值來解包(預期 3,得到 2)
請解決這個問題
您是否檢查過您是否將 RGB 或灰度圖像傳遞給代碼? 錯誤告訴您圖像形狀是只有兩個元素的元組,這通常是灰度圖像的情況(只有 1 個通道)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.