Python Forum

Full Version: show grayscale image using matplotlib
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

Hello guys,

Now I used PIL to convert my image from RGB to Grayscale, and then I use the matplotlib to show the coordinate value and greyscale value of every pixel on image. The problem is the image shown on the screen doesn't looks like a greyscale image but it can successfully show me the pixel coordinate value and greyscale value of the image. I don't know why it happens.

from PIL import Image
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
img=Image.open('beam.jpg').convert('L')
img.save('gray_beam.jpg')
im=mpimg.imread('gray_beam.jpg')
a=plt.imshow(im)
plt.show(a)
from PIL import Image
import matplotlib.image as mpimg
import matplotlib.pyplot as plt

img=Image.open('beam.jpg').convert('L')
plt.imshow(img, cmap='gray')
plt.show()