Reputation:
I have a png image as follows:
I wrote the following script to read into matplotlib.
import numpy as np, matplotlib.pyplot as plt
from PIL import Image
fi = "map.png"
data = np.array(Image.open(fi))
print data.shape
plt.imshow(data)
plt.show()
But the image looks different.
How to make it look similiar to the first one?
I mean, the colors.
Upvotes: 1
Views: 300
Reputation: 460
The image you have provided is not a Grayscale image
import matplotlib.pyplot as plot
import matplotlib.image as image_rgb
image = image_rgb.imread("image.png")
plot.imshow(image)
plot.show()
I have not used the PIL library and it produces apt results.
Upvotes: 0
Reputation: 25518
Matplotlib handles images much more transparently if you use the mpimg package:
import numpy as np, matplotlib.pyplot as plt
import matplotlib.image as mpimg
fi = "map.png"
data = mpimg.imread(fi)
print(data.shape)
plt.imshow(data)
plt.show()
Upvotes: 1