-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Conversion of image to array fails #3863
Comments
I find that if I add in >>> import numpy as np
>>> from PIL import Image, ImageFile
>>> ImageFile.LOAD_TRUNCATED_IMAGES = True
>>> im = Image.open("doesNotConvertToArray.jpg")
>>> a1 = np.asarray(im)
>>> print(a1.shape)
(1018, 2703, 3)
>>> a2 = np.asarray(im)
>>> print(a2.shape)
(1018, 2703, 3) |
@sommerfelt Did that help? Okay to close this issue? |
I reported the issue more because it indicates a bug in PIL and not so much because it causes a problem for me. In my case I will use a1.dtype==object to flag a corrupted image rather than cloaking it by setting ImageFile.LOAD_TRUNCATED_IMAGES = True. So to conclude: For my purposes the issue is closed if I can rely on this behaviour, but for PIL it remains either a bug (an Exception should be raised unless ImageFile.LOAD_TRUNCATED_IMAGES = True) or if you like, it could be called an undocumented feature. |
I've created PR #3965 to resolve this, by fixing the inconsistent behaviour. |
I had the same problem. To do so: im = Image.open("doesNotConvertToArray.jpg").convert('L')
a1 = np.asarray(im)
a2 = np.asarray(im)
print a1
print a2 |
Tried to load and convert an image (attached) to a numpy array. Fails on first try, succeeds on second. Strange!
Guessing cause may be that the image is slightly corrupted, but this is not detected or reported by PIL.
What are your OS, Python and Pillow versions?
The text was updated successfully, but these errors were encountered: