【问题标题】:PIL ValueError: Images do not matchPIL ValueError:图像不匹配
【发布时间】:2018-10-22 08:10:46
【问题描述】:

我一直在用 PIL 在 python 中搞乱,我正在研究一个在 4 个象限中镜像和成像的函数。显然我有一个错误,我似乎无法弄清楚。我的功能如下:

def mirror_four(image):
x = image.size[0]
y = image.size[1]

temp = Image.new("RGB", (image.size[0], image.size[1]), "black")

tl = image
tr = mirror_left(image)
bl = mirror_verticle(image)
br = mirror_verticle(tr)

image.paste(temp,(0,0,int(x/2),int(y/2)),tl)
image.paste(temp,(int(x/2),0,0,int(y/2)),tr)
image.paste(temp,(0,int(y/2),int(x/2),0),bl)
image.paste(temp,(x/2,y/2,x,y),br)

return temp

这会返回错误:ValueError: Images do not match

我有点迷茫,PIL 文档对我帮助不大。提前感谢您的帮助!

【问题讨论】:

  • 你发现了吗?我遇到了类似的问题,但无法弄清楚。

标签: python image python-imaging-library valueerror


【解决方案1】:

以您的第一个粘贴行为例 - 对于 'paste' 的 'box' 参数,您已指定 (0,0,int(x/2),int(y/2) - 大小的一半图像。但是,尝试粘贴的图像与框的大小不匹配。将“框”参数更改为 (0,0,int(x),int(y)) 将解决您的直接问题,尽管我怀疑您实际上想要裁剪正在粘贴的图像。

我还要注意,如果您不想 - (0,0),则不必提供要粘贴的图像的大小,因为 x 和 y 也可以。

【讨论】:

    【解决方案2】:

    您为 box 提供的参数错误。 应该是image.paste(the_second_image, (x, y, x+w, y+h) 不要更改最后两个参数。你可以做的是,w, h = the_second_image.size() image.paste(the_second_image, (x, y, x+w, y+h) 这行得通,对我有用。

    【讨论】:

      猜你喜欢
      • 2012-08-30
      • 2020-04-22
      • 2022-08-07
      • 2021-08-01
      • 2021-05-05
      • 1970-01-01
      • 2016-11-06
      • 2012-09-11
      • 2019-03-05
      相关资源
      最近更新 更多