【问题标题】:skimage's rgb2gray in python: AttributeError: Nonetype object has no attribute ndimpython中skimage的rgb2gray:AttributeError:Nonetype对象没有属性ndim
【发布时间】:2014-12-11 17:23:57
【问题描述】:

据我所知,我使用的是这段代码(skimage 版本为 0.10.0):

from scipy import misc
import scipy.io as sio
from skimage.color import rgb2gray

img = cv2.imread(myfile)
img = rgb2gray(img)

但现在我收到了这个错误:

Traceback (most recent call last):
  File "C:\work_asaaki\code\generateProposals.py", line 48, in <module>
    img = rgb2gray(img)
  File "C:\Anaconda\lib\site-packages\skimage\color\colorconv.py", line 635, in rgb2gray
    if rgb.ndim == 2:
AttributeError: 'NoneType' object has no attribute 'ndim'

问题可能是什么?如何修复它才能将图像转换为灰度?

【问题讨论】:

    标签: python opencv image-processing grayscale


    【解决方案1】:

    鉴于错误消息,您的问题是 imread 调用失败,这意味着 imgis None。

    imread调用失败的原因通常是文件路径错误。

    【讨论】:

    • 就是这样。这些文件都是 png,但我在 myfile 路径中使用 .jpg。
    猜你喜欢
    • 2020-12-11
    • 2021-02-19
    • 2019-08-11
    • 1970-01-01
    • 2021-07-31
    • 1970-01-01
    • 2018-07-07
    • 1970-01-01
    • 2018-07-19
    相关资源
    最近更新 更多