![]() |
show grayscale image using matplotlib - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: show grayscale image using matplotlib (/thread-5988.html) |
show grayscale image using matplotlib - zyb1003 - Oct-31-2017 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) RE: show grayscale image using matplotlib - heiner55 - Nov-01-2017 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() |