如何在numpy中将3d图像数组转换为2d图像数组 [英] How do I convert a 3d image array into 2d image array in numpy
本文介绍了如何在numpy中将3d图像数组转换为2d图像数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将图像的3D数组存储在Numpy数组中.使用一种算法,我将RGB图像转换为灰度图像.但是在第三维中,RGB值是相同的(对于灰色,RGB值是相同的),我想将所有三个值都转换为一,从而将3D数组转换为2D.
I have a 3D array of a image stored in Numpy array. Using an algorithm, I converted the RGB image into Grayscale. But in the third dimension the RGB values are same (for gray, the RGB values are same) and I want to convert all the three values into one and thus converting the 3D array into 2D.
即 当前的3d数组是:
i.e the current 3d array is:
[[[24 24 24] [36 36 36].......[108 108 108]]
[[196 196 196] [45 45 45] ..... [90 90 90]]
...........................................
...........................................
[[80 80 80] [74 74 74] ..........[127 127 127]]]
我想要的2D数组是:
[[24 36 ..........108]
[196 45 ......... 90]
[80 74 ..........127]]
我该如何实现?
推荐答案
可以使用切片语法实现
a[:,:,0]
这篇关于如何在numpy中将3d图像数组转换为2d图像数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文