在 Google colab 中从 RGB 值打印图像

问题描述 投票:0回答:1

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

例如:

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]]
python image opencv image-processing google-colaboratory
1个回答
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()
© www.soinside.com 2019 - 2024. All rights reserved.