PIL attribute error: Shape when creating an array

PIL attribute error: Shape when creating an array

我正在尝试使用 PIL 扭曲两个不同大小的图像;具体来说,通过将未来扭曲目标图像的形状(大小)设置为 numpy 数组,我遇到了 AttributeError:

文件 "C:\Anaconda2\lib\site-packages\PIL\Image.py",第 632 行,在 getattr 中 引发 AttributeError(名称) 属性错误:形状

为什么会这样?我的印象是我前段时间正在做这件事并且它工作得很好,更不用说我完全不明白 python 不明白的是什么( shape 属性应该将其作为输入没有问题)

import skimage.io
from PIL import Image
import numpy as np


Img1 = Image.open(picture1 + ".png") 
Img1

Img2 = Image.open(picture2 + ".png")
Img2

r, c = Img2.shape[:2]

    # creates array for the future shape in x,y
corners = np.array([[0, 0],
                    [0, r],
                    [c, 0],
                    [c, r]])
...

此致,JJ

我认为 Image 对象具有 size 属性,数组具有 shape 属性。尝试在您的代码中重命名它。 (参见:http://effbot.org/imagingbook/image.htm