2017-04-24 162 views
0

我正在尝试将一堆图像像素数据加载到numpy数组中,但是遇到了解决如何填充dtype字段的问题。将图像加载到numpy数组中

我的图片128×128与型UINT8尺寸×3和装载如下:

import glob 
from scipy import misc 
images = np.fromiter((misc.imread(path) for path in glob.glob('images/*.png')), <dtype_field>) 

misc.imread负载的每一个图像作为numpy的阵列,但我面临的课题是转动的此列表将自己图像成一个numpy数组。

试过以下,以及,但不工作:

images = [misc.imread(path) for path in glob.glob('extra_signs/*.png')] 
images = np.asarray(images) 

从哪里获得以下错误:

ValueError: could not broadcast input array from shape (128,128,3) into shape (128,128)

设置到D型投np.uint8以下错误:

ValueError: setting an array element with a sequence.

说明:我看了在附近的计算器中,我发现如何将图像读入numpy数组,但没有将所有图像读入单个数组。

+1

它看起来像你的一个图像不是128x128x3。你确定文件中没有128x128形状的单色图像吗? –

+0

@WarrenWeckesser“单色图像”是“灰度”图像的一个奇特词汇吗? – kmario23

+0

@WarrenWeckesser你几乎是对的。原来我有一个4通道深度的图像。不知道那里出了什么问题,但是我用另一个正常深度为3的工具替换了它,并且工作正常。谢谢沃伦! –

回答

2

检查您正在阅读的所有图像的大小。显然至少有一个不是128x128x3。