Trying to run simple PIL python example, can't convert jpeg to float

前端 未结 3 1931
忘了有多久
忘了有多久 2021-02-09 15:32

so I wrote a simple python script

from PIL import Image
from pylab import *
im = array(Image.open(\'sample.jpg\'))
imshow(im)

and i get this er

3条回答
  •  被撕碎了的回忆
    2021-02-09 15:53

    What you have is close. Looking at the imshow docs, you need to pass either an Image OR a data array.

    This should work:

    from PIL import Image
    from pylab import *
    im = Image.open('sample.jpg')
    imshow(im)
    


    Here's what imshow() is expecting:

    "X may be a float array, a uint8 array or a PIL image."

    There are some more details here:
    http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.imshow

提交回复
热议问题