2017-10-17 157 views
2

我有以下的乳房X线照片图像和我想读这个使用PIL图像,然后使用matplotlib绘制它:PIL图像和matplotlib阴谋被饱和的黑色和白色png图片

enter image description here

代码我现在用的就是:

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

但我得到这个图片:

enter image description here

为什么它不显示正确的图像?

回答

2

你必须在加载到numpy数组后才能将图像转换为使用matplotlib进行处理。要以灰度显示图像,请使用grey colormap over-vise图像将以彩色模式显示。

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

enter image description here