Reputation: 2289
I have the following mammogram image and I am trying to read this using PIL image and then plot it using matplotlib:
The code I am using is:
%matplotlib inline
from PIL import Image
from matplotlib.pyplot import imshow
from scipy.misc import imread
path = './sample.png'
image = Image.open(path).convert('RGB')
imshow(image)
But I am getting this image:
Why it's not showing the correct image?
Upvotes: 4
Views: 2965
Reputation: 36695
You have to convert image after loading to numpy array to process with matplotlib. To show image in grey scale use grey
colormap over-vise image will be shown in color mode.
import matplotlib.pyplot as plt
from PIL import Image
import numpy as np
from matplotlib.pyplot import imshow
from scipy.misc import imread
path = './1.png'
image = Image.open(path)
plt.imshow(np.asarray(image), cmap='gray')
plt.show()
Upvotes: 7