Answer the question
In order to leave comments, you need to log in
How to make Pillow's getdata() return an array of RGB tuples for a pixel if the photo is black and white?
I'm converting the PIllow pixel array to a NumPy 3D array, and this code works fine with color images:
def PIL2array(img):
np.array(img.getdata(), np.uint8).reshape(img.size[0], img.size[1], 3)
ValueError: cannot reshape array of size 784 into shape (28,28,3)
Answer the question
In order to leave comments, you need to log in
Everything is much simpler:
You can also put -1 instead of 3:
np.array(img.getdata(), np.uint8).reshape(img.size[0], img.size[1], -1)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question