2017-10-17 172 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