我正在尝试使用 PIL 扭曲两个不同尺寸的图像;具体来说,通过将 future 扭曲的目标图像的形状(大小)设置为 numpy 数组,我遇到了 AttributeError:
文件“C:\Anaconda2\lib\site-packages\PIL\Image.py”,第 632 行,getattr 引发属性错误(名称) 属性错误:形状
为什么会发生这种情况?我的印象是我不久前就在做这件事,而且工作得很好,更不用说我绝对不明白 python 不理解的是什么(形状属性应该采用这是没有问题的输入)
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)
关于python - PIL属性错误: Shape when creating an array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38609557/