Why is the bmp image displayed as the wrong color using plt.imshow matplotlib on an IPython laptop?

There is a bmp image, as shown in the first image below, and its information is displayed as the second image below. But when displayed with the plt.imshow () function matplotlib on an IPython laptop, it has the wrong color, like the third image below. So can I know the reason?
Thank!

enter image description here

enter image description here

enter image description here


Source file shared in dropbox https://dl.dropboxusercontent.com/u/26518813/test2.bmp

And the code for showing the image on IPython-notebook:

%pylab inline --no-import-all
from PIL import Image
plt.imshow(Image.open("./test/test2.bmp")) 
+3
source share
1 answer

, matplotlib.pyplot. Matplotlib .bmp , , CMAP . . , cmap="gray".

from PIL import Image
img= Image.open(r'./test/test2.bmp')
plt.imshow(img,cmap='gray',vmin=0,vmax=255)

, vmin vmax, , , python . PIL:

img=matplotlib.image.imread(r'/Users/giacomo/Downloads/test2.bmp')
plt.imshow(img,cmap='gray',vmin=0,vmax=255)

PIL .png .

PIL.Image, :

from PIL import Image
img= Image.open( r'./test/test2.bmp')
img.show()

, I-Python Notebook,

- 'P' ( : , ImagePalette, ). .convert, matplotlib plt.imshow:

convertedimg=img.convert('P')
plt.imshow(convertedimg)

enter image description here

+6

All Articles