Getting list of pixel values from PIL

前端 未结 9 1180
感动是毒
感动是毒 2020-11-27 15:07

Guys, I\'m looking for a bit of assistance. I\'m a newbie programmer and one of the problems I\'m having at the minute is trying to convert a black & white .jpg

9条回答
  •  野性不改
    2020-11-27 15:46

    Python shouldn't crash when you call getdata(). The image might be corrupted or there is something wrong with your PIL installation. Try it with another image or post the image you are using.

    This should break down the image the way you want:

    from PIL import Image
    im = Image.open('um_000000.png')
    
    pixels = list(im.getdata())
    width, height = im.size
    pixels = [pixels[i * width:(i + 1) * width] for i in xrange(height)]
    

提交回复
热议问题