numpy 3D图像阵列到2D [英] numpy 3D-image array to 2D

查看:131
本文介绍了numpy 3D图像阵列到2D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个灰色图像的 3D-numpy 数组,看起来像这样:

I have a 3D-numpy array of a gray image, which looks something like this:

[[[120,120,120],[67,67,67]]...]

显然我有每个RG和B相同,因为它是一个灰色图像 - 这是redundent。
我想得到一个新的2D数组,看起来像:

Obviously I have every R G and B the same because it is a gray image - this is redundent. I want to get a new 2D array which looks like:

[[120,67]...]

这意味着将每个像素的数组[x,x,x]仅取值x

Which means to take every pixel's array [x,x,x] to just the value x

我该怎么做?

推荐答案

如果你的形状 ndarray 是(M,N,3),那么你可以得到这样的(M,N)灰度图像:

If the shape of your ndarray is (M, N, 3), then you can get an (M, N) gray-scale image like this:

>>> gray = img[:,:,0]

这篇关于numpy 3D图像阵列到2D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆