我试图将nxnx3矩阵转换为RGB图像,其中矩阵中的每个空格都是[R,G,B]。我以为这很容易,但我遇到了一个奇怪的错误。在
我有这个图像:http://www.cs.brandeis.edu//~arya/test2.bmp
这只是一个10像素×10双像素位图,上面有一个红色的对角线,如你所见。在
下面是我的python代码:
import numpy as np
from PIL import Image
imm = Image.open("test2.bmp")
t = np.int32(imm)
print(t.shape) # (10,10,3)
new = Image.fromarray(t, mode="RGB")
new.save("test_output.bmp")
然后我得到这个图像:http://www.cs.brandeis.edu//~arya/test_out.bmp-与原始输出非常明显的不同。我会料到的图像.fromarray()为了塑造我的形象,我是不是错过了什么?在
谢谢你!在
Pillow文档说,"RGB" mode表示3x8位整数,但数组是由32位整数组成的。你能改成
np.int8(imm)
吗?在相关问题 更多 >
编程相关推荐