New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mode incorrectly determined on Image.fromarray with bool input dtype #3109
Comments
@akhmerov How about a PR to address this issue? |
@aclark4life sorry, I'm not familiar enough with the codebase and especially with the low level numpy format to identify the source of the issue and fix it efficiently. (I did check if I could come up with an easy fix when trying to figure out what is happening.) |
I've created PR #3790 to resolve this. |
Bad news for guys, this bug still exists:
Even worse, it will crash when you set argument
Related issues: My environment: |
@Zhangchenkai The fix is not in Pillow 6.0.0 (released ~2019-04-01), it will be in Pillow 6.1.0 due for release on 2019-07-01. Please retest with master or wait for the release. |
The bug is still in releases on Pypi. Pillow 7.1.1, Python 3.8.2 |
@stranskj can't confirm with the same versions of Pillow and Python. EDIT: just in case, numpy version 1.18.1, and I have a conda-forge + linux installation. |
Also cannot reproduce (both installed from PyPI via pip): Python 3.8.2 (v3.8.2:7b3ab5921f, Feb 24 2020, 17:52:18)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(.startup.py)
(imported collections, datetime, itertools, math, os, pprint, re, sys, time)
>>> from PIL import Image
>>> import numpy as np
>>> Image.__version__
'7.1.1'
>>> np.__version__
'1.18.2'
>>> print(np.array(Image.fromarray(np.eye(5, dtype=bool))))
[[ True False False False False]
[False True False False False]
[False False True False False]
[False False False True False]
[False False False False True]]
>>> print(np.eye(5, dtype=bool))
[[ True False False False False]
[False True False False False]
[False False True False False]
[False False False True False]
[False False False False True]]
>>> np.array(Image.fromarray(np.eye(5, dtype=bool))) == np.eye(5, dtype=bool)
array([[ True, True, True, True, True],
[ True, True, True, True, True],
[ True, True, True, True, True],
[ True, True, True, True, True],
[ True, True, True, True, True]]) @stranskj If you still have a problem, please open a new issue and fill in the template with more details. Thanks. |
What did you do?
I observed that
Image.fromarray
works incorrectly onbool
array input, likely due to an incorrectly determined mode or rawmode.What did you expect to happen?
Same as
print(np.eye(5, dtype=bool))
, so:What actually happened?
What versions of Pillow and Python are you using?
Pillow: 5.1.0
python: '3.6.5 | packaged by conda-forge | (default, Apr 6 2018, 13:39:56) \n[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)]'
numpy: 1.14.2
Workaround
Use
Image.fromarray(boolean_array * np.uint(255))
The text was updated successfully, but these errors were encountered: