我有一个numpy维度数组(10980x10980)。
当我使用matplotlib.image.imsave('file.tiff',data)
保存它时,viridis
伪着色方案会自动应用到绘图中。我这样做了,得到了一个480 MB的tiff文件。
如果我使用matplotlib.pyplot
保存相同的数字,
plt.imshow(data)
plt.colorbar()
plt.savefig('file.tiff')
我获得了一个大约1.5MB的文件。
这两个文件的tiff信息如下:
matplotlib.image.imsave
TIFF Directory at offset 0x8 (8)
Image Width: 10980 Image Length: 10980
Resolution: 100, 100 pixels/inch
Bits/Sample: 8
Compression Scheme: None
Photometric Interpretation: RGB color
Extra Samples: 1<unassoc-alpha>
Samples/Pixel: 4
Rows/Strip: 10980
Planar Configuration: single image plane
pyplot.savefig
TIFF Directory at offset 0x8 (8)
Image Width: 640 Image Length: 480
Resolution: 100, 100 pixels/inch
Bits/Sample: 8
Compression Scheme: None
Photometric Interpretation: RGB color
Extra Samples: 1<unassoc-alpha>
Samples/Pixel: 4
Rows/Strip: 480
Planar Configuration: single image plane
我们可以看到,plt.savefig已经将尺寸降到640x480。为什么是这样?以及如何改变这种状况?
发布于 2021-09-29 13:39:02
你在做两种不同的操作。
matplotlib.image.imsave('file.tiff',data)
将包含在“数据”中的数据保存到一个tiff中(本质上是一个可以作为图像查看的数组)。
plt.imshow(data); plt.colorbar(); plt.savefig('file.tiff')
正在创建matplotlib图形,显示存储在数据中的数据,然后使用默认参数(dpi等)。将这个数字保存为tiff。这两个语法都是正确的,这取决于您的用例是什么。
发布于 2021-09-29 13:34:45
根据Pyplot.Savefig的文档,如果没有设置dpi
参数,它将默认使用图形的dpi值,这会影响分辨率。
image.imsave
的文档声明它不影响解析。
编辑寻址作者对我的回答的评论: DPI仅仅是每英寸像素。图像大小=px/dpi= 1098/10 = 109.8英寸。10980/1 = 10980英寸,这使图像变大了100倍。
https://stackoverflow.com/questions/69377283
复制相似问题