[英]How to convert three 3D numpy arrays to RGB matrix in python
I'm not even sure if it is possible, but I am pretty new to python. 我什至不确定是否可行,但是我对python还是很陌生。
I have three 3D datasets, each is a 64 x 64 x 50 numpy array. 我有三个3D数据集,每个数据集都是64 x 64 x 50 numpy数组。 I am trying to combine each 3D dataset into a single 3D RGB image, where each cell is represented by an RGB value, and each color channel represents values for a single dataset. 我正在尝试将每个3D数据集合并为一个3D RGB图像,其中每个单元格均由RGB值表示,每个颜色通道表示单个数据集的值。
For example, my data is three different isotopes measured in a rock, so I would like R to represent the values for oxygen-16, G = sulfur-32, and B = magnesium-24. 例如,我的数据是在一块岩石中测得的三种不同的同位素,因此我希望R代表氧16的值,G =硫32的值,B =镁24的值。
I have figured out how to normalize each isotope array to a discretized value between 0-255 with the following generalized equation: 我想出了如何使用以下广义方程将每个同位素阵列归一化为0-255之间的离散值:
new_arr = ((arr - arr.min()) * (1/(arr.max() - arr.min()) * 255).astype('uint8')
More specifically for my data, I have the following: 更具体而言,我的数据如下:
O16R = ((O16.get_data() - np.min(O16.get_data())) * (1/(np.max(O16.get_data()) - np.min(O16.get_data())) * 255).astype('uint8'))
S32G = ((S32.get_data() - np.min(S32.get_data())) * (1/(np.max(S32.get_data()) - np.min(S32.get_data())) * 255).astype('uint8'))
Mg24B = ((Mg24.get_data() - np.min(Mg24.get_data())) * (1/(np.max(Mg24.get_data()) - np.min(Mg24.get_data())) * 255).astype('uint8'))
Now, I would like to create another 64 x 64 x 50 3D array, with each index in the array defined by the RGB values corresponding to the indexed values defined above. 现在,我想创建另一个64 x 64 x 50 3D数组,该数组中的每个索引都由与上面定义的索引值相对应的RGB值定义。
For a simplified example, if I had small 2 x 1 arrays of: 举一个简化的例子,如果我有2个x 1小数组:
O16R = (151, 3)
S32G = (2 , 57)
Mg24B = (0, 111)
Then I need a resulting RGB nested matrix with values: 然后,我需要一个具有值的结果RGB嵌套矩阵:
RGB = ( [151,2,0] , [3,57,111] )
I figure that I need to create a for loop, but I haven't been able to figure it out. 我认为我需要创建一个for循环,但无法弄清楚。 This is what I have so far, but it doesn't parse the data. 到目前为止,这就是我所拥有的,但是它没有解析数据。
RGB = np.zeros(shape=(64,64,50))
for i in RGB:
RGB = ([O16R, S32G, Mg24B])
Any help would be appreciated. 任何帮助,将不胜感激。
IIUC, for you minimal example you can do either of the following: IIUC,对于您的最小示例,您可以执行以下任一操作:
# setup:
O16R = (151, 3)
S32G = (2 , 57)
Mg24B = (0, 111)
# using zip:
RGB = np.array(list(zip(O16R, S32G, Mg24B)))
# or just transposing the array:
RGB = np.array([O16R, S32G, Mg24B]).T
Both return: 两者都返回:
>>> RGB
array([[151, 2, 0],
[ 3, 57, 111]])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.