b=ndimage.gaussian_filter(imagefile,5)
是python的新手,无法解决这个问题.
如何将b保存为图像,b的类型为’numpy.ndarray’?
试过这些,
1.
im = Image.fromarray(b)
im.save("newfile.jpeg")
错误:TypeError(“无法处理此数据类型”)
2.
imsave('newfile.jpg', b)
错误:ValueError:’arr’没有适合任何模式的数组形状.
将ndarray保存到图像中的正确方法是什么?
编辑:
解决了:
im = Image.fromarray(b)
im.save(‘newfile.jpeg’)工作,我加载图像的方式是错误的,
file = Image.open("abc.jpg")
imagefile = file.load()
//我在加载后使用的是imagefile,它没有给出正确的形状来重建图像.
//相反如果我使用文件(即打开后直接,我可以通过上面的方法保存)
解决方法:
我认为最好的方法是使用matplotlib imshow.
使用图像库:
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版本:
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")
希望这可以帮助!
标签:python