python-pillow / Pillow

Python Imaging Library (Fork)
https://python-pillow.org
Other
12.36k stars 2.24k forks source link

Fails to open OME-TIFF example data files #811

Closed anntzer closed 1 year ago

anntzer commented 10 years ago

OME-TIFF is a TIFF format that embeds some microscopy-specific metadata as an XML comment embedded in the TIFF header. Sample data is available at https://www.openmicroscopy.org/site/support/ome-model/ome-tiff/data.html, but PIL fails to open single-channel.ome.tiff (throwing OSError: cannot identify image file 'single-channel.ome.tiff').

hugovk commented 10 years ago

I'm not at a computer to test, but just to confirm: does this happen with Pillow (the PIL fork)? Which version of Pillow do you have?

anntzer commented 10 years ago

Yes, this is with Pillow 2.5.0, Python 3.4. I actually haven't tested this with PIL.

wiredfool commented 10 years ago

The actual problem with that file is that it is specified as a bigendian 8-bit signed integer format, which we don't have listed in the formats that we support. This past includes a mode line that will read the format and store it in an unsigned integer. Visual inspection of the image looks okay. The XML from the OME format shows up in the tags directory.

diff --git a/PIL/TiffImagePlugin.py b/PIL/TiffImagePlugin.py
index 2e49931..d96542a 100644
--- a/PIL/TiffImagePlugin.py
+++ b/PIL/TiffImagePlugin.py
@@ -185,6 +185,7 @@ OPEN_INFO = {
     (MM, 1, 1, 1, (1,), ()): ("1", "1"),
     (MM, 1, 1, 2, (1,), ()): ("1", "1;R"),
     (MM, 1, 1, 1, (8,), ()): ("L", "L"),
+    (MM, 1, 2, 1, (8,), ()): ("L", "L"), #signed 8 bit???
     (MM, 1, 1, 1, (8,8), (2,)): ("LA", "LA"),
     (MM, 1, 1, 2, (8,), ()): ("L", "L;R"),
     (MM, 1, 1, 1, (16,), ()): ("I;16B", "I;16B"),
anntzer commented 10 years ago

The Image file formats doc does not mention this limitation. Is this a non-standard TIFF format? (I don't know.)

wiredfool commented 10 years ago

There are many combinations, we support 60 or more of them. See lines ~145->212 of TiffImagePlugin for the combinations. I've never seen a signed 8bit image before, so if it's not rare, it's not exactly common either.

We don't have a specific mode for signed 8 bit images, so while we can read the image, we don't actually report the bytes correctly. (we'd return 0-255, not -127->127).

radarhere commented 6 years ago

Just a direct link to the sample image - https://downloads.openmicroscopy.org/images/OME-TIFF/2016-06/bioformats-artificial/single-channel.ome.tiff

radarhere commented 1 year ago

I've created PR #7111 to resolve this.