0

I want to convert a PIL image to a numpy array. Numpy's asarray function simply puts the image in a 0-dimensional array.

(Pdb) p img
<PIL.Image._ImageCrop image mode=RGB size=1024x0 at 0x106953560>
(Pdb) img.getdata()
<ImagingCore object at 0x104c97b10>
(Pdb) np.asarray(img.getdata())
array([], dtype=float64)
(Pdb) np.asarray(img)
array(<PIL.Image._ImageCrop image mode=RGB size=1024x0 at 0x106953560>, dtype=object)
(Pdb) np.asarray(img).shape
()
(Pdb) np.asarray(img, np.uint8)
*** SystemError: error return without exception set

The solutions on a similar SO question didn't work.

1 Answer 1

5

Your img has size 1024x0:

PIL.Image._ImageCrop image mode=RGB size=1024x0 at 0x106953560

That is an image with 0 height. Therefore, the resultant NumPy array is empty. To fix, crop the image so that it has a positive width and height.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.