python - 在 python 中显示 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(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/

相关文章:

matlab - 在 MATLAB GUI 弹出菜单中写入指数

arrays - 在matlab中对结构体中的数据进行向量化

python - 导入 nltk 时反复出现的问题

html - 当 html 标签没有设置背景颜色时,为什么 body 背景图像不包含在 body 中?

html - 如何在 div 中居中(背景)图像?

matlab - 如何在 MATLAB 中将元胞数组的元胞数组合并为单个元胞数组

python - 截取一个应用程序,不管它前面是什么?

python - 混合属性的过滤器计算结果为 "where false"

python - 无法在 Python 中使用 xor 符号生成 unicode 字符串文字?

ruby-on-rails - 当前版本的 rmagick gem (2.13.1) 不适用于当前版本的 ImageMagick (6.6.4)