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
16-bit integer TIFF fails to load as expected #5248
Comments
Oh, of course, after filing one makes progress. GIMP reports that the image is in 16-bit integer format. The 4.3.0 release notes say: "Pillow now can read 16-bit multichannel TIFF files including files with alpha transparency. The image data is truncated to 8-bit precision." For my sample pixel at x,y = 200,200, GIMP reports RGB = 1924, 738, 376 = 0x0784, 0x02E2, 0x0178, which truncates to (about) the 7, 3, 1 as found by GIMP. It's not obvious to me where the Pillow values (132, 10, 120 = 0x84, 0x0A, 0x78) are coming from although you can see overlaps in the hex representations. |
@radarhere I've had cases where I've had comparable differences between what I've seen in an image viewer and what I've gotten out of Pillow, and the ultimate culprit has been color profiles, but yes, now I think the issue is the handling of the 16-bit integer data. |
Well it's pretty clear this is just truncation and just the LSB is taken by Pillow. I've tested loading via import imageio
img0 = imageio.imread('gemini1210a.tif', 'TIFF-PIL')[...,0:3]
img1 = imageio.imread('gemini1210a.tif', 'TIFF-FI')[...,0:3]
img2 = imageio.imread('gemini1210a.tif')[...,0:3] FI/tifffile return a uint16 array and for your pixel at (200,200) the value ['0x0784', '0x030a', '0x0178'] |
@kmilos I had the G channel being 738 = 0x02E2, not ending in 0x0A. Probably I just made a typo above, though — I remember that I had at least one other one. |
Testing, this image now loads correctly in Pillow 8.2.0 and later, thanks to #5364. import numpy as np
from PIL import Image, ImageCms
img_cnv = Image.open('gemini1210a.tif')
arr_cnv = np.asarray(img_cnv)
print(arr_cnv[200,200]) gives |
edit: the actual issue might have to do with 16-bit-int TIFF loading; see next comment. At first I thought that the issue was application of the color profile, but now I think probably not.
What did you do?
I am trying to work with this image (55 MiB TIFF) in Pillow. It's an astronomical image of a galaxy.
What did you expect to happen?
I want to convert the image to sRGB. If I do the transformation using GIMP, most of the image comes out close to black as you'd expect:
What actually happened?
Doing the conversion myself, nothing happens, and the resulting values are very wrong:
I'm not an expert in this stuff but I've experimented with various mode conversions, rendering intents, etc. and can't figure out a way to get the profile transform to actually do anything.
What are your OS, Python and Pillow versions?
Side note
The image's profile is labeled as being "sRGB IEC61966-2.1", so I am surprised that the values that GIMP obtains are so far off from the ones in the raw image as read by Pillow. Maybe an indication that there's a data format issue?
The text was updated successfully, but these errors were encountered: