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")

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])

closed as off-topic by Peter K. Sep 13 '17 at 15:41

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "General programming questions are off-topic here, but can be asked on Stack Overflow." – Peter K.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    $\begingroup$ Welcome to DSP.SE! This is just an RTFM question about plt.imshow and, as such, is not a signal processing question. $\endgroup$ – Peter K. Sep 13 '17 at 15:42
  • $\begingroup$ It works for me: just use misc.imshow(car) instead of plt.imshow(car). $\endgroup$ – MBaz Sep 13 '17 at 15:45

You need to set the cmap properties of the imshow() function:



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


Not the answer you're looking for? Browse other questions tagged or ask your own question.