Skip to content

16-bit integer TIFF fails to load as expected #5248

@pkgw

Description

@pkgw

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:

# before running code: convert image to PNG in GIMP, save as `gimp-good.png`
import numpy as np
from PIL import Image, ImageCms

img_cnv = Image.open('gimp-good.png')
arr_cnv = np.asarray(img_cnv)
print(arr_cnv[200,200])  # corners of image are full black
<<< [7 3 1] 

What actually happened?

Doing the conversion myself, nothing happens, and the resulting values are very wrong:

import numpy as np
from PIL import Image, ImageCms
from io import BytesIO

img_orig = Image.open('gemini1210a.tif')
img_orig = img_orig.convert('RGB')  # image reads as RGBX mode, but X channel is all 255s; seems to be unrelated
arr_orig = np.asarray(img_orig)

in_prof = ImageCms.getOpenProfile(BytesIO(img_orig.info['icc_profile']))
out_prof = ImageCms.createProfile('sRGB')
xform = ImageCms.buildTransform(in_prof, out_prof, 'RGB', 'RGB')
img_xform = ImageCms.applyTransform(img_orig, xform)
arr_xform = np.asarray(img_xform)

print(arr_orig[200,200], arr_xform[200,200])
<<< [132  10 120] [132  10 120]

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?

  • OS: Linux, Fedora 33
  • Python: 3.8.6 (conda-forge)
  • Pillow: 8.1.0 (conda-forge)

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    AnacondaIssues with Anaconda's PillowTIFF

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions