Cannot write array of shape (H, W, 1) to JPEG image with v3 API
See original GitHub issueSwitching from the v2 API to the v3 API, I noticed the following difference:
This works
import numpy as np
import imageio
x = np.zeros((10, 30, 1), dtype=np.uint8)
imageio.v2.imwrite("test.jpg", x)
while the same with imageio.v3.imwrite
fails with the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\kpkx626\AppData\Local\Programs\Python\Python38\lib\site-packages\imageio\v3.py", line 161, in imwrite
encoded = img_file.write(image, **kwargs)
File "C:\Users\kpkx626\AppData\Local\Programs\Python\Python38\lib\site-packages\imageio\plugins\pillow.py", line 322, in write
primary_image.save(self._request.get_file(), **save_args)
File "C:\Users\kpkx626\AppData\Local\Programs\Python\Python38\lib\site-packages\PIL\Image.py", line 2305, in save
save_handler = SAVE_ALL[format.upper()]
KeyError: 'JPEG'
This happens with Pillow 9.1.1 and 9.2.0 and Python 3.8.10 on Windows.
Is this considered an intended change, or should PillowPlugin.write
squeeze out the third dimension?
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Saving a Numpy array as an image - python - Stack Overflow
An answer using PIL (just in case it's useful). given a numpy array "A": from PIL import Image im = Image.fromarray(A) im.save("your_file.jpeg").
Read more >Importing Image Data into NumPy Arrays | Pluralsight
Loading and displaying an image using Matplotlib, OpenCV and Keras API. Converting the loaded images to the NumPy array and back. Conducting ...
Read more >Arrays and Array Images - Earth Engine - Google Developers
An array image of 1-D vectors created in this manner has no concept of 2-D shape. To perform 2-D only operations such as...
Read more >Reading/Writing images and videos - PyTorch
They are currently specific to reading and writing video and images. ... Reads a JPEG or PNG image into a 3 dimensional RGB...
Read more >Source code for monai.data.image_reader
This function returns two objects, first is numpy array of image data, ... sr = min(max(direction.shape[0], 1), 3) affine: np.ndarray = np.eye(sr +...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@FirefoxMetzger I created #849 to address the
tifffile
plugin issue.@slanzmich Oh? This sounds quite right. Could you make a new issue for this?
tifffile
is an entirely different plugin so it uses a different code path than what I shared above.