Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9232701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:22:35+00:00 2026-06-18T06:22:35+00:00

I’m playing around with PIL and came across this problem and I can’t see

  • 0

I’m playing around with PIL and came across this problem and I can’t see where in the docs I’m going wrong. Here is my simple code

from PIL import Image
from PIL.ImageChops import difference

imageA = Image.open("image1.png")
imageB = Image.open("image2.png")

if imageA.size == imageB.size:
    diff = difference(imageA, imageB)
    diff.save("test.png")

which gives me the error

Traceback (most recent call last):
  File "C:\[XXX]\box-test.py", line 8, in <module>
    diff = difference(imageA, imageB)
  File "C:\Python32\lib\site-packages\PIL\ImageChops.py", line 123, in difference
    return image1._new(image1.im.chop_difference(image2.im))
ValueError: images do not match

Any help would be appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:22:36+00:00Added an answer on June 18, 2026 at 6:22 am

    The documentation for this function doesn’t tell much in fact. So let me try to clarify it a little. First, the sizes of the images are irrelevant to whether the function works or not, it internally checks for a size that both images fit.

    Now, when can you actually compare the images by using the function ImageChops.difference ?

    First, both images have to have pixels that can be stored in an unsigned byte. This is a very common type of image, but this excludes comparison between images even if they are the same mode. So, you cannot compare an image x and y when one or /both/ of them have a mode of: F, I, I;16, I;16L, I;16B, BGR;15, BGR;16, BGR;24, or BGR;32. Just to make it clear: it doesn’t matter if both images are in the same mode if they happen to be in one of the modes above, the function will refuse to work.

    So, the comparison can be done when the images are in the modes 1, P, L, LA, RGB, RGBA, RGBX, RGBa, CMYK, or YCbCr as long as they have the same number of bands. This means the images don’t have to have the same mode to be compared. For instance, difference(x.convert('CMYK'), x.convert('RGBA')) or difference(x.convert('1'), x.convert('P')) work just fine. Of course this means difference(x.convert('LA'), x.convert('L')), fails. Finally, the resulting image will always have the mode equal to the first image passed to the function.

    This is valid at least for the PIL 1.1.7.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.