-3

I am following https://www.analyticsvidhya.com/blog/2014/12/image-processing-python-basics/ to practice image processing.

I am writing the code in an incremental way and checking if everything goes well. So far I have written the following code

from matplotlib import pyplot as plt
from skimage import data
from skimage.feature import blob_dog, blob_log, blob_doh
from math import sqrt
from skimage.color import rgb2gray
import glob
from skimage.io import imread

example_file=glob.glob(r"/home/snowbell/sample.jpg")[0]
im=imread(example_file, as_grey=True)
plt.imshow(im, cmap=cm.gray)
plt.show()

The image location and the image name is only thing I have changed. I am getting the following error:-

Traceback (most recent call last):
  File "test.py", line 11, in <module>
    plt.imshow(im, cmap=cm.gray)
NameError: name 'cm' is not defined
3
  • Just a note : this looks more like a programming question rather than something Unix-related. PS: A simple google search after your NameError would yield lots of helpful results. Commented Jan 12, 2017 at 11:11
  • What did you expect cm.gray to produce? You never defined the name cm nor did you import it. Commented Jan 12, 2017 at 13:26
  • Does this answer your question? python name error name not defined Commented May 20, 2021 at 0:29

1 Answer 1

10

from matplotlib import cm should work. Or import matplotlib.cm as cm

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.