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?
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With