Alex Z
Alex Z

Reputation: 1539

matplotlib changing bitmap color mapping

I'm using matplotlib to generate some composite figures (from raw data and images). I'm trying to get the script to take image files of a few file formats, which are then plotted via:

Nxy = mpimg.imread(Nxy_filename)
imgplot = ax1.imshow(Nxy)

where ax1 is the subplot I want the image to show up in. This works fine for both PNG and JPEG images, but for a .bmp (of the same image) matplotlib seems to turn it blue, i.e.

enter image description here

turns into:

enter image description here

in my composite figure. On the other hand, the png and jpg files look exactly the same as the original. Any idea why this would happen? I'm reluctant to blindly alter the color map in the code since the other image formats appear as expected.

Upvotes: 0

Views: 201

Answers (1)

Molly
Molly

Reputation: 13610

It sounds like your PNG and JPEG images are RGB images that happen to be grey while the BMP image is grey scale. Check the shape of Nxy. My guess is it's two dimensional for the BMP while the PNG and JPEG image arrays have three dimensions.

Upvotes: 2

Related Questions