Comments (2)
I can reproduce the exception on an amd64 architecture using the following snippet:
>>> import imageio.v3 as iio
>>> import numpy as np
>>> img = iio.imread("imageio:chelsea.png", mode="L")
>>> img.dtype
dtype('uint8')
>>> iio.imwrite("foo.png", img.astype("<u2"))
>>> iio.imwrite("foo.png", img.astype(">u2"))
Traceback (most recent call last):
File "/Users/<user>/projects/imageio/.venv/lib/python3.10/site-packages/PIL/PngImagePlugin.py", line 1277, in _save
rawmode, mode = _OUTMODES[mode]
KeyError: 'I;16B'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/<user>/projects/imageio/imageio/v3.py", line 139, in imwrite
with imopen(
File "/Users/<user>/projects/imageio/imageio/core/v3_plugin_api.py", line 367, in __exit__
self.close()
File "/Users/<user>/projects/imageio/imageio/plugins/pillow.py", line 123, in close
self._flush_writer()
File "/Users/<user>/projects/imageio/imageio/plugins/pillow.py", line 457, in _flush_writer
primary_image.save(self._request.get_file(), **self.save_args)
File "/Users/<user>/projects/imageio/.venv/lib/python3.10/site-packages/PIL/Image.py", line 2413, in save
save_handler(self, fp, filename)
File "/Users/<user>/projects/imageio/.venv/lib/python3.10/site-packages/PIL/PngImagePlugin.py", line 1280, in _save
raise OSError(msg) from e
OSError: cannot write mode I;16B as PNG
This originates from Pillow. Internally their PNG writer maintains a list of valid input buffer dtypes and I;16B
(big-endian 16-bit) is not listed there. However, I;16
(little-endian 16-bit) is. If I add I;16B
in their list of allowed dtypes everything runs as it should. --- I will create an issue over at pillow and ask if they can add it, since this looks like a bug/oversight to me :)
The reason this error shows up on s390x is because it is a big-endian architecture. For PNGs (though this will likely extend in the future) ImageIO will unpack pixels into native endianness. As such you get a big-endian buffer on a big-endian machine, which is more performant but, for now, not allowed as input when writing with pillow.
from imageio.
xref: python-pillow/Pillow#7301
from imageio.
Related Issues (20)
- Some tests fail if imageio-ffmpeg is not installed
- test_findlib2 fails for unknown reason HOT 1
- Transparency not working on gifs HOT 3
- Question: loading TIFF as grayscale in v3 HOT 5
- New behavior of imageio.imsave HOT 5
- heif format / .heic image file support HOT 2
- imread on S3 stream fails with PIL.UnidentifiedImageError HOT 2
- ImageResource type should support bytes HOT 1
- [Bug Report] imageio v3 crashed when read hdr images after a certain number of times
- Link to the documentation in the README is broken HOT 1
- imread() fails on HTTPS, code example from documentation HOT 3
- 8bit grayscale now loaded as RGB HOT 5
- 2.31.4: documentation build fails HOT 1
- iio pyav plugin crash along with python when handling a webm file, setting format to rgba HOT 2
- It does not seem to support avif image format HOT 1
- Support for Pillow v10.1 (re: setting `image.mode`) HOT 8
- Inconsistency when reading floating point .exr image file HOT 3
- imageio.imread changes the values of graycale pixels, try to read 12-bit png grayscale image. HOT 8
- super slow video reads HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imageio.