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()显然在做一些事情,关于图像尺寸的信息仍然包含在ndarraypix
--数组(,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