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

Image.show() problem with I;16 mode TIFFs #4729

Closed
feldroop opened this issue Jun 25, 2020 · 6 comments · Fixed by #4744
Closed

Image.show() problem with I;16 mode TIFFs #4729

feldroop opened this issue Jun 25, 2020 · 6 comments · Fixed by #4744
Labels
Bug Any unexpected behavior, until confirmed feature.

Comments

@feldroop
Copy link

feldroop commented Jun 25, 2020

What did you do?

Loaded a 16 bit integer TIFF file and showed it.

What did you expect to happen?

That the image looks exactly the same as when opened manually.

What actually happened?

It looked very different.

I can't share the original image I am working with, but it becomes almost completely white, whereas it was mostly black before.

I generated another example (code below). I can't upload it here, because GitHub doesn't accept .tif.

The black one on the left side is the actual correct one opened manually.

Screenshot

The problem might be the temporary conversion to BMP. (Uneducated guess)

What are your OS, Python and Pillow versions?

  • OS: Windows 10 and WSL Ubuntu 18.04
  • Python: 3.8.2
  • Pillow: 7.1.2
from PIL import Image 

# code used to generate the example image
# img = Image.new('I;16', (1000,1000), 70)

# code that causes issue
with Image.open('test_generated.tif') as img:
    print(img.mode) # I;16
    print(img.format) # TIFF 
    img.show()

EDIT:
test_generated.zip

@radarhere
Copy link
Member

If you compress your original image into a zip or tgz, then you should be able to upload it.

@wiredfool
Copy link
Member

I'm pretty sure it's because the default conversions are using the 0-255 range of the i;16 and clipping the rest to 255.

@feldroop
Copy link
Author

If you compress your original image into a zip or tgz, then you should be able to upload it.

I'm not allowed to share it. The generated example is enough to reproduce and analyze the error, isn't it?
I uploaded it as a .zip.

I'm pretty sure it's because the default conversions are using the 0-255 range of the i;16 and clipping the rest to 255.

When generating the example picture (code above) I used higher number than 255 for the intensitiy (instead of now 70). They all produced blank white images. Makes sense regarding your explanation.

@radarhere
Copy link
Member

I was just reading your message that you couldn't upload a .tif, and trying to offer a solution.

Regarding your problem, it's something of a known issue. See #3159, and the related #3011

@nulano
Copy link
Contributor

nulano commented Jun 26, 2020

Note that #4080 was merged and released in 7.1.0, meaning that show should now always convert the image to PNG, not BMP. However, due to the following line, images are always converted to a different mode unless they are in one of 1, RGBA, or LA modes:

image.mode in ("1", "RGBA") or (self.format == "PNG" and image.mode == "LA")

This is likely no longer necessary, since PNG supports I;16 mode, as well as most (if not all) others.

@radarhere
Copy link
Member

Thanks @nulano. I've created PR #4744 accordingly.

@radarhere radarhere added the Bug Any unexpected behavior, until confirmed feature. label Jun 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Any unexpected behavior, until confirmed feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants