Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resizing produces different results for Pillow 6.2.2 and Pillow 8.0.1 #5039

Closed
tanujjain opened this issue Nov 12, 2020 · 9 comments
Closed
Labels
Anaconda Issues with Anaconda's Pillow

Comments

@tanujjain
Copy link

tanujjain commented Nov 12, 2020

What did you do?

Resized an RGB image (from (640, 480) to (8, 8)), with resample parameter set to Image.ANTIALIAS using Pillow 6.2.2 and saved the resized image. Then I upgraded the Pillow version to the latest (8.0.1) and repeated the above steps with the same image and same parameters. Then, reloaded both the resized images with Image.open and compared the resized images using == operator (of pillow images). To check equality, I then typecasted the resized images to numpy array and compared element by element.

What did you expect to happen?

I expected the resized images to be same for the same images across the mentioned Pillow versions. I see that the default value for parameter resample has changed across these versions, but since I fixed the resample parameter to the same value (Image.ANTIALIAS), I expect the resized images to be same. I see that another parameter reducing_gap has also been added after Pillow 6.2.2, but going through the source code, I don't really see how it should lead to a different behaviour if the default value None is used.

What actually happened?

The resized images compared to False when compared with == operator. When the resized images were typecasted to numpy array, most elements were different.

What are your OS, Python and Pillow versions?

  • OS: macOS Mojave, 10.14.6
  • Python: Python 3.6.12 :: Anaconda, Inc.
  • Pillow: 6.2.2 and 8.0.1

Ran the below code once for Pillow 6.2.2 and then for Pillow 8.0.1:

from PIL import Image
im = Image.open('/path/to/image.jpg')
im_res = im.resize((8, 8), Image.ANTIALIAS)
im_res.save('resized_image.jpg')

Then loaded the resized images:

from PIL import Image
im_622 = Image.open('resized_image_pil622.jpg')
im_801 = Image.open('resized_image_pil801.jpg')
im_622 == im_801  # returns False

Source image is attached.
ukbench00120

@radarhere
Copy link
Member

I'm not actually able to replicate this on my macOS 10.15 machine.

How did you install both versions of Pillow?

@tanujjain
Copy link
Author

tanujjain commented Nov 13, 2020

Steps to install:

  1. Create and activate a new conda environment
  2. Run pip install pillow==6.2.2
  3. Run code mentioned in the issue description
  4. Run pip install pillow==8.0.1

@wiredfool
Copy link
Member

wiredfool commented Nov 13, 2020

JPEG is a lossy format, and different versions of libjpeg will interpret it differently.

If you're worried about bit-for-bit differences, you need to use a lossless format like PNG.

@radarhere radarhere added JPEG and removed JPEG labels Nov 15, 2020
@radarhere
Copy link
Member

I wonder if this is the same as #5069 - if you run

from PIL import Image
print(Image.core.jpeglib_version)

in both situations, what do you get?

@tanujjain
Copy link
Author

tanujjain commented Nov 30, 2020

I get 9.0 in both cases.

@radarhere
Copy link
Member

Could you attach the images output by each version of Pillow?

@radarhere
Copy link
Member

Now that #5367 is merged, Pillow 8.3.0 should have different resizing results again to Pillow 8.2.0

@radarhere
Copy link
Member

If I try and run the following code on our macOS 10.15 CI

python3.6 -m pip install Pillow==6.2.2 --only-binary=:all:
python3.6 -c "from PIL import Image;im = Image.open('input.jpg');im_res = im.resize((8, 8), Image.ANTIALIAS);im_res.save('resized_image_622.jpg')"
python3.6 -m pip install Pillow==8.0.1 --only-binary=:all:
python3.6 -c "from PIL import Image;im = Image.open('input.jpg');im_res = im.resize((8, 8), Image.ANTIALIAS);im_res.save('resized_image_801.jpg')"
echo "Comparison"
python3.6 -c "from PIL import Image;im = Image.open('resized_image_622.jpg');im2 = Image.open('resized_image_801.jpg');print(im == im2)"

I find that the output matches - https://github.com/radarhere/pillow-wheels/runs/2904979445?check_suite_focus=true#step:4:346

@radarhere
Copy link
Member

From what I can see, Anaconda doesn't install Python 3.6 to start with anymore. You're on macOS 10.14 though so it seems conceivable that you just installed it a while ago.

Closing, as I'm not able to replicate. This can be re-opened if a way to replicate can be found.

@aclark4life aclark4life added the Anaconda Issues with Anaconda's Pillow label May 19, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Anaconda Issues with Anaconda's Pillow
Projects
None yet
Development

No branches or pull requests

4 participants