user961627
user961627

Reputation: 12747

skimage's rgb2gray in python: AttributeError: Nonetype object has no attribute ndim

I was using this code (with skimage version 0.10.0) as far as I can remember without issues:

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

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

But now I'm getting this error:

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'

What could the problem possibly be? How can I fix it to be able to convert the image to grayscale?

Upvotes: 2

Views: 12754

Answers (1)

Hannes Ovr&#233;n
Hannes Ovr&#233;n

Reputation: 21831

Given the error message your problem is that the imread call fails, which means imgis None.

Reason for why the imread call fails is usually that the path to the file is wrong.

Upvotes: 5

Related Questions