Phillip M. Feldman
Phillip M. Feldman

Reputation: 546

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

Upvotes: 0

Views: 864

Answers (1)

par
par

Reputation: 143

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

Upvotes: 1

Related Questions