Reputation: 371
I've created a mozaic image, such that a large picture consists of many tiny pictures. I can view this image just fine in the matplotlib viewer and I can zoom in to see all the tiny pictures. But when I save the image, no matter the extension, the image loses the zoom ability such that the tiny images become blurred when zooming in. Is there a way to save the image in full resolution? I have the image in rgb in a numpy array so if there are other libraries more suitable that would work too.
Upvotes: 1
Views: 2787
Reputation: 305
You can try imageio library: https://imageio.readthedocs.io/en/stable/userapi.html#imageio.imwrite
from imageio import imwrite
imwrite("image.png", array)
Upvotes: 0
Reputation: 114946
Another option is the small library that I wrote called numpngw
. If the numpy array is, say, img
(an array of 8-bit or 16-bit unsigned integers with shape (m, n, 3)), you could use:
from numpngw import write_png
write_png('output.png', img)
(If the array is floating point, you'll have to convert the values to unsigned integers. The PNG file format does not store floating point values.)
Upvotes: 0
Reputation:
I think you're being mislead by Windows's Photos Application here, which applies blur automatically if you zoom too much.
The image is being saved correctly with all pixel values by Matplotlib, you can check it by zooming again on the pixels of the loaded image.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
# save image
array = np.random.random((4000, 4000, 3))
plt.imsave("save.png", array)
# load image
img = mpimg.imread("save.png")
plt.imshow(img)
plt.show()
Upvotes: 2
Reputation: 1207
This should work :
from PIL import Image
Image.fromarray(numpy_img).save("img_path.png")
Upvotes: 3