简体   繁体   English

Python在两个gif图像上应用logical_xor函数会返回错误ValueError:图像的模式错误

[英]Python applying logical_xor function on two gif images returns the error ValueError: image has wrong mode

I have two gif images and I need to do logical_xor on them from PIL library This is my code: 我有两个gif图像,我需要从PIL库中对其进行逻辑处理。这是我的代码:

from PIL import Image

image = Image.open("image.gif") key = Image.open("key.gif")

test = image.mode == key.mode

print(test)

def logical_xor(image1, image2): """Logical XOR between two images. .. code-block:: python out = ((bool(image1) != bool(image2)) % MAX) :rtype: :py:class:~PIL.Image.Image """

   image1.load()
   image2.load()
   return image1._new(image1.im.chop_xor(image2.im))

secret = logical_xor(image, key)

I am getting this error:

True Traceback (most recent call last): File "C:/Users/negut_000/OneDrive/Scoala/Crypto/Image Encrypt Decrypt OTP/Encrypt.py", line 24, in <module> secret = logical_xor(image, key) File "C:/Users/negut_000/OneDrive/Scoala/Crypto/Image Encrypt Decrypt OTP/Encrypt.py", line 21, in logical_xor return image1._new(image1.im.chop_xor(image2.im)) ValueError: image has wrong mode Process finished with exit code 1

It seems that the images have the same mode so I don't understand the problem. 看来图像具有相同的模式,所以我不明白问题所在。 Please help! 请帮忙!

Using instead of 使用代替

   image = Image.open("image.gif")
   key = Image.open("key.gif")

This code 这段代码

image = Image.open("image.gif", mode='r').convert("1")
key = Image.open("key.gif", mode='r').convert("1")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM