Convert RGB Image to Grayscale and Display It (Python + Matplotlib) I just started learning image processing and I was trying to read a RGB image then convert it to grayscale. I was hoping for something like this:



However, what I get was:



I tried using both scipy and PIL but they yield the same results. Am I lacking of understanding about grayscale image here?

Using scipy:

from scipy import misc
car = misc.imread('image.jpg', mode="L")
plt.imshow(car)


Using PIL:

from PIL import Image
pil_im = Image.open('image.jpg')
pil_imgray = pil_im.convert('LA')

img = np.array(list(pil_imgray.getdata(band=0)), float)
img.shape = (pil_imgray.size[1], pil_imgray.size[0])
plt.imshow(img)
You need to set the cmap properties of the imshow() function:

https://matplotlib.org/devdocs/api/_as_gen/matplotlib.pyplot.imshow.html

Use:

plt.imshow(img, cmap = "gray")