python - PIL属性错误: Shape when creating an array

标签 python numpy scipy python-imaging-library

我正在尝试使用 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/

相关文章:

python - 单对象迭代器

python - 如何在适用于 python 3.8 的 AWS lambda 上安装 Pillow?

python - 以其他列组的最大值为条件计算新列

python - numpy 条件列表成员元素明智

python - 获取 Python 函数并生成所有导数

python - 打印时对齐小数点

python - Python jsonschema 验证器是否使用实际 jsonschema 的超集?

c++ - 将 2D numpy 数组转换为 C++ short**?

python-3.x - 如何获取 numpy 3-D 数组的对角线分量?

python - 求解前一时间步的 ODE 函数(延迟微分方程)