我有一个像这样的 rgb 矩阵:
image=[[(12,14,15),(23,45,56),(,45,56,78),(93,45,67)],
[(r,g,b),(r,g,b),(r,g,b),(r,g,b)],
[(r,g,b),(r,g,b),(r,g,b),(r,g,b)],
..........,
[()()()()]
]
我想显示包含上述矩阵的图像。
我用这个函数来显示灰度图像:
def displayImage(image):
displayList=numpy.array(image).T
im1 = Image.fromarray(displayList)
im1.show()
argument(image)有矩阵
有人帮我怎么显示rgb矩阵
最佳答案
matplotlib 库中的
imshow 将完成这项工作
关键是您的 NumPy 数组具有正确的形状:
高 x 宽 x 3
(或 RGBA 的高度 x 宽度 x 4)
>>> import os
>>> # fetching a random png image from my home directory, which has size 258 x 384
>>> img_file = os.path.expanduser("test-1.png")
>>> from scipy import misc
>>> # read this image in as a NumPy array, using imread from scipy.misc
>>> M = misc.imread(img_file)
>>> M.shape # imread imports as RGBA, so the last dimension is the alpha channel
array([258, 384, 4])
>>> # now display the image from the raw NumPy array:
>>> from matplotlib import pyplot as PLT
>>> PLT.imshow(M)
>>> PLT.show()
关于python - 在 python 中显示 rgb 矩阵图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22777660/