Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在我将2D灰度PIL图像转换为1D numpy阵列后,获得2D numpy阵列(图像/矩阵)的最平滑方法是什么?_Python_Arrays_Numpy_Python Imaging Library - Fatal编程技术网

Python 在我将2D灰度PIL图像转换为1D numpy阵列后,获得2D numpy阵列(图像/矩阵)的最平滑方法是什么?

Python 在我将2D灰度PIL图像转换为1D numpy阵列后,获得2D numpy阵列(图像/矩阵)的最平滑方法是什么?,python,arrays,numpy,python-imaging-library,Python,Arrays,Numpy,Python Imaging Library,我的代码如下所示: 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", 我需要将一维数组洗牌,使其成为二维数组,以便可以访问(x,y)像素。最顺利的方法是什么 我得到了上述错误: IndexError: too many indices fo

我的代码如下所示:

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",
我需要将一维数组洗牌,使其成为二维数组,以便可以访问(x,y)像素。最顺利的方法是什么

我得到了上述错误:

IndexError: too many indices for array
编辑:

下面是执行上述代码后从终端收集的一些信息。np.asarray()显然在做一些事情,关于图像尺寸的信息仍然包含在ndarray
pix
--
数组(,dtype=object)

>>img
>>>皮克斯
数组(,dtype=object)
>>>类型(img)
>>>类型(pix)
>>>img.size
(1280, 1080)
>>>像素大小
1.
如果您可以使用scipy:

from scipy import ndimage
image = ndimage.imread('image.png')
image.shape

您可以在
numpy
中使用
.flat()
抱歉,我感到困惑-我认为flat()将数组折叠为一维-这与我想要的相反。我需要在PIL图像中使用seek()函数来处理多页TIFF(TIFF堆栈)。
from scipy import ndimage
image = ndimage.imread('image.png')
image.shape