Reading PhotometricInterpretation CFA TIFF file fails
Dear Pillow developers
I am the developer of FabIO and we rely on Pillow to read some file-formats which are not specific to X-ray detectors.
One of our user reported a file which could not be read with Pillow but could with tiffile, he provided a file of shape2880x2880 of uint16 available in this issue:
https://github.com/silx-kit/fabio/issues/458
The error message is
>>> PIL.Image.open("test.tif")
---------------------------------------------------------------------------
UnidentifiedImageError Traceback (most recent call last)
<ipython-input-18-b037e95b0993> in <module>
----> 1 PIL.Image.open("test.tif")
~/.venv/py39/lib/python3.9/site-packages/PIL/Image.py in open(fp, mode, formats)
3028 for message in accept_warnings:
3029 warnings.warn(message)
-> 3030 raise UnidentifiedImageError(
3031 "cannot identify image file %r" % (filename if filename else fp)
3032 )
UnidentifiedImageError: cannot identify image file 'test.tif'
The user provides some hints in the fabio issue about PhotometricInterpretation which may be uninterpreted... since the value in question is available, I suspect it is rather a bug somewhere in the parser.
I can help but I will need a minimum guidance in the structure of Pillow.
Cheers,
Jerome
Hi.
If I modify my Image.py like so
diff --git a/src/PIL/Image.py b/src/PIL/Image.py
index 6ecd5fac8..bdb8f4af7 100644
--- a/src/PIL/Image.py
+++ b/src/PIL/Image.py
@@ -2982,6 +2982,8 @@ def open(fp, mode="r", formats=None):
# Leave disabled by default, spams the logs with image
# opening failures that are entirely expected.
# logger.debug("", exc_info=True)
+ if i == "TIFF":
+ raise
continue
except BaseException:
if exclusive_fp:
and then try to open the file, I get
Traceback (most recent call last):
File "PIL/TiffImagePlugin.py", line 1324, in _setup
KeyError: (b'II', 32803, (1,), 1, (16,), ())
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "demo.py", line 2, in <module>
im = Image.open('test.tif')
File "PIL/Image.py", line 2994, in open
File "PIL/Image.py", line 2978, in _open_core
File "PIL/TiffImagePlugin.py", line 1032, in __init__
File "PIL/ImageFile.py", line 111, in __init__
File "PIL/TiffImagePlugin.py", line 1057, in _open
File "PIL/TiffImagePlugin.py", line 1114, in _seek
File "PIL/TiffImagePlugin.py", line 1327, in _setup
SyntaxError: unknown pixel mode
The second value in (b'II', 32803, (1,), 1, (16,), ()) is PhotometricInterpretation. If PhotometricInterpretation were 1 (MINISBLACK), we would have an entry for that - https://github.com/python-pillow/Pillow/blob/fcb87ecbe171f959ff62cefe0e33061b24d3de5a/src/PIL/TiffImagePlugin.py#L170
I see that https://www.awaresystems.be/imaging/tiff/tifftags/photometricinterpretation.html does list 32803 = CFA.
So I agree that it is a value we have not supported, rather than a bug from faulty logic.
(b'II', 32803, (1,), 1, (16,), ()) also covers one of the files in #6482, so I'm going to close this as part of that.