繁体   English   中英

在python中显示rgb矩阵图像

[英]display an rgb matrix image in python

我有一个像这样的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()

参数(图像)具有矩阵

任何人都帮我如何显示rgb矩阵

impow在matplotlib库中将完成这项工作

重要的是你的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()

Matplotlib的内置函数imshow将让你这样做。

import matplotlib.pyplot as plt
def displayImage(image):
    plt.imshow(image)
    plt.show()

暂无
暂无

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

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