Coder Social home page Coder Social logo

Comments (2)

FirefoxMetzger avatar FirefoxMetzger commented on May 21, 2024

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.

FirefoxMetzger avatar FirefoxMetzger commented on May 21, 2024

xref: python-pillow/Pillow#7301

from imageio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.