太多值无法解压缩frangi过滤器中的错误

时间:2019-02-16 17:31:15

标签: python opencv

运行以下代码时,我收到错误消息“要解包的值太多”:

from skimage.filters import frangi, hessian
import cv2
import matplotlib.pyplot as plt
image = cv2.imread('test.png')
image= cv2.resize(image,(300,300))
cv2.imshow('im',image)
cv2.waitKey(0)
fig, ax = plt.subplots(ncols=3, subplot_kw={'adjustable': 'box-forced'})
k=frangi(image)
ax[0].imshow(k, cmap=plt.cm.gray)
ax[0].set_title('Frangi filter result')

1 个答案:

答案 0 :(得分:2)

如果您看看documentation,它说image必须是:

  • image :( N,M)ndarray
    • 包含输入图像数据的数组。

基本上,您可以在应用滤镜之前将图像转换为灰度;像这样的东西:

import cv2
import matplotlib.pyplot as plt
from skimage.filters import frangi, hessian

image = cv2.imread('test.png')  # <-- shape: (N, M, C)
image = cv2.resize(image, (300,300))

cv2.imshow('im', image)
cv2.waitKey(0)

fig, ax = plt.subplots(ncols=3, subplot_kw={'adjustable': 'box-forced'})
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)   # <-- shape: (N, M)
k = frangi(gray_image)
ax[0].imshow(k, cmap=plt.cm.gray)
ax[0].set_title('Frangi filter result')

这是一个基于scikit examples的MCVE:

import cv2
from skimage.data import camera
from skimage.filters import frangi

import matplotlib.pyplot as plt

image = cv2.imread('lenna.png')
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
frangi_result = frangi(gray_image)

fig, ax = plt.subplots(ncols=3)

ax[0].imshow(image[..., ::-1])  # BGR to RGB
ax[0].set_title('Original image')

ax[1].imshow(gray_image, cmap=plt.cm.gray)
ax[1].set_title('Grayscale image')

ax[2].imshow(frangi_result, cmap=plt.cm.gray)
ax[2].set_title('Frangi filter result')

for a in ax:
    a.axis('off')

plt.tight_layout()
plt.show()

输出为:

frangi output