我的代码如下所示:
img = Image.open(path)
pix = np.asarray(img)
# i tried to access an (x,y) pixel and found the array was one dimensional
print str(float(pix[1,1])), "\t",
我需要洗牌的一维数组,使它是2D,以便我可以访问(x,y)像素。做这件事最顺利的方法是什么?
对于上述情况,我得到这个错误:
IndexError: too many indices for array
编辑:
下面是执行上述代码后从终端收集的一些信息。np.asarray()显然在做一些事情,关于图像维数的信息仍然包含在ndarray pix
-- array(<PIL.TiffImagePlugin.TiffImageFile image mode=I;16 size=1280x1080 at 0x110CA9F38>, dtype=object)
中。
>>> img
<PIL.TiffImagePlugin.TiffImageFile image mode=I;16 size=1280x1080 at 0x110CA9F38>
>>> pix
array(<PIL.TiffImagePlugin.TiffImageFile image mode=I;16 size=1280x1080 at 0x110CA9F38>, dtype=object)
>>> type(img)
<type 'instance'>
>>> type(pix)
<type 'numpy.ndarray'>
>>> img.size
(1280, 1080)
>>> pix.size
1
发布于 2015-05-27 15:59:43
如果你能用枕木:
from scipy import ndimage
image = ndimage.imread('image.png')
image.shape
https://stackoverflow.com/questions/30494869
复制