【问题标题】:Printing image in Google collab from RGB values从 RGB 值在 Google colab 中打印图像
【发布时间】:2021-12-12 12:06:36
【问题描述】:

我分别有 3 个 R、G、B 值矩阵。如何使用这些值在 google collab 中渲染图像?

例如:

R-->
[[0.42901963 0.31078428 0.36038652 ... 0.27254903 0.4882353  0.24117649]
 [0.43333334 0.45294118 0.4764706  ... 0.49201334 0.4882353  0.3703206 ]
 [0.40980393 0.26734048 0.44509804 ... 0.5315686  0.20932277 0.23689204]
 ...
 [0.5388459  0.76791734 0.7519609  ... 0.08951493 0.2306132  0.04509804]
 [0.48431373 0.7684314  0.70000005 ... 0.24686275 0.18435073 0.08169503]
 [0.33529413 0.4490196  0.30335644 ... 0.06035676 0.01       0.00588235]]
G-->
[[0.4423529  0.5310728  0.42156866 ... 0.4647059  0.5256234  0.43725494]
 [0.4735859  0.45149118 0.42156866 ... 0.5572651  0.6411765  0.44465208]
 [0.5366665  0.43479633 0.54319084 ... 0.5909356  0.32078427 0.3945098 ]
 ...
 [0.23941179 0.14777678 0.15454468 ... 0.292549   0.4882353  0.39845172]
 [0.33411762 0.25010756 0.20251276 ... 0.40734947 0.46862745 0.23725492]
 [0.19942838 0.08862745 0.24450144 ... 0.25440764 0.4254902  0.28509802]]
B-->
[[0.40352952 0.39656913 0.51828635 ... 0.40019608 0.5226905  0.48695084]
 [0.424424   0.34313726 0.37058824 ... 0.6115687  0.47450972 0.41921562]
 [0.5156863  0.53137255 0.3509804  ... 0.66647065 0.23549022 0.43791977]
 ...
 [0.25509804 0.33137256 0.34705883 ... 0.37803924 0.39119145 0.32024965]
 [0.4019608  0.38627452 0.3292157  ... 0.37790114 0.26235297 0.15098041]
 [0.12568627 0.25450435 0.29607844 ... 0.20882358 0.32529414 0.15490198]]

【问题讨论】:

  • 你至少需要努力。你还没有表现出任何解决这个问题的尝试。 -- 您的 answer 仅取决于 matplotlib,而不取决于 google colab。这个问题似乎根本不是 google colab 特有的。

标签: python image opencv image-processing google-colaboratory


【解决方案1】:

完成!

R、G、B 数组大小为 32x32,所以我选择创建一个大小为 32x32x3 的 3d 矩阵。你可以相应地改变..

from matplotlib import pyplot as PLT

new_mat= np.zeros((32, 32, 3))
for i in range(32):
  for j in range(32):
    new_mat[i][j][0]=r[i][j]
    new_mat[i][j][1]=g[i][j]
    new_mat[i][j][2]=b[i][j]

PLT.imshow(new_mat)
PLT.show()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-28
    • 1970-01-01
    • 2021-08-14
    • 2018-08-17
    • 2021-09-12
    • 2019-06-20
    • 1970-01-01
    相关资源
    最近更新 更多