Image matplotlib.pyplot.imsave后端
我正在使用matplotlib.pyplot在Spyder中工作,希望将numpy数组保存到图像中。Image matplotlib.pyplot.imsave后端,image,numpy,matplotlib,scipy,backend,Image,Numpy,Matplotlib,Scipy,Backend,我正在使用matplotlib.pyplot在Spyder中工作,希望将numpy数组保存到图像中。 imsave()的文档说明,我可以保存的格式取决于后端。那么后端到底是什么呢?我似乎能够保存.tiff图像,但f.e.我希望它们保存为8位tiff,而不是RGB tiff。知道我可以在哪里更改吗?如果您试图从mat将阵列保存为tiff(没有轴标记ect),您最好使用 (假设您使用的是ipython--pylab,因此定义了rand) 写: import PIL.Image as Image im
imsave()的文档说明,我可以保存的格式取决于后端。那么后端到底是什么呢?我似乎能够保存.tiff图像,但f.e.我希望它们保存为8位tiff,而不是RGB tiff。知道我可以在哪里更改吗?如果您试图从mat将阵列保存为tiff(没有轴标记ect),您最好使用 (假设您使用的是
ipython--pylab
,因此定义了rand
)
写:
import PIL.Image as Image
im = Image.new('L',(100,100))
im.putdata(np.floor(rand(100,100) * 256).astype('uint8').ravel())
im.save('test.tif')
ravel()
很重要,putdata
需要的是序列(即1D)而不是数组
阅读:
im2 = Image.open('test.tif')
figure()
imshow(im2)
和输出文件:
$ tiffinfo test.tif
TIFF Directory at offset 0x8 (8)
Image Width: 100 Image Length: 100
Bits/Sample: 8
Compression Scheme: None
Photometric Interpretation: min-is-black
Rows/Strip: 100
Planar Configuration: single image plane
我担心
imsave
将在保存前对其应用cmap
并将其转换为RGB格式,因此无法获得RGB TIFF。我不喜欢PIL,但它可能是你想要的更好的选择。谢谢,这正是我想要的。太棒了,谢谢。我甚至没有想过使用PIL,因为我被困在了我的小盒子里;)