python - 从 RGB 值在 Google Collab 中打印图像
问题描述
我分别有 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]]
解决方案
完毕!
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()
推荐阅读
- python - 即使打包已安装,Pyp3 也会给出 ModuleNotFoundError
- blockchain - indy-node 和 indy-sdk 有什么区别?
- html - 使用 {{currentDate | 获取接下来的两个月 日期:'MMM'}}
- google-analytics - 分析显示 fbclid 和 fblogin.htm 但我不应该拥有它们
- html - 从 URL 中填充模态文本(引导程序)
- oracle - 如何在 oracle 19c 的 MERGE 语句中使用提交?
- javascript - 构造 DTO 而不显式命名值
- image - pdf Flutter,如何将资产中的图像(JPG/PNG等)附加到pdf中
- python-3.x - 运行雅虎财务模块时出现错误
- ember.js - 如何在 Ember JS 的轮播中显示视频