Pillow icon indicating copy to clipboard operation
Pillow copied to clipboard

Fails to open OME-TIFF example data files

Open anntzer opened this issue 11 years ago • 6 comments

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').

anntzer avatar Jul 20 '14 07:07 anntzer

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?

hugovk avatar Jul 20 '14 08:07 hugovk

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

anntzer avatar Jul 20 '14 10:07 anntzer

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"),

wiredfool avatar Jul 20 '14 17:07 wiredfool

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

anntzer avatar Jul 20 '14 19:07 anntzer

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).

wiredfool avatar Jul 20 '14 20:07 wiredfool

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

radarhere avatar Aug 22 '18 10:08 radarhere

I've created PR #7111 to resolve this.

radarhere avatar Apr 24 '23 04:04 radarhere