我有一个Numpy数组类型的矩阵.我如何将其作为图像写入磁盘?任何格式都有效(png,jpeg,bmp ......).一个重要的限制是PIL不存在.
我试图在numpy中使用fft模块:
import Image, numpy
i = Image.open('img.png')
a = numpy.asarray(i, numpy.uint8)
b = abs(numpy.fft.rfft2(a))
b = numpy.uint8(b)
j = Image.fromarray(b)
j.save('img2.png')
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试将numpy数组转换回PIL图像时,我收到错误:
TypeError: Cannot handle this data type
Run Code Online (Sandbox Code Playgroud)
但是,a和b数组似乎都具有相同的数据类型(uint8),并且Image.fromarray(a)运行正常.我注意到形状略有不同(a.shape =(1840,3264,3)vs b.shape =(1840,3264,2)).
我确实解决了这个问题并找出了PIL接受的数据类型?