我想使用PillowPython模块获得一个浮动RGBA像素值的列表。在
到目前为止,我只能得到RGBA整数数据:
from PIL import Image
im = Image.open("Lenna.png")
im_alpha = im.convert('RGBA')
Pixels = list(im.getdata())
例如,这将得到我的示例((226,137,125,255),…) 但是,我不知道如何以浮点形式获取这些信息,例如((0.88627451,0.537254902,0.490196078,1),…)。在
我怎么能做到呢?在
这是我在RGB.png中使用的:
现在,请注意,它取决于.png的类型;例如,请参见http://www.schaik.com/pngsuite/pngsuite_bas_png.html以获取测试文件,对于^{} (即“3x16位rgb颜色”),打印输出为:
^{pr2}$因此,即使这是16位,值似乎跨越0-255,就像8位一样。在这种情况下,我们需要用255来缩放
numpy.divide
的数据,以获得0.0-1.0的浮动范围。。。在但是,如果使用索引/托盘png ^{} ,则可以得到:
所以现在矩阵的内容不代表RGB(A)值,而是调色板中的索引,所以除以255没有意义。在
最后,如果它是一个RGBA png,比如^{} ,那么也会得到alpha:
同样,即使这是16位png,值似乎也被缩放到255,因此除以255得到浮点值是有意义的。在
换句话说,用
numpy
和PIL来缩放矩阵值相对容易,但是,您应该确保矩阵的格式是正确的。。。在相关问题 更多 >
编程相关推荐