I have this code:
from PIL import Image
import numpy as np
img = Image.open('img.jpg')
Image.fromarray(np.array([[np.mean(i, axis=1).astype(int).tolist()]*len(i) for i in np.array(img).tolist()]).astype('uint8')).show()
And I am trying to modify the pixels of the image in PIL, however when I run it it gives an error as follows:
KeyError: ((1, 1, 1280), '|u1')
Not just that, it also outputs a second error as follows:
TypeError: Cannot handle this data type
Is there a way to overcome this?
P.S. I searched and the most related question to mine was:
Convert numpy.array object to PIL image object
However I don't get it nor know how to implement it.