Why matplotlib.pyplot.imsave() and matplotlib.pyplot.imshow() image qualities are different? How to ensure the same quality?

iamai picture iamai · Jan 6, 2019 · Viewed 19.9k times · Source

Seems matplotlib.imsave() lightens the image when compared to that of matplotlib.imshow(). For example, look at the code below.

import imageio
import matplotlib.pyplot as plt
image = imageio.imread('image.jpg')
plt.imshow(image)
plt.imsave('image_new.jpg',image )

image_new = imageio.imread('image_new.jpg')
plt.imshow(image_new)

Saved image 'image_new.jpg' (right) is slightly lighter than 'image.jpg' (left)

image.jpg image_new.jpg

image_source: https://c1.staticflickr.com/9/8191/8424182610_e23dcc6b4d_b.jpg

Answer