在python中显示rgb矩阵图像
我有一个rgb矩阵,类似这样:在python中显示rgb矩阵图像,python,image,matlab,matrix,rgb,Python,Image,Matlab,Matrix,Rgb,我有一个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(imag
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()
参数(图像)具有矩阵
任何人都可以帮助我如何显示rgb矩阵的内置函数imshow,您可以这样做
import matplotlib.pyplot as plt
def displayImage(image):
plt.imshow(image)
plt.show()
matplotlib库中的imshow将执行此任务
关键是您的NumPy阵列具有正确的形状:
高x宽x 3
(或RGBA的高度x宽度x 4)
此代码执行时没有错误,但没有显示任何错误。如果不使用matplotlib保存图像,但要打开图像,则需要添加“plt.show()”。我编辑了原始答案以反映这一点。这有一个纯白色的边界框和轴
>>> 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()