简体   繁体   中英

Pillow issue: grayscale image unexpectedly rendered in color

When I load a grayscale JPEG image using Pillow.Image.open() and plot it using pyplot.image() , the result has unexpected garish colors. I suspect that I'm doing something wrong. Any advice will be appreciated. Here's my code:

from matplotlib import pyplot
from PIL import Image

image_array= Image.open('01.Ned and Clara.jpg')
pyplot.imshow(image_array)
pyplot.show()

Phillip

You can use the colormap to force grayscale

from matplotlib import pyplot
from PIL import Image
import matplotlib.cm as cm

image_array= Image.open('01.Ned and Clara.jpg')
pyplot.imshow(image_array,cmap = cm.Greys_r)
pyplot.show()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM