Saving numpy.ndarray in python as an image
Saving numpy.ndarray in python as an image
I think the best approach is using matplotlib
imshow
.
using the image
library:
import Image
import numpy as np
x = np.array([[1, 2, 3], [4, 5, 6]], np.int32)
im = Image.fromarray(x)
im.save(test.png)
Matplotlib Version:
import numpy as np
import matplotlib.pyplot as plt
x = np.array([[1, 2, 3], [4, 5, 6]], np.int32)
plt.imshow(x)
plt.savefig(array)
Hope this helps!