简体   繁体   English

如何在标准化 [0,1] 范围内保存 matplotlib 图形?

[英]How do I save a matplotlib figure in the normalized [0,1] range?

I am generating annotation files for image segmentation learning.我正在为图像分割学习生成注释文件。 For that I am relying on matplotlibs fill_between() method.为此,我依赖于 matplotlibs fill_between() 方法。 I need to save the figure borderless and in a value range of [0,1].我需要将图形保存为无边框且值范围为 [0,1]。

How do I do that?我怎么做?

I found out that fig.savefig() can pass arguments to the pillow backend when saving as.png, however i can not find the right arguments to pass to save it in [0,1] range instead of [0,255]我发现 fig.savefig() 可以在保存为.png 时将 arguments 传递到枕头后端,但是我找不到正确的 arguments 传递以将其保存在 [0,1] 范围而不是 [0,255]

You can't save a png image in a real valued range of [0,1] .无法将 png 图像保存在[0,1]的实际值范围内。 Image intensity values in RGB format are only defined for natural numbers of [0,255] . RGB 格式的图像强度值仅针对自然数[0,255]定义。 It would also makes little sense to visualise an image with such low intensity values, because it would appear pretty much black.将具有如此低强度值的图像可视化也没有什么意义,因为它看起来几乎是黑色的。

What you could do instead if you are interested in persisting your data is normalising your matrix to your range and save it as a numpy array instead using numpys save() function.如果您对保留数据感兴趣,您可以做的是将矩阵规范化到您的范围并将其保存为 numpy 数组,而不是使用 numpys save() function。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM