I have a numpy ndarray that looks something like:
(我有一个看起来像的numpy ndarray:)
[[0, 0.25, 1, ...., 0.5, 0.23 ],
[0.3, 0.75, 1, ..., 0.5, 0.37 ],
...,
...,
[0, 0.25, 1, ...., 0.5, 0.23 ],
[0.3, 0.75, 1, ..., 0.5, 0.37 ]]
Basically every value is in the range 0 - 1.0
(基本上每个值都在0-1.0的范围内)
I would like to visualize this as a bitmap and currently I have a very slow loop which basically does this:
(我想将其可视化为位图,目前我有一个很慢的循环,基本上可以这样做:)
for i, row in enumerate(data):
for j, val in enumerate(row):
yield val_to_rgb(val)
It then will take the 3-tuple of rgb components and do a PIL putdata on it and create a PNG.
(然后它将使用三元组的rgb组件,并对其进行PIL putdata并创建PNG。)
I need to do this many times and this ghetto method is slow, and the colorization is very ugly.
(我需要做很多次,而且这种贫民窟的方法很慢,而且着色很丑陋。)
My question is this:
(我的问题是这样的:)
Is there a series of matrix operations I can apply which will yield a colorized matrix containing the raw RGB values?
(我可以应用一系列矩阵运算,以产生包含原始RGB值的彩色矩阵吗?)
Which really consists of two questions:
(其中实际上包含两个问题:)
- What is the most efficient transformation I can apply to get RGB tuples from the above matrix
(我可以应用最有效的变换来从上述矩阵中获取RGB元组)
- Is there a "nice" way to convert (0, 1.0) values into a colorized representation?
(有没有一种“不错”的方法可以将(0,1.0)值转换为彩色表示形式?)
Edit: Clarification- I'm looking to SAVE this as PNG, not just view it in real time.
(编辑:澄清-我希望将其另存为PNG,而不仅仅是实时查看。)
The reason being that a lot of this is getting executed on a headless machine which I then inspect after the fact. (原因是很多这样的事情都是在无头机器上执行的,后来我检查了一下。)
The output of the current algo looks pretty nasty:
(当前算法的输出看起来很讨厌:)
ask by amirpc translate from so