How to convert a PIL Image into a numpy array?

后端 未结 8 2375
不知归路
不知归路 2020-11-22 17:12

Alright, I\'m toying around with converting a PIL image object back and forth to a numpy array so I can do some faster pixel by pixel transformations than PIL\'s Pixel

8条回答
  •  一整个雨季
    2020-11-22 17:45

    You need to convert your image to a numpy array this way:

    import numpy
    import PIL
    
    img = PIL.Image.open("foo.jpg").convert("L")
    imgarr = numpy.array(img) 
    

提交回复
热议问题