簡體   English   中英

Python在兩個gif圖像上應用logical_xor函數會返回錯誤ValueError:圖像的模式錯誤

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

我有兩個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

看來圖像具有相同的模式,所以我不明白問題所在。 請幫忙!

使用代替

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

這段代碼

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